From 95f541053682f28e3bed470d49692a643c5c5d87 Mon Sep 17 00:00:00 2001 From: sanderegg <35365065+sanderegg@users.noreply.github.com> Date: Fri, 17 Mar 2023 13:57:12 +0100 Subject: [PATCH] mypy --- .../src/simcore_postgres_database/utils_products.py | 4 ++-- .../src/simcore_service_catalog/core/background_tasks.py | 7 +++++-- .../simcore_service_catalog/db/repositories/products.py | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/postgres-database/src/simcore_postgres_database/utils_products.py b/packages/postgres-database/src/simcore_postgres_database/utils_products.py index f4536eeb58c..b05e699b8a4 100644 --- a/packages/postgres-database/src/simcore_postgres_database/utils_products.py +++ b/packages/postgres-database/src/simcore_postgres_database/utils_products.py @@ -2,7 +2,7 @@ """ -from typing import Optional, Protocol +from typing import Any, Optional, Protocol import sqlalchemy as sa @@ -23,7 +23,7 @@ async def scalar(self, *args, **kwargs): class _AiopgConnection(Protocol): # Prototype to account for aiopg-only (this protocol avoids import <-> installation) - async def scalar(self, *args, **kwargs): + async def scalar(self, *args, **kwargs) -> Any: ... async def execute(self, *args, **kwargs): diff --git a/services/catalog/src/simcore_service_catalog/core/background_tasks.py b/services/catalog/src/simcore_service_catalog/core/background_tasks.py index 81ec3c533f0..e6adf6c074b 100644 --- a/services/catalog/src/simcore_service_catalog/core/background_tasks.py +++ b/services/catalog/src/simcore_service_catalog/core/background_tasks.py @@ -16,6 +16,7 @@ from typing import Any, Final, cast from fastapi import FastAPI +from models_library.function_services_catalog.api import iter_service_docker_data from models_library.services import ServiceDockerData from models_library.services_db import ServiceAccessRightsAtDB, ServiceMetaDataAtDB from packaging.version import Version @@ -27,7 +28,6 @@ from ..db.repositories.projects import ProjectsRepository from ..db.repositories.services import ServicesRepository from ..services import access_rights -from ..services.function_services import iter_service_docker_data logger = logging.getLogger(__name__) @@ -83,7 +83,10 @@ async def _create_services_in_db( services_repo = ServicesRepository(app.state.engine) - sorted_services = sorted(service_keys, key=lambda t: Version(t[1])) + def _by_version(t: tuple[ServiceKey, ServiceVersion]) -> Version: + return Version(t[1]) + + sorted_services = sorted(service_keys, key=_by_version) for service_key, service_version in sorted_services: service_metadata: ServiceDockerData = services_in_registry[ diff --git a/services/catalog/src/simcore_service_catalog/db/repositories/products.py b/services/catalog/src/simcore_service_catalog/db/repositories/products.py index 21a2bc02df0..57b036150d2 100644 --- a/services/catalog/src/simcore_service_catalog/db/repositories/products.py +++ b/services/catalog/src/simcore_service_catalog/db/repositories/products.py @@ -6,5 +6,5 @@ class ProductsRepository(BaseRepository): async def get_default_product_name(self) -> str: async with self.db_engine.begin() as conn: - product_name = await get_default_product_name(conn) + product_name: str = await get_default_product_name(conn) return product_name