11from traitlets import List
22
3+ from nbconvert .exporters .exporter import ResourcesDict
4+ from nbformat .notebooknode import NotebookNode
5+ from typing import Optional , Any , Tuple
6+
37from .. import utils
48from ..api import Gradebook
59from . import NbGraderPreprocessor
@@ -10,7 +14,10 @@ class GetGrades(NbGraderPreprocessor):
1014
1115 display_data_priority = List (['text/html' , 'application/pdf' , 'text/latex' , 'image/svg+xml' , 'image/png' , 'image/jpeg' , 'text/plain' ], config = True )
1216
13- def preprocess (self , nb , resources ):
17+ def preprocess (self ,
18+ nb : NotebookNode ,
19+ resources : ResourcesDict ,
20+ ) -> Tuple [NotebookNode , ResourcesDict ]:
1421 # pull information from the resources
1522 self .notebook_id = resources ['nbgrader' ]['notebook' ]
1623 self .assignment_id = resources ['nbgrader' ]['assignment' ]
@@ -37,7 +44,7 @@ def preprocess(self, nb, resources):
3744
3845 return nb , resources
3946
40- def _get_comment (self , cell , resources ) :
47+ def _get_comment (self , cell : NotebookNode , resources : ResourcesDict ) -> None :
4148 """Graders can optionally add comments to the student's solutions, so
4249 add the comment information into the database if it doesn't
4350 already exist. It should NOT overwrite existing comments that
@@ -55,7 +62,7 @@ def _get_comment(self, cell, resources):
5562 # save it in the notebook
5663 cell .metadata .nbgrader ['comment' ] = comment .comment
5764
58- def _get_score (self , cell , resources ) :
65+ def _get_score (self , cell : NotebookNode , resources : ResourcesDict ) -> None :
5966 grade = self .gradebook .find_grade (
6067 cell .metadata ['nbgrader' ]['grade_id' ],
6168 self .notebook_id ,
@@ -65,7 +72,10 @@ def _get_score(self, cell, resources):
6572 cell .metadata .nbgrader ['score' ] = grade .score
6673 cell .metadata .nbgrader ['points' ] = grade .max_score
6774
68- def preprocess_cell (self , cell , resources , cell_index ):
75+ def preprocess_cell (self ,
76+ cell : NotebookNode ,
77+ resources : ResourcesDict , cell_index : int ,
78+ ) -> Tuple [NotebookNode , ResourcesDict ]:
6979 # if it's a solution cell, then add a comment
7080 if utils .is_solution (cell ):
7181 self ._get_comment (cell , resources )
0 commit comments