Skip to content

Commit 8bb7244

Browse files
committed
Add additional annotations to auth
1 parent a7c2d79 commit 8bb7244

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

nbgrader/auth/base.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from traitlets import Instance, Type
22
from traitlets.config import LoggingConfigurable
3-
from typing import Any
3+
from typing import Any, Optional
44

55

66
class BaseAuthPlugin(LoggingConfigurable):
77

8-
def get_student_courses(self, student_id): # pragma: no cover
8+
def get_student_courses(self, student_id: str) -> Optional[list]: # pragma: no cover
99
"""Gets the list of courses that the student is enrolled in.
1010
1111
Arguments
@@ -23,7 +23,7 @@ def get_student_courses(self, student_id): # pragma: no cover
2323
"""
2424
raise NotImplementedError
2525

26-
def add_student_to_course(self, student_id, course_id): # pragma: no cover
26+
def add_student_to_course(self, student_id: str, course_id: str) -> None: # pragma: no cover
2727
"""Grants a student access to a given course.
2828
2929
Arguments
@@ -36,7 +36,7 @@ def add_student_to_course(self, student_id, course_id): # pragma: no cover
3636
"""
3737
raise NotImplementedError
3838

39-
def remove_student_from_course(self, student_id, course_id): # pragma: no cover
39+
def remove_student_from_course(self, student_id: str, course_id: str) -> None: # pragma: no cover
4040
"""Removes a student's access to a given course.
4141
4242
Arguments
@@ -52,17 +52,17 @@ def remove_student_from_course(self, student_id, course_id): # pragma: no cover
5252

5353
class NoAuthPlugin(BaseAuthPlugin):
5454

55-
def get_student_courses(self, student_id):
55+
def get_student_courses(self, student_id: str) -> Optional[list]:
5656
# None means that the student has access to any course that might exist
5757
# on the system.
5858
return None
5959

60-
def add_student_to_course(self, student_id, course_id):
60+
def add_student_to_course(self, student_id: str, course_id: str) -> None:
6161
# Nothing to do, we don't keep track of which students are in which
6262
# courses in the default setting.
6363
pass
6464

65-
def remove_student_from_course(self, student_id, course_id):
65+
def remove_student_from_course(self, student_id: str, course_id: str) -> None:
6666
# Nothing to do, we don't keep track of which students are in which
6767
# courses in the default setting.
6868
pass
@@ -83,7 +83,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
8383
self.log.debug("Using authenticator: %s", self.plugin_class.__name__)
8484
self.plugin = self.plugin_class(parent=self)
8585

86-
def get_student_courses(self, student_id):
86+
def get_student_courses(self, student_id: str) -> Optional[list]:
8787
"""Gets the list of courses that the student is enrolled in.
8888
8989
Arguments
@@ -101,7 +101,7 @@ def get_student_courses(self, student_id):
101101
"""
102102
return self.plugin.get_student_courses(student_id)
103103

104-
def has_access(self, student_id, course_id):
104+
def has_access(self, student_id: str, course_id: str) -> bool:
105105
"""Checks whether a student has access to a particular course.
106106
107107
Arguments
@@ -121,7 +121,7 @@ def has_access(self, student_id, course_id):
121121
return True
122122
return course_id in courses
123123

124-
def add_student_to_course(self, student_id: str, course_id: str) -> Any:
124+
def add_student_to_course(self, student_id: str, course_id: str) -> None:
125125
"""Grants a student access to a given course.
126126
127127
Arguments
@@ -132,9 +132,9 @@ def add_student_to_course(self, student_id: str, course_id: str) -> Any:
132132
The unique id of the course.
133133
134134
"""
135-
return self.plugin.add_student_to_course(student_id, course_id)
135+
self.plugin.add_student_to_course(student_id, course_id)
136136

137-
def remove_student_from_course(self, student_id, course_id):
137+
def remove_student_from_course(self, student_id: str, course_id: str) -> None:
138138
"""Removes a student's access to a given course.
139139
140140
Arguments

nbgrader/auth/jupyterhub.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def get_jupyterhub_api_url() -> str:
2424
return os.environ.get('JUPYTERHUB_API_URL') or 'http://127.0.0.1:8081/hub/api'
2525

2626

27-
def get_jupyterhub_authorization():
27+
def get_jupyterhub_authorization() -> dict:
2828
if os.getenv('JUPYTERHUB_API_TOKEN'):
2929
api_token = os.environ['JUPYTERHUB_API_TOKEN']
3030
else:
@@ -72,7 +72,7 @@ def _query_jupyterhub_api(method: str, api_path: str, post_data: Optional[dict]
7272

7373
class JupyterHubAuthPlugin(BaseAuthPlugin):
7474

75-
def get_student_courses(self, student_id):
75+
def get_student_courses(self, student_id: str) -> Optional[list]:
7676
if student_id == "*":
7777
student_id = "{authenticated_user}"
7878
response = None
@@ -138,7 +138,7 @@ def add_student_to_course(self, student_id: str, course_id: str) -> None:
138138
self.log.error(err_msg + str(e))
139139
self.log.error("Make sure you set a valid admin_user 'api_token' in your config file before starting the service")
140140

141-
def remove_student_from_course(self, student_id, course_id):
141+
def remove_student_from_course(self, student_id: str, course_id: str) -> None:
142142
if not course_id:
143143
self.log.error(
144144
"Could not remove student from course because the course_id has "

0 commit comments

Comments
 (0)