From 82437724ccd250d6754d0b0d0a24500b6ef556d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 12 May 2017 13:38:54 +0200 Subject: [PATCH] Added some type annotation The web layer uses string IDs, whereas the API layer uses ObjectIDs. Those annotations make it a bit more explicit what is used where. --- pillar/auth/__init__.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pillar/auth/__init__.py b/pillar/auth/__init__.py index 7b7e2889..5f5a525b 100644 --- a/pillar/auth/__init__.py +++ b/pillar/auth/__init__.py @@ -1,6 +1,7 @@ """Authentication code common to the web and api modules.""" import logging +import typing from flask import session import flask_login @@ -13,15 +14,15 @@ log = logging.getLogger(__name__) class UserClass(flask_login.UserMixin): - def __init__(self, token): + def __init__(self, token: typing.Optional[str]): # We store the Token instead of ID self.id = token - self.username = None - self.full_name = None - self.objectid = None - self.gravatar = None - self.email = None - self.roles = [] + self.username: str = None + self.full_name: str = None + self.objectid: str = None + self.gravatar: str = None + self.email: str = None + self.roles: typing.List[str] = [] def has_role(self, *roles): """Returns True iff the user has one or more of the given roles."""