Skip to content

Commit effa8fc

Browse files
Housekeeping (#1019)
1 parent ad58bb5 commit effa8fc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+70
-76
lines changed

mp_api/client/core/client.py

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
from typing import (
2222
TYPE_CHECKING,
2323
ForwardRef,
24-
Generic,
2524
Optional,
26-
TypeVar,
2725
get_args,
2826
)
2927
from urllib.parse import quote, urljoin
@@ -65,10 +63,8 @@
6563

6664
SETTINGS = MAPIClientSettings() # type: ignore
6765

68-
T = TypeVar("T")
6966

70-
71-
class BaseRester(Generic[T]):
67+
class BaseRester:
7268
"""Base client class with core stubs."""
7369

7470
suffix: str = ""
@@ -140,15 +136,8 @@ def __init__(
140136
if not self.endpoint.endswith("/"):
141137
self.endpoint += "/"
142138

143-
if session:
144-
self._session = session
145-
else:
146-
self._session = None # type: ignore
147-
148-
if s3_client:
149-
self._s3_client = s3_client
150-
else:
151-
self._s3_client = None
139+
self._session = session
140+
self._s3_client = s3_client
152141

153142
@property
154143
def session(self) -> requests.Session:
@@ -596,7 +585,7 @@ def _submit_requests( # noqa
596585
url: url used to make request
597586
use_document_model: if None, will defer to the self.use_document_model attribute
598587
parallel_param: parameter to parallelize requests with
599-
num_chu: fieldsnky: Maximum number of chunks of data to yield. None will yield all possible.
588+
num_chunks: Maximum number of chunks of data to yield. None will yield all possible.
600589
chunk_size: Number of data entries per chunk.
601590
timeout: Time in seconds to wait until a request timeout error is thrown
602591
@@ -1077,7 +1066,9 @@ def _generate_returned_model(
10771066
include_fields: dict[str, tuple[type, FieldInfo]] = {}
10781067
for name in set_fields:
10791068
field_copy = model_fields[name]._copy()
1080-
field_copy.default = None
1069+
if not field_copy.default_factory:
1070+
# Fields with a default_factory cannot also have a default in pydantic>=2.12.3
1071+
field_copy.default = None
10811072
include_fields[name] = (
10821073
Optional[model_fields[name].annotation],
10831074
field_copy,
@@ -1097,8 +1088,6 @@ def _generate_returned_model(
10971088
),
10981089
__module__=self.document_model.__module__,
10991090
)
1100-
# if other_vars:
1101-
# data_model.model_rebuild(_types_namespace=other_vars)
11021091

11031092
orig_rester_name = self.document_model.__name__
11041093

@@ -1151,7 +1140,7 @@ def _query_resource_data(
11511140
suburl: str | None = None,
11521141
use_document_model: bool | None = None,
11531142
timeout: int | None = None,
1154-
) -> list[T] | list[dict]:
1143+
) -> list[BaseModel] | list[dict]:
11551144
"""Query the endpoint for a list of documents without associated meta information. Only
11561145
returns a single page of results.
11571146
@@ -1181,7 +1170,7 @@ def _search(
11811170
all_fields: bool = True,
11821171
fields: list[str] | None = None,
11831172
**kwargs,
1184-
) -> list[T] | list[dict]:
1173+
) -> list[BaseModel] | list[dict]:
11851174
"""A generic search method to retrieve documents matching specific parameters.
11861175
11871176
Arguments:
@@ -1216,7 +1205,7 @@ def get_data_by_id(
12161205
self,
12171206
document_id: str,
12181207
fields: list[str] | None = None,
1219-
) -> T | dict:
1208+
) -> BaseModel | dict:
12201209
warnings.warn(
12211210
"get_data_by_id is deprecated and will be removed soon. Please use the search method instead.",
12221211
DeprecationWarning,
@@ -1251,7 +1240,7 @@ def _get_all_documents(
12511240
fields=None,
12521241
chunk_size=1000,
12531242
num_chunks=None,
1254-
) -> list[T] | list[dict]:
1243+
) -> list[BaseModel] | list[dict]:
12551244
"""Iterates over pages until all documents are retrieved. Displays
12561245
progress using tqdm. This method is designed to give a common
12571246
implementation for the search_* methods on various endpoints. See

mp_api/client/mprester.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,10 +1203,11 @@ def get_entries_in_chemsys(
12031203

12041204
elements_set = set(elements) # remove duplicate elements
12051205

1206-
all_chemsyses = []
1207-
for i in range(len(elements_set)):
1208-
for els in itertools.combinations(elements_set, i + 1):
1209-
all_chemsyses.append("-".join(sorted(els)))
1206+
all_chemsyses = [
1207+
"-".join(sorted(els))
1208+
for i in range(len(elements_set))
1209+
for els in itertools.combinations(elements_set, i + 1)
1210+
]
12101211

12111212
entries = []
12121213

mp_api/client/routes/_general_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from mp_api.client.core import BaseRester
66

77

8-
class GeneralStoreRester(BaseRester[GeneralStoreDoc]): # pragma: no cover
8+
class GeneralStoreRester(BaseRester): # pragma: no cover
99
suffix = "_general_store"
1010
document_model = GeneralStoreDoc # type: ignore
1111
primary_key = "submission_id"

mp_api/client/routes/_messages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from mp_api.client.core import BaseRester
88

99

10-
class MessagesRester(BaseRester[MessagesDoc]): # pragma: no cover
10+
class MessagesRester(BaseRester): # pragma: no cover
1111
suffix = "_messages"
1212
document_model = MessagesDoc # type: ignore
1313
primary_key = "title"

mp_api/client/routes/_user_settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from mp_api.client.core import BaseRester
66

77

8-
class UserSettingsRester(BaseRester[UserSettingsDoc]): # pragma: no cover
8+
class UserSettingsRester(BaseRester): # pragma: no cover
99
suffix = "_user_settings"
1010
document_model = UserSettingsDoc # type: ignore
1111
primary_key = "consumer_id"

mp_api/client/routes/materials/absorption.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from mp_api.client.core.utils import validate_ids
99

1010

11-
class AbsorptionRester(BaseRester[AbsorptionDoc]):
11+
class AbsorptionRester(BaseRester):
1212
suffix = "materials/absorption"
1313
document_model = AbsorptionDoc # type: ignore
1414
primary_key = "material_id"

mp_api/client/routes/materials/alloys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from mp_api.client.core.utils import validate_ids
99

1010

11-
class AlloysRester(BaseRester[AlloyPairDoc]):
11+
class AlloysRester(BaseRester):
1212
suffix = "materials/alloys"
1313
document_model = AlloyPairDoc # type: ignore
1414
primary_key = "pair_id"

mp_api/client/routes/materials/bonds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from mp_api.client.core.utils import validate_ids
99

1010

11-
class BondsRester(BaseRester[BondingDoc]):
11+
class BondsRester(BaseRester):
1212
suffix = "materials/bonds"
1313
document_model = BondingDoc # type: ignore
1414
primary_key = "material_id"

mp_api/client/routes/materials/chemenv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from mp_api.client.core.utils import validate_ids
1515

1616

17-
class ChemenvRester(BaseRester[ChemEnvDoc]):
17+
class ChemenvRester(BaseRester):
1818
suffix = "materials/chemenv"
1919
document_model = ChemEnvDoc # type: ignore
2020
primary_key = "material_id"

mp_api/client/routes/materials/dielectric.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from mp_api.client.core.utils import validate_ids
99

1010

11-
class DielectricRester(BaseRester[DielectricDoc]):
11+
class DielectricRester(BaseRester):
1212
suffix = "materials/dielectric"
1313
document_model = DielectricDoc # type: ignore
1414
primary_key = "material_id"

0 commit comments

Comments
 (0)