Skip to content

Commit ca36539

Browse files
fix pylint
1 parent 12ec0a3 commit ca36539

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

packages/models-library/src/models_library/projects.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ def convert_sql_alchemy_enum(cls, v):
113113
)
114114

115115

116+
def _patch_json_schema_extra(schema: dict) -> None:
117+
# Patch to allow jsonschema nullable
118+
# SEE https://github.com/samuelcolvin/pydantic/issues/990#issuecomment-645961530
119+
state_pydantic_schema = deepcopy(schema["properties"]["state"])
120+
schema["properties"]["state"] = {"anyOf": [{"type": "null"}, state_pydantic_schema]}
121+
122+
116123
class Project(BaseProjectModel):
117124
# NOTE: This is the pydantic pendant of project-v0.0.1.json used in the API of the webserver/webclient
118125
# NOT for usage with DB!!
@@ -172,14 +179,6 @@ class Project(BaseProjectModel):
172179
alias="workspaceId",
173180
)
174181

175-
def _patch_json_schema_extra(self, schema: dict) -> None:
176-
# Patch to allow jsonschema nullable
177-
# SEE https://github.com/samuelcolvin/pydantic/issues/990#issuecomment-645961530
178-
state_pydantic_schema = deepcopy(schema["properties"]["state"])
179-
schema["properties"]["state"] = {
180-
"anyOf": [{"type": "null"}, state_pydantic_schema]
181-
}
182-
183182
model_config = ConfigDict(
184183
title="osparc-simcore project",
185184
extra="forbid",

packages/models-library/src/models_library/projects_nodes.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@ class NodeState(BaseModel):
113113
)
114114

115115

116+
def _patch_json_schema_extra(schema: dict) -> None:
117+
# NOTE: exporting without this trick does not make runHash as nullable.
118+
# It is a Pydantic issue see https://github.com/samuelcolvin/pydantic/issues/1270
119+
for prop_name in ["parent", "runHash"]:
120+
if prop_name in schema.get("properties", {}):
121+
prop = deepcopy(schema["properties"][prop_name])
122+
prop["nullable"] = True
123+
schema["properties"][prop_name] = prop
124+
125+
116126
class Node(BaseModel):
117127
key: ServiceKey = Field(
118128
...,
@@ -234,15 +244,6 @@ def convert_from_enum(cls, v):
234244
return NodeState(currentStatus=running_state_value)
235245
return v
236246

237-
def _patch_json_schema_extra(self, schema: dict) -> None:
238-
# NOTE: exporting without this trick does not make runHash as nullable.
239-
# It is a Pydantic issue see https://github.com/samuelcolvin/pydantic/issues/1270
240-
for prop_name in ["parent", "runHash"]:
241-
if prop_name in schema.get("properties", {}):
242-
prop = deepcopy(schema["properties"][prop_name])
243-
prop["nullable"] = True
244-
schema["properties"][prop_name] = prop
245-
246247
model_config = ConfigDict(
247248
extra="forbid",
248249
json_schema_extra=_patch_json_schema_extra, # type: ignore[typeddict-item]

packages/models-library/src/models_library/utils/json_serialization.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ def decimal_encoder(dec_value: Decimal) -> int | float:
5656
"""
5757
if dec_value.as_tuple().exponent >= 0: # type: ignore[operator]
5858
return int(dec_value)
59-
else:
60-
return float(dec_value)
59+
60+
return float(dec_value)
6161

6262

6363
ENCODERS_BY_TYPE: dict[type[Any], Callable[[Any], Any]] = {
@@ -95,7 +95,8 @@ def pydantic_encoder(obj: Any) -> Any:
9595

9696
if isinstance(obj, BaseModel):
9797
return obj.model_dump()
98-
elif is_dataclass(obj):
98+
99+
if is_dataclass(obj):
99100
return asdict(obj) # type: ignore[call-overload]
100101

101102
# Check the class type and its superclasses for a matching encoder

0 commit comments

Comments
 (0)