diff --git a/src/accounting/utils/user.py b/src/accounting/utils/user.py index f7c20ad..c50d6f6 100644 --- a/src/accounting/utils/user.py +++ b/src/accounting/utils/user.py @@ -50,10 +50,11 @@ class AbstractUserUtils(t.Generic[T], ABC): @property @abstractmethod - def current_user(self) -> T: - """Returns the current user. + def current_user(self) -> T | None: + """Returns the currently logged-in user. - :return: The current user. + :return: The currently logged-in user, or None if the user has not + logged in """ @abstractmethod @@ -117,7 +118,7 @@ def get_user_pk(username: str) -> int: return __user_utils.get_pk(__user_utils.get_by_username(username)) -def get_current_user() -> user_cls: +def get_current_user() -> user_cls | None: """Returns the currently logged-in user. The result is cached in the current request. diff --git a/tests/test_site/__init__.py b/tests/test_site/__init__.py index 941af29..7455172 100644 --- a/tests/test_site/__init__.py +++ b/tests/test_site/__init__.py @@ -80,7 +80,7 @@ def create_app(is_testing: bool = False) -> Flask: return auth.User.id @property - def current_user(self) -> auth.User: + def current_user(self) -> auth.User | None: return auth.current_user() def get_by_username(self, username: str) -> auth.User | None: