Skip to content

Commit

Permalink
fix(bc): correct typing in constraints service
Browse files Browse the repository at this point in the history
  • Loading branch information
hdinia committed Mar 28, 2024
1 parent ae23954 commit 075c32b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions antarest/study/business/binding_constraint_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def parse_constraint(key: str, value: str, char: str, new_config: ConstraintOutp
return False

@staticmethod
def constraint_model_adapter(constraint: ConstraintInput, version: int) -> ConstraintOutput:
def constraint_model_adapter(constraint: Mapping[str, Any], version: int) -> ConstraintOutput:
"""
Adapts a constraint configuration to the appropriate version-specific format.
Expand Down Expand Up @@ -479,7 +479,7 @@ def get_binding_constraint(

# If a specific constraint ID is provided, we return that constraint
if filters.bc_id:
return filtered_constraints.get(filters.bc_id)
return filtered_constraints.get(filters.bc_id) # type: ignore

# Else we return all the matching constraints, based on the given filters
return list(filtered_constraints.values())
Expand Down Expand Up @@ -677,7 +677,7 @@ def update_binding_constraint(
}

if study_version >= 870:
updated_constraint["group"] = data.group or existing_constraint.group
updated_constraint["group"] = data.group or existing_constraint.group # type: ignore

args = {
**updated_constraint,
Expand Down Expand Up @@ -836,7 +836,7 @@ def remove_constraint_term(
binding_constraint_id: str,
term_id: str,
) -> None:
return self.update_constraint_term(study, binding_constraint_id, term_id)
return self.update_constraint_term(study, binding_constraint_id, term_id) # type: ignore


def _replace_matrices_according_to_frequency_and_version(
Expand Down
2 changes: 1 addition & 1 deletion antarest/study/business/table_mode_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def set_table_data(
enabled=col_values.get("enabled", current_binding_dto.enabled),
time_step=col_values.get("type", current_binding_dto.time_step),
operator=col_values.get("operator", current_binding_dto.operator),
coeffs=BindingConstraintManager.constraints_to_coeffs(current_binding_dto),
coeffs=BindingConstraintManager.terms_to_coeffs(current_binding_dto.terms),
command_context=command_context,
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def test_lifecycle__nominal(self, client: TestClient, user_access_token: str, st
expected = [
{
"comments": "",
"terms": [],
"terms": [],
"enabled": True,
"filterSynthesis": "",
"filterYearByYear": "",
Expand All @@ -233,7 +233,7 @@ def test_lifecycle__nominal(self, client: TestClient, user_access_token: str, st
},
{
"comments": "",
"terms": [],
"terms": [],
"enabled": True,
"filterSynthesis": "",
"filterYearByYear": "",
Expand All @@ -244,7 +244,7 @@ def test_lifecycle__nominal(self, client: TestClient, user_access_token: str, st
},
{
"comments": "New API",
"terms": [],
"terms": [],
"enabled": True,
"filterSynthesis": "",
"filterYearByYear": "",
Expand Down Expand Up @@ -301,7 +301,7 @@ def test_lifecycle__nominal(self, client: TestClient, user_access_token: str, st
)
assert res.status_code == 200, res.json()
binding_constraint = res.json()
constraint_terms = binding_constraint["terms"]
constraint_terms = binding_constraint["terms"]
expected = [
{
"data": {"area1": area1_id, "area2": area2_id},
Expand Down Expand Up @@ -336,7 +336,7 @@ def test_lifecycle__nominal(self, client: TestClient, user_access_token: str, st
)
assert res.status_code == 200, res.json()
binding_constraint = res.json()
constraint_terms = binding_constraint["terms"]
constraint_terms = binding_constraint["terms"]
expected = [
{
"data": {"area1": area1_id, "area2": area2_id},
Expand Down Expand Up @@ -426,7 +426,7 @@ def test_lifecycle__nominal(self, client: TestClient, user_access_token: str, st
# Check that the matrix is a daily/weekly matrix
res = client.get(
f"/v1/studies/{study_id}/raw",
params={"path": f"input/bindingconstraints/{bc_id}", "depth": 1, "formatted": True}, #type: ignore
params={"path": f"input/bindingconstraints/{bc_id}", "depth": 1, "formatted": True}, # type: ignore
headers=user_headers,
)
assert res.status_code == 200, res.json()
Expand Down Expand Up @@ -657,7 +657,7 @@ def test_for_version_870(self, client: TestClient, admin_access_token: str, stud
for term in ["lt", "gt", "eq"]:
res = client.get(
f"/v1/studies/{study_id}/raw",
params={"path": f"input/bindingconstraints/{bc_id_w_matrix}_{term}", "depth": 1, "formatted": True}, #type: ignore
params={"path": f"input/bindingconstraints/{bc_id_w_matrix}_{term}", "depth": 1, "formatted": True}, # type: ignore
headers=admin_headers,
)
assert res.status_code == 200
Expand Down Expand Up @@ -729,7 +729,7 @@ def test_for_version_870(self, client: TestClient, admin_access_token: str, stud
"path": f"input/bindingconstraints/{bc_id_w_matrix}_{term_alias}",
"depth": 1,
"formatted": True,
}, # type: ignore
}, # type: ignore
headers=admin_headers,
)
assert res.status_code == 200
Expand Down

0 comments on commit 075c32b

Please sign in to comment.