Skip to content

Commit 8c0646a

Browse files
bug fixes
1 parent 6c5cd68 commit 8c0646a

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

mp_api/client/contribs/client.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from math import isclose
1717
from pathlib import Path
1818
from tempfile import gettempdir
19-
from typing import TYPE_CHECKING, Literal, overload
19+
from typing import TYPE_CHECKING, Literal, cast, overload
2020
from urllib.parse import urlsplit
2121

2222
import orjson
@@ -69,7 +69,7 @@
6969

7070
if TYPE_CHECKING:
7171
from collections.abc import Generator, Iterable, Sequence
72-
from typing import Any, cast
72+
from typing import Any
7373

7474
from mp_api.client.contribs.types import (
7575
AllIdMap,
@@ -1419,6 +1419,7 @@ def _collect_ids_as_sets(
14191419
components: set[str],
14201420
data_id_fields: dict[str, str],
14211421
) -> AllIdSets:
1422+
14221423
ret: AllIdSets = {}
14231424

14241425
for contrib in contributions:
@@ -1432,13 +1433,12 @@ def _collect_ids_as_sets(
14321433
ret[project] = id_sets
14331434

14341435
project_sets = ret[project]
1435-
if TYPE_CHECKING:
1436-
cast(set[str], project_sets["ids"]).add(contrib["id"])
1437-
cast(set[str], project_sets["identifiers"]).add(contrib["identifier"])
1436+
cast(set[str], project_sets["ids"]).add(contrib["id"])
1437+
cast(set[str], project_sets["identifiers"]).add(contrib["identifier"])
14381438

14391439
if data_id_field:
14401440
data_value = contrib.get("data", {}).get(data_id_field)
1441-
if TYPE_CHECKING and isinstance(data_value, str):
1441+
if isinstance(data_value, str):
14421442
cast(set[str], project_sets[f"{data_id_field}_set"]).add(data_value)
14431443

14441444
for component in components:
@@ -1449,8 +1449,7 @@ def _collect_ids_as_sets(
14491449
if component not in project_sets:
14501450
project_sets[component] = {"ids": set(), "md5s": set()}
14511451

1452-
if TYPE_CHECKING:
1453-
component_sets = cast(ComponentIdSets, project_sets[component])
1452+
component_sets = cast(ComponentIdSets, project_sets[component])
14541453

14551454
for item in component_items:
14561455
if not isinstance(item, dict):

mp_api/client/contribs/schemas.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,14 @@ def __repr__(self) -> str:
234234
"""Format for display."""
235235
return self.display_name
236236

237+
def __float__(self) -> float:
238+
"""Allow conversion to float."""
239+
return float(self.value)
240+
241+
def __int__(self) -> int:
242+
"""Allow conversion to int."""
243+
return int(self.value)
244+
237245

238246
class BaseContrib(_DictLikeAccess):
239247
"""Define base schema for a single contribution."""

0 commit comments

Comments
 (0)