Skip to content

Commit

Permalink
mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderegg committed Mar 17, 2023
1 parent d19ffcd commit 518a712
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from fastapi.requests import Request
from sqlalchemy.ext.asyncio import AsyncEngine

from ...db.repositories import BaseRepository
from ...db.repositories._base import BaseRepository

logger = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import logging
from collections import defaultdict
from distutils.version import Version
from itertools import chain
from typing import Any, Iterable, Optional
from typing import Any, Iterable, Optional, cast

import packaging.version
import sqlalchemy as sa
Expand Down Expand Up @@ -97,7 +98,7 @@ async def list_services(
product_name,
)
):
services_in_db.append(ServiceMetaDataAtDB(**row))
services_in_db.append(ServiceMetaDataAtDB.from_orm(row))
return services_in_db

async def list_service_releases(
Expand Down Expand Up @@ -142,9 +143,11 @@ async def list_service_releases(
releases.append(ServiceMetaDataAtDB.from_orm(row))

# Now sort naturally from latest first: (This is lame, the sorting should be done in the db)
return sorted(
releases, key=lambda x: packaging.version.parse(x.version), reverse=True
)
def _by_version(x: ServiceMetaDataAtDB) -> Version:
return cast(Version, packaging.version.parse(x.version))

releases_sorted = sorted(releases, key=_by_version, reverse=True)
return releases_sorted

async def get_latest_release(self, key: str) -> Optional[ServiceMetaDataAtDB]:
"""Returns last release or None if service was never released"""
Expand Down Expand Up @@ -190,7 +193,8 @@ async def get_service(
result = await conn.execute(query)
row = result.first()
if row:
return ServiceMetaDataAtDB(**row)
return ServiceMetaDataAtDB.from_orm(row)
return None # mypy

async def create_service(
self,
Expand All @@ -216,7 +220,7 @@ async def create_service(
)
row = result.first()
assert row # nosec
created_service = ServiceMetaDataAtDB(**row)
created_service = ServiceMetaDataAtDB.from_orm(row)

for access_rights in new_service_access_rights:
insert_stmt = pg_insert(services_access_rights).values(
Expand All @@ -242,7 +246,7 @@ async def update_service(
)
row = result.first()
assert row # nosec
updated_service = ServiceMetaDataAtDB(**row)
updated_service = ServiceMetaDataAtDB.from_orm(row)
return updated_service

async def get_service_access_rights(
Expand Down Expand Up @@ -360,6 +364,7 @@ async def get_service_specifications(
"getting specifications from db for %s", f"{key}:{version} for {groups=}"
)
gid_to_group_map = {group.gid: group for group in groups}

group_specs = {
GroupType.EVERYONE: None,
GroupType.PRIMARY: None,
Expand Down Expand Up @@ -418,6 +423,7 @@ async def get_service_specifications(
group_specs[GroupType.PRIMARY],
):
return ServiceSpecifications.parse_obj(merged_specifications)
return None # mypy


def _is_newer(
Expand Down

0 comments on commit 518a712

Please sign in to comment.