Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix pylint tests #7056

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ci/helpers/install_pylint.bash
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ PYLINT_VERSION="$(grep pylint== $REQUIREMENTS | awk '{print $1}')"
uv pip install "$PYLINT_VERSION"

# Minimal packages to pass linter
echo "$CURDIR/requirements.txt"
uv pip install -r "$CURDIR/requirements.txt"
echo "$CURDIR/requirements/requirements.txt"
uv pip install -r "$CURDIR/requirements/requirements.txt"

echo "INFO:" "$(pylint --version)" "@" "$(command -v pylint)"
6 changes: 6 additions & 0 deletions ci/helpers/requirements/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
# Targets to pip-compile requirements
#
include ../../../requirements/base.Makefile

# Add here any extra explicit dependency: e.g. _migration.txt: _base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#
# Installing these void e.g. E0611: No name 'UploadFile' in module 'fastapi' (no-name-in-module)
#
--constraint ../../requirements/constraints.txt
--constraint ../../../requirements/constraints.txt

aiohttp
fastapi
docker
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
# This file was autogenerated by uv via the following command:
# uv pip compile requirements.in -o requirements.txt
aiohttp==3.9.5
# via
# -c ../../requirements/constraints.txt
# -r requirements.in
aiosignal==1.3.1
# via aiohttp
annotated-types==0.7.0
Expand All @@ -12,36 +7,43 @@ anyio==4.3.0
# via starlette
attrs==23.2.0
# via aiohttp
certifi==2024.12.14
# via requests
charset-normalizer==3.4.1
# via requests
docker==7.1.0
fastapi==0.115.0
# via -r requirements.in
frozenlist==1.4.1
# via
# aiohttp
# aiosignal
idna==3.7
# via
# anyio
# requests
# yarl
multidict==6.0.5
# via
# aiohttp
# yarl
pydantic==2.9.2
# via
# -c ../../requirements/constraints.txt
# fastapi
pydantic-core==2.23.4
pydantic==2.10.5
# via fastapi
pydantic-core==2.27.2
# via pydantic
requests==2.32.3
# via docker
sniffio==1.3.1
# via anyio
starlette==0.38.6
# via
# -c ../../requirements/constraints.txt
# fastapi
typing-extensions==4.11.0
# via fastapi
typing-extensions==4.12.2
# via
# fastapi
# pydantic
# pydantic-core
urllib3==2.3.0
# via
# docker
# requests
yarl==1.9.4
# via aiohttp
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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR: this also works without .keys().

if k in successful_transaction
}
return PaymentsTransactionsDB(**kwargs)
Expand Down
Loading