Skip to content

Commit 42ed70a

Browse files
authored
Refactors to account for pydantic deprecation warnings (#152)
1 parent 513ee70 commit 42ed70a

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

RATapi/inputs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def make_problem(project: RATapi.Project) -> ProblemDefinition:
179179
for layer in project.layers:
180180
layer_params = [
181181
project.parameters.index(getattr(layer, attribute), True)
182-
for attribute in list(layer.model_fields.keys())[1:-2]
182+
for attribute in list(RATapi.models.Layer.model_fields.keys())[1:-2]
183183
]
184184
layer_params.append(project.parameters.index(layer.hydration, True) if layer.hydration else float("NaN"))
185185
layer_params.append(hydrate_id[layer.hydrate_with])

RATapi/project.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,12 @@ def model_post_init(self, __context: Any) -> None:
365365
and wrap ClassList routines to control revalidation.
366366
"""
367367
# Ensure all ClassLists have the correct _class_handle defined
368-
for field in (fields := self.model_fields):
369-
type = fields[field].annotation
370-
if get_origin(type) == ClassList:
368+
for field in (fields := Project.model_fields):
369+
annotation = fields[field].annotation
370+
if get_origin(annotation) == ClassList:
371371
classlist = getattr(self, field)
372372
if not hasattr(field, "_class_handle"):
373-
classlist._class_handle = get_args(type)[0]
373+
classlist._class_handle = get_args(annotation)[0]
374374

375375
layers_field = self.layers
376376
if not hasattr(layers_field, "_class_handle"):

tests/test_project.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def test_classlists(test_project) -> None:
141141
"""The ClassLists in the "Project" model should contain instances of the models given by the dictionary
142142
"model_in_classlist".
143143
"""
144-
for model in (fields := test_project.model_fields):
144+
for model in (fields := RATapi.Project.model_fields):
145145
if get_origin(fields[model].annotation) == RATapi.ClassList:
146146
class_list = getattr(test_project, model)
147147
assert class_list._class_handle == get_args(fields[model].annotation)[0]
@@ -1613,7 +1613,7 @@ def test_save_load(project, request):
16131613
for file in original_project.custom_files:
16141614
file.path = file.path.resolve()
16151615

1616-
for field in original_project.model_fields:
1616+
for field in RATapi.Project.model_fields:
16171617
assert getattr(converted_project, field) == getattr(original_project, field)
16181618

16191619

0 commit comments

Comments
 (0)