From 20f713e6f78c0c08fbd3d10760cbc2890a53baeb Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Tue, 29 Apr 2025 11:54:56 +0200 Subject: [PATCH] Fix errors reported by mypy Signed-off-by: Jan Lindemann --- tools/python/jwutils/auth/Auth.py | 2 +- tools/python/jwutils/auth/dummy/Auth.py | 22 +++++++++++--------- tools/python/jwutils/db/query/QueryResult.py | 4 ++-- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/tools/python/jwutils/auth/Auth.py b/tools/python/jwutils/auth/Auth.py index 3a9b589..03763f2 100644 --- a/tools/python/jwutils/auth/Auth.py +++ b/tools/python/jwutils/auth/Auth.py @@ -53,7 +53,7 @@ class Auth: # export self.__conf = conf @abc.abstractmethod - def _access(self, what: str, access_type: Optional[Access]=None, who: Optional[Union[User|Group]]=None) -> bool: + def _access(self, what: str, access_type: Optional[Access], who: User|Group|None) -> bool: pass @abc.abstractmethod diff --git a/tools/python/jwutils/auth/dummy/Auth.py b/tools/python/jwutils/auth/dummy/Auth.py index bf65704..3850e56 100644 --- a/tools/python/jwutils/auth/dummy/Auth.py +++ b/tools/python/jwutils/auth/dummy/Auth.py @@ -2,7 +2,7 @@ from typing import Optional, Union -from ... import log +from ...log import * from ... import Config from .. import Access from .. import Auth as AuthBase @@ -23,25 +23,27 @@ class User(UserBase): def __init__(self, auth: AuthBase, name: str): self.__name = name self.__auth = auth - self.__groups = None + self.__groups: Optional[list[GroupBase]] = None def _name(self) -> str: return self.__name - def _groups(self) -> list[Group]: + def _groups(self) -> list[GroupBase]: if self.__groups is None: - for name in conf['user.' + name + '.groups']: - ret[name] = Group(self, name) + name: str = '' + ret: list[GroupBase] = [] + for name in self.__auth.conf['user.' + name + '.groups']: + ret.append(Group(self.__auth, name)) self.__groups = ret - self.__groups = ret + return self.__groups class Auth(AuthBase): # export def __init__(self, conf: Config): self.__conf = conf - self.__users = None + self.__users: Optional[dict[str, User]] = None self.__groups = None - self.__current_user = None + self.__current_user: User|None = None def _user(self, name_) -> User: if self.__users is None: @@ -51,8 +53,8 @@ class Auth(AuthBase): # export self.__users = ret return self.__users[name_] - def _access(self, what: str, access_type: Optional[Access]=None, who: Optional[Union[User|Group]]=None) -> bool: - slog(log.WARNING, f'Returning False for {access_type} access to resource {what} by {who}') + def _access(self, what: str, access_type: Optional[Access], who: User|GroupBase|None) -> bool: # type: ignore + slog(WARNING, f'Returning False for {access_type} access to resource {what} by {who}') return False def _current_user(self) -> User: diff --git a/tools/python/jwutils/db/query/QueryResult.py b/tools/python/jwutils/db/query/QueryResult.py index 831d918..baa2ca1 100644 --- a/tools/python/jwutils/db/query/QueryResult.py +++ b/tools/python/jwutils/db/query/QueryResult.py @@ -32,7 +32,7 @@ class QueryResult(abc.ABC): # export return self.__query @property - def session(self) -> DataBase: + def session(self) -> Session: return self.__session @property @@ -58,5 +58,5 @@ class QueryResult(abc.ABC): # export # -- pure virtuals @abc.abstractmethod - def _cast(self, session: Session, res_type: ResType, **kwargs) -> Union[Any|list[Any]]: + def _cast(self, res_type: ResType, **kwargs) -> Union[Any|list[Any]]: pass