Changed the type hint of the "current_user" pseudo property of the AbstractUserUtils class to return None when the user has not logged in.

This commit is contained in:
依瑪貓 2023-02-07 14:12:22 +08:00 committed by 依瑪貓
parent dc24af1db0
commit 31dc8fab04
2 changed files with 6 additions and 5 deletions

View File

@ -50,10 +50,11 @@ class AbstractUserUtils(t.Generic[T], ABC):
@property @property
@abstractmethod @abstractmethod
def current_user(self) -> T: def current_user(self) -> T | None:
"""Returns the current user. """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 @abstractmethod
@ -117,7 +118,7 @@ def get_user_pk(username: str) -> int:
return __user_utils.get_pk(__user_utils.get_by_username(username)) 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 """Returns the currently logged-in user. The result is cached in the
current request. current request.

View File

@ -80,7 +80,7 @@ def create_app(is_testing: bool = False) -> Flask:
return auth.User.id return auth.User.id
@property @property
def current_user(self) -> auth.User: def current_user(self) -> auth.User | None:
return auth.current_user() return auth.current_user()
def get_by_username(self, username: str) -> auth.User | None: def get_by_username(self, username: str) -> auth.User | None: