Skip to content

Commit a2b2fc0

Browse files
Patches to contribs client (#1094)
2 parents 5bdefe4 + 8c3f20d commit a2b2fc0

3 files changed

Lines changed: 38 additions & 8 deletions

File tree

mp_api/client/contribs/_types.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,36 @@ def from_dict(cls, dct: dict) -> Self:
316316
return cls((k, v) for k, v in dct.items() if k in keys)
317317

318318

319+
"""
320+
The following type annotations are only used in type checking
321+
(mypy) the ContribsClient.get_all_ids function.
322+
This function has highly hetereogeneous output and these
323+
represent the intermediate and final data structures returned
324+
by that function.
325+
326+
They **shouldn't** have to be used elsewhere.
327+
"""
328+
319329
ComponentIdSets = dict[str, set[str]]
330+
"""Use only when type checking of ContribsClient.get_all_ids(...,fmt="sets")."""
331+
320332
ProjectIdSets = dict[str, set[str] | ComponentIdSets]
333+
"""Use only when type checking of ContribsClient.get_all_ids(...,fmt="sets")."""
334+
321335
AllIdSets = dict[str, ProjectIdSets]
336+
"""Use only when type checking of ContribsClient.get_all_ids(...,fmt="sets")."""
322337

323338
ComponentNameMap = dict[str, dict[str, str]]
339+
"""Use only when type checking of ContribsClient.get_all_ids(...,fmt="map")."""
340+
324341
IdentifierLeaf = dict[str, str | ComponentNameMap]
342+
"""Use only when type checking of ContribsClient.get_all_ids(...,fmt="map")."""
343+
325344
IdentifierBranch = dict[str, IdentifierLeaf]
345+
"""Use only when type checking of ContribsClient.get_all_ids(...,fmt="map")."""
346+
326347
ProjectIdMap = dict[str, IdentifierLeaf | IdentifierBranch]
348+
"""Use only when type checking of ContribsClient.get_all_ids(...,fmt="map")."""
349+
327350
AllIdMap = dict[str, ProjectIdMap]
351+
"""Use only when type checking of ContribsClient.get_all_ids(...,fmt="map")."""

mp_api/client/contribs/client.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
from mp_api.client.contribs._logger import MPCC_LOGGER, TqdmToLogger
5151
from mp_api.client.contribs._types import (
5252
Attachment,
53+
ComponentIdSets,
5354
MPCDict,
5455
MPCStructure,
5556
Table,
@@ -71,10 +72,9 @@
7172
from collections.abc import Generator, Iterable, Sequence
7273
from typing import Any
7374

74-
from mp_api.client.contribs.types import (
75+
from mp_api.client.contribs._types import (
7576
AllIdMap,
7677
AllIdSets,
77-
ComponentIdSets,
7878
IdentifierLeaf,
7979
ProjectIdSets,
8080
)
@@ -88,11 +88,15 @@
8888
warnings.filterwarnings("default", category=DeprecationWarning, module=__name__)
8989

9090

91-
def validate_email(email_string: str):
91+
def validate_email(email_string: str) -> None:
9292
"""Validate user email address.
9393
9494
Args:
9595
email_string (str) : the user's email address
96+
Returns:
97+
None
98+
Raises:
99+
SwaggerValidationError on malformed email address.
96100
"""
97101
if email_string.count(":") != 1:
98102
raise SwaggerValidationError(
@@ -107,6 +111,8 @@ def validate_email(email_string: str):
107111
if d > BaseDiagnosis.CATEGORIES["VALID"]:
108112
raise SwaggerValidationError(f"{email} {d.message}")
109113

114+
return None
115+
110116

111117
# TODO: mypy has some problems with putting a bare `str`
112118
# as a callable function in SwaggerFormat
@@ -2109,7 +2115,7 @@ def submit_contributions(
21092115
digest in digests[project_name][component]
21102116
or digest
21112117
in existing.get(project_name, {})
2112-
.get(component, {})
2118+
.get(component, {}) # type: ignore[union-attr]
21132119
.get("md5s", [])
21142120
)
21152121

@@ -2227,9 +2233,9 @@ def put_future(pk, payload):
22272233
pk=project_name, _fields=["unique_identifiers"]
22282234
).result()["unique_identifiers"]
22292235
)
2230-
existing_ids = existing.get(project_name, {}).get(
2231-
"identifiers", []
2232-
)
2236+
existing_ids: Iterable[str] = existing.get(
2237+
project_name, {}
2238+
).get("identifiers", [])
22332239
contribs[project_name] = [
22342240
c
22352241
for c in contribs[project_name]

mp_api/client/contribs/schemas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,5 +372,5 @@ class QueryResult(_DictLikeAccess):
372372

373373
total_count: int
374374
total_pages: int
375-
data: list[BaseModel] | None = None
375+
data: list[ContribData] | None = None
376376
has_more: bool = False

0 commit comments

Comments
 (0)