Skip to content

Commit 534139a

Browse files
authored
♻️Maintenance: mypy catalog (#6121)
1 parent 46e3c9b commit 534139a

File tree

22 files changed

+86
-52
lines changed

22 files changed

+86
-52
lines changed

.github/workflows/ci-testing-deploy.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,6 @@ jobs:
665665
run: ./ci/github/unit-testing/catalog.bash install
666666
- name: typecheck
667667
run: ./ci/github/unit-testing/catalog.bash typecheck
668-
continue-on-error: true
669668
- name: test
670669
if: always()
671670
run: ./ci/github/unit-testing/catalog.bash test

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def create(
6565
total: int,
6666
limit: int,
6767
offset: int,
68-
):
68+
) -> "PageRpc":
6969
return cls(
7070
_meta=PageMetaInfoLimitOffset(
7171
total=total, count=len(chunk), limit=limit, offset=offset

services/catalog/requirements/_test.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ pytest-mock
2828
pytest-runner
2929
respx
3030
sqlalchemy[mypy] # adds Mypy / Pep-484 Support for ORM Mappings SEE https://docs.sqlalchemy.org/en/20/orm/extensions/mypy.html
31+
types-psycopg2
32+
types-PyYAML

services/catalog/requirements/_test.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ tomli==2.0.1
185185
# coverage
186186
# mypy
187187
# pytest
188+
types-psycopg2==2.9.21.20240417
189+
# via -r requirements/_test.in
190+
types-pyyaml==6.0.12.20240724
191+
# via -r requirements/_test.in
188192
typing-extensions==4.10.0
189193
# via
190194
# -c requirements/_base.txt

services/catalog/setup.cfg

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@ commit_args = --no-verify
99

1010
[tool:pytest]
1111
asyncio_mode = auto
12-
markers =
12+
markers =
1313
testit: "marks test to run during development"
14+
15+
[mypy]
16+
plugins =
17+
pydantic.mypy
18+
sqlalchemy.ext.mypy.plugin

services/catalog/src/simcore_service_catalog/_constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from typing import Final
1+
from typing import Any, Final
22

33
# These are equivalent to pydantic export models but for responses
44
# SEE https://pydantic-docs.helpmanual.io/usage/exporting_models/#modeldict
55
# SEE https://fastapi.tiangolo.com/tutorial/response-model/#use-the-response_model_exclude_unset-parameter
6-
RESPONSE_MODEL_POLICY: Final[dict[str, bool]] = {
6+
RESPONSE_MODEL_POLICY: Final[dict[str, Any]] = {
77
"response_model_by_alias": True,
88
"response_model_exclude_unset": True,
99
"response_model_exclude_defaults": False,

services/catalog/src/simcore_service_catalog/api/dependencies/services.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22
from dataclasses import dataclass
3-
from typing import Annotated
3+
from typing import Annotated, cast
44

55
from fastapi import Depends, FastAPI, Header, HTTPException, status
66
from models_library.api_schemas_catalog.services_specifications import (
@@ -92,10 +92,13 @@ async def get_service_from_manifest(
9292
Retrieves service metadata from the docker registry via the director
9393
"""
9494
try:
95-
return await manifest.get_service(
96-
key=service_key,
97-
version=service_version,
98-
director_client=director_client,
95+
return cast(
96+
ServiceMetaDataPublished,
97+
await manifest.get_service(
98+
key=service_key,
99+
version=service_version,
100+
director_client=director_client,
101+
),
99102
)
100103

101104
except ValidationError as exc:

services/catalog/src/simcore_service_catalog/api/rest/_services.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import urllib.parse
66
from typing import Annotated, Any, TypeAlias, cast
77

8-
from aiocache import cached
8+
from aiocache import cached # type: ignore[import-untyped]
99
from fastapi import APIRouter, Depends, Header, HTTPException, status
1010
from models_library.api_schemas_catalog.services import ServiceGet, ServiceUpdate
1111
from models_library.services import ServiceKey, ServiceType, ServiceVersion
@@ -335,6 +335,7 @@ async def update_service(
335335

336336
if updated_service.access_rights:
337337
# start by updating/inserting new entries
338+
assert x_simcore_products_name # nosec
338339
new_access_rights = [
339340
ServiceAccessRightsAtDB(
340341
key=service_key,
@@ -366,6 +367,7 @@ async def update_service(
366367
await services_repo.delete_service_access_rights(deleted_access_rights)
367368

368369
# now return the service
370+
assert x_simcore_products_name # nosec
369371
return await get_service(
370372
user_id=user_id,
371373
service_in_manifest=await get_service_from_manifest(

services/catalog/src/simcore_service_catalog/api/rest/_services_ports.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ async def list_service_ports(
3030
ports: list[ServicePortGet] = []
3131

3232
if service.inputs:
33-
for name, port in service.inputs.items():
34-
ports.append(ServicePortGet.from_service_io("input", name, port))
33+
for name, input_port in service.inputs.items():
34+
ports.append(ServicePortGet.from_service_io("input", name, input_port))
3535

3636
if service.outputs:
37-
for name, port in service.outputs.items():
38-
ports.append(ServicePortGet.from_service_io("output", name, port))
37+
for name, output_port in service.outputs.items():
38+
ports.append(ServicePortGet.from_service_io("output", name, output_port))
3939

4040
return ports

services/catalog/src/simcore_service_catalog/api/rest/_services_resources.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ async def get_service_resources(
197197
)
198198

199199
service_spec: ComposeSpecLabelDict | None = parse_raw_as(
200-
ComposeSpecLabelDict | None,
200+
ComposeSpecLabelDict | None, # type: ignore[arg-type]
201201
service_labels.get(SIMCORE_SERVICE_COMPOSE_SPEC_LABEL, "null"),
202202
)
203203
_logger.debug("received %s", f"{service_spec=}")

0 commit comments

Comments
 (0)