11from nbformat import read as _read , reads as _reads
22from nbformat import write as _write , writes as _writes
3+ from nbformat .notebooknode import NotebookNode
4+ import typing
35from .v1 import MetadataValidatorV1
46from .common import BaseMetadataValidator , ValidationError
57
@@ -12,7 +14,7 @@ def __init__(self) -> None:
1214 super ().__init__ ()
1315 self .v1 = MetadataValidatorV1 ()
1416
15- def _upgrade_v1_to_v2 (self , cell ) :
17+ def _upgrade_v1_to_v2 (self , cell : NotebookNode ) -> NotebookNode :
1618 meta = cell .metadata ['nbgrader' ]
1719
1820 # only add cell type if the checksum has also already been set
@@ -24,7 +26,7 @@ def _upgrade_v1_to_v2(self, cell):
2426
2527 return cell
2628
27- def upgrade_cell_metadata (self , cell ) :
29+ def upgrade_cell_metadata (self , cell : NotebookNode ) -> NotebookNode :
2830 if 'nbgrader' not in cell .metadata :
2931 return cell
3032
@@ -42,7 +44,7 @@ def upgrade_cell_metadata(self, cell):
4244 self ._remove_extra_keys (cell )
4345 return cell
4446
45- def validate_cell (self , cell ) :
47+ def validate_cell (self , cell : NotebookNode ) -> None :
4648 super (MetadataValidatorV2 , self ).validate_cell (cell )
4749
4850 if 'nbgrader' not in cell .metadata :
@@ -81,7 +83,7 @@ def validate_cell(self, cell):
8183 raise ValidationError (
8284 "Markdown solution cell is not marked as a grade cell: {}" .format (cell .source ))
8385
84- def validate_nb (self , nb ) :
86+ def validate_nb (self , nb : NotebookNode ) -> None :
8587 super (MetadataValidatorV2 , self ).validate_nb (nb )
8688
8789 ids = set ([])
@@ -103,23 +105,23 @@ def validate_nb(self, nb):
103105 ids .add (grade_id )
104106
105107
106- def read_v2 (source , as_version , ** kwargs ) :
108+ def read_v2 (source : typing . io . TextIO , as_version : int , ** kwargs : typing . Any ) -> NotebookNode :
107109 nb = _read (source , as_version , ** kwargs )
108110 MetadataValidatorV2 ().validate_nb (nb )
109111 return nb
110112
111113
112- def write_v2 (nb , fp , ** kwargs ) :
114+ def write_v2 (nb : NotebookNode , fp : typing . io . TextIO , ** kwargs : typing . Any ) -> None :
113115 MetadataValidatorV2 ().validate_nb (nb )
114- return _write (nb , fp , ** kwargs )
116+ _write (nb , fp , ** kwargs )
115117
116118
117- def reads_v2 (source , as_version , ** kwargs ) :
119+ def reads_v2 (source : str , as_version : int , ** kwargs : typing . Any ) -> NotebookNode :
118120 nb = _reads (source , as_version , ** kwargs )
119121 MetadataValidatorV2 ().validate_nb (nb )
120122 return nb
121123
122124
123- def writes_v2 (nb , ** kwargs ) :
125+ def writes_v2 (nb : NotebookNode , ** kwargs : typing . Any ) -> None :
124126 MetadataValidatorV2 ().validate_nb (nb )
125- return _writes (nb , ** kwargs )
127+ _writes (nb , ** kwargs )
0 commit comments