Skip to content

Commit

Permalink
make pylint happy
Browse files Browse the repository at this point in the history
  • Loading branch information
bisgaard-itis committed Jan 17, 2025
1 parent add6ab6 commit e99f5f3
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ class MyModel(BaseModel):
],
)
def test_field_fn(fn: Callable[[Any], Any], expected: Any, name: str):
assert expected == fn(MyModel.model_fields[name])
assert expected == fn(MyModel.model_fields.get(name))
10 changes: 5 additions & 5 deletions packages/models-library/src/models_library/user_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,19 @@ def to_db(self) -> dict:

@classmethod
def update_preference_default_value(cls, new_default: Any) -> None:
expected_type = get_type(cls.model_fields["value"])
expected_type = get_type(cls.model_fields.get("value"))
detected_type = type(new_default)
if expected_type != detected_type:
msg = (
f"Error, {cls.__name__} {expected_type=} differs from {detected_type=}"
)
raise TypeError(msg)

if cls.model_fields["value"].default is None:
cls.model_fields["value"].default_factory = lambda: new_default
if cls.model_fields.get("value").default is None:
cls.model_fields.get("value").default_factory = lambda: new_default
else:
cls.model_fields["value"].default = new_default
cls.model_fields["value"].default_factory = None
cls.model_fields.get("value").default = new_default
cls.model_fields.get("value").default_factory = None

cls.model_rebuild(force=True)

Expand Down
2 changes: 1 addition & 1 deletion packages/models-library/tests/test_rest_ordering.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def test_ordering_query_model_class__defaults():
model = OrderQueryParamsModel.model_validate({"order_by": {"field": "name"}})
assert model.order_by
assert model.order_by.field == "name"
assert model.order_by.direction == OrderBy.model_fields["direction"].default
assert model.order_by.direction == OrderBy.model_fields.get("direction").default

# direction alone is invalid
with pytest.raises(ValidationError) as err_info:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class LabelSchemaAnnotations(BaseModel):
@classmethod
def create_from_env(cls) -> "LabelSchemaAnnotations":
data = {}
for field_name in cls.model_fields:
for field_name in cls.model_fields.keys():
if value := os.environ.get(field_name.upper()):
data[field_name] = value
return cls.model_validate(data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def _compose_url(
isinstance(v, (str, int)) or v is None for v in kwargs.values()
) # nosec

composed_url: str = str(AnyUrl.build(**kwargs)) # type: ignore[arg-type]
composed_url: str = str(AnyUrl.build(**kwargs)) # type: ignore[arg-type] # pylint: disable=missing-kwoa
return composed_url.rstrip("/")

def _build_api_base_url(self, *, prefix: str) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def transaction(
) -> PaymentsTransactionsDB:
kwargs = {
k: successful_transaction[k]
for k in PaymentsTransactionsDB.model_fields
for k in PaymentsTransactionsDB.model_fields.keys()
if k in successful_transaction
}
return PaymentsTransactionsDB(**kwargs)
Expand Down

0 comments on commit e99f5f3

Please sign in to comment.