Skip to content

Commit 44e040a

Browse files
committed
Add comment on decorators with input arguments
1 parent 98df201 commit 44e040a

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎src/common/Authentication.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,11 @@ def decode_token(token):
6363
return result
6464
else:
6565
raise Exception("Invalid token!")
66+
# https://realpython.com/primer-on-python-decorators/#defining-decorators-with-arguments
6667
@staticmethod
6768
def auth_required(url):
69+
# The function to decorate is only passed in directly if the decorator is called without arguments
70+
# Return a decorator function that takes a function as an argument (actual_auth_required) and returns a wrapper function (decorated_auth_required).
6871
def actual_auth_required(func):
6972
"""
7073
Authentication required
@@ -94,9 +97,11 @@ def decorated_auth_required(*args, **kwargs):
9497
return func(*args, **kwargs)
9598
return decorated_auth_required
9699
return actual_auth_required
97-
100+
# https://realpython.com/primer-on-python-decorators/#defining-decorators-with-arguments
98101
@staticmethod
99102
def require_role(role):
103+
# The function to decorate is only passed in directly if the decorator is called without arguments
104+
# Return a decorator function that takes a function as an argument (actual_auth_required) and returns a wrapper function (decorated_auth_required).
100105
def decorated_require_role(func):
101106
@wraps(func)
102107
def wrapped_require_role(*args, **kwargs):

0 commit comments

Comments
 (0)