Skip to content

Commit 91ef60c

Browse files
committed
fix the merge issues on versions file
Signed-off-by: Omswastik-11 <omswastikpanda11@gmail.com>
1 parent 6da5428 commit 91ef60c

1 file changed

Lines changed: 11 additions & 22 deletions

File tree

openml/_api/resources/base/versions.py

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from collections.abc import Mapping
4-
from typing import Any
4+
from typing import Any, cast
55

66
import xmltodict
77

@@ -189,10 +189,7 @@ def untag(self, resource_id: int, tag: str) -> list[str]:
189189
def _get_endpoint_name(self) -> str:
190190
if self.resource_type == ResourceType.DATASET:
191191
return "data"
192-
endpoint_name = self.resource_type.value
193-
if not isinstance(endpoint_name, str):
194-
raise TypeError(f"Unexpected endpoint type: {type(endpoint_name)}")
195-
return endpoint_name
192+
return cast("str", self.resource_type.value)
196193

197194
def _extract_id_from_upload(self, parsed: Mapping[str, Any]) -> int:
198195
"""
@@ -223,23 +220,18 @@ def _extract_id_from_upload(self, parsed: Mapping[str, Any]) -> int:
223220
if not isinstance(root_value, Mapping):
224221
raise ValueError("Unexpected XML structure")
225222

226-
# 1. Specifically look for keys ending in _id or id (e.g., oml:id, oml:run_id)
227-
for k, v in root_value.items():
228-
if (
229-
(k.endswith(("id", "_id")) or "id" in k.lower())
230-
and isinstance(v, (str, int))
231-
and str(v).isdigit()
232-
):
233-
return int(v)
223+
# Look for oml:id directly in the root value
224+
if "oml:id" in root_value:
225+
id_value = root_value["oml:id"]
226+
if isinstance(id_value, (str, int)):
227+
return int(id_value)
234228

235-
# 2. Fallback: check all values for numeric/string IDs, excluding xmlns or URLs
229+
# Fallback: check all values for numeric/string IDs
236230
for v in root_value.values():
237231
if isinstance(v, (str, int)):
238-
val_str = str(v)
239-
if val_str.isdigit():
240-
return int(val_str)
232+
return int(v)
241233

242-
raise ValueError(f"No ID found in upload response: {root_value}")
234+
raise ValueError("No ID found in upload response")
243235

244236

245237
class ResourceV2API(ResourceAPI):
@@ -266,7 +258,4 @@ def untag(self, resource_id: int, tag: str) -> list[str]: # noqa: ARG002
266258
self._not_supported(method="untag")
267259

268260
def _get_endpoint_name(self) -> str:
269-
endpoint_name = self.resource_type.value
270-
if not isinstance(endpoint_name, str):
271-
raise TypeError(f"Unexpected endpoint type: {type(endpoint_name)}")
272-
return endpoint_name
261+
return cast("str", self.resource_type.value)

0 commit comments

Comments
 (0)