2222from .. import plugins
2323from .. import exchange
2424from .. import converters
25+ from traitlets .traitlets import MetaHasTraits
26+ from typing import List as TypingList
27+ from io import StringIO
28+ from typing import Any
2529
2630
2731nbgrader_aliases = {
@@ -62,15 +66,15 @@ class NbGrader(JupyterApp):
6266 _log_formatter_cls = LogFormatter
6367
6468 @default ("log_level" )
65- def _log_level_default (self ):
69+ def _log_level_default (self ) -> int :
6670 return logging .INFO
6771
6872 @default ("log_datefmt" )
69- def _log_datefmt_default (self ):
73+ def _log_datefmt_default (self ) -> str :
7074 return "%Y-%m-%d %H:%M:%S"
7175
7276 @default ("log_format" )
73- def _log_format_default (self ):
77+ def _log_format_default (self ) -> str :
7478 return "%(color)s[%(name)s | %(levelname)s]%(end_color)s %(message)s"
7579
7680 logfile = Unicode (
@@ -83,7 +87,11 @@ def _log_format_default(self):
8387 )
8488 ).tag (config = True )
8589
86- def init_logging (self , handler_class , handler_args , color = True , subapps = False ):
90+ def init_logging (self ,
91+ handler_class : type ,
92+ handler_args : TypingList [StringIO ],
93+ color : bool = True ,
94+ subapps : bool = False ) -> None :
8795 handler = handler_class (* handler_args )
8896
8997 if color :
@@ -101,7 +109,7 @@ def init_logging(self, handler_class, handler_args, color=True, subapps=False):
101109 if subapps and self .subapp :
102110 self .subapp .init_logging (handler_class , handler_args , color = color , subapps = subapps )
103111
104- def deinit_logging (self ):
112+ def deinit_logging (self ) -> None :
105113 if len (self .log .handlers ) > 1 :
106114 for handler in self .log .handlers [1 :]:
107115 handler .close ()
@@ -115,10 +123,10 @@ def deinit_logging(self):
115123 classes = List ()
116124
117125 @default ("classes" )
118- def _classes_default (self ):
126+ def _classes_default (self ) -> TypingList [ MetaHasTraits ] :
119127 return [NbGrader , CourseDirectory ]
120128
121- def all_configurable_classes (self ):
129+ def all_configurable_classes (self ) -> TypingList [ MetaHasTraits ] :
122130 """Get a list of all configurable classes for nbgrader
123131 """
124132 # Call explicitly the method on this class, to avoid infinite recursion
@@ -163,10 +171,10 @@ def all_configurable_classes(self):
163171 return classes
164172
165173 @default ("config_file_name" )
166- def _config_file_name_default (self ):
174+ def _config_file_name_default (self ) -> str :
167175 return u'nbgrader_config'
168176
169- def _load_config (self , cfg , ** kwargs ) :
177+ def _load_config (self , cfg : Config , ** kwargs : Any ) -> None :
170178 if 'NbGraderConfig' in cfg :
171179 self .log .warning (
172180 "Use NbGrader in config, not NbGraderConfig. Outdated config:\n %s" ,
@@ -286,14 +294,14 @@ def fail(self, msg, *args):
286294 self .log .error (msg , * args )
287295 sys .exit (1 )
288296
289- def build_extra_config (self ):
297+ def build_extra_config (self ) -> Config :
290298 return Config ()
291299
292300 def excepthook (self , etype , evalue , tb ):
293301 format_excepthook (etype , evalue , tb )
294302
295303 @catch_config_error
296- def initialize (self , argv = None ):
304+ def initialize (self , argv : TypingList [ str ] = None ) -> None :
297305 self .update_config (self .build_extra_config ())
298306 self .init_syspath ()
299307 self .coursedir = CourseDirectory (parent = self )
@@ -305,11 +313,11 @@ def initialize(self, argv=None):
305313 if self .logfile :
306314 self .init_logging (logging .FileHandler , [self .logfile ], color = False )
307315
308- def init_syspath (self ):
316+ def init_syspath (self ) -> None :
309317 """Add the cwd to the sys.path ($PYTHONPATH)"""
310318 sys .path .insert (0 , os .getcwd ())
311319
312- def reset (self ):
320+ def reset (self ) -> None :
313321 # stop logging
314322 self .deinit_logging ()
315323
@@ -325,7 +333,7 @@ def print_subcommands(self):
325333 for key , (app , desc ) in self .subcommands .items ():
326334 print (" {}\n {}\n " .format (key , desc ))
327335
328- def load_config_file (self , ** kwargs ) :
336+ def load_config_file (self , ** kwargs : Any ) -> None :
329337 """Load the config file.
330338 By default, errors in loading config are handled, and a warning
331339 printed on screen. For testing, the suppress_errors option is set
@@ -341,6 +349,6 @@ def load_config_file(self, **kwargs):
341349
342350 super (NbGrader , self ).load_config_file (** kwargs )
343351
344- def start (self ):
352+ def start (self ) -> None :
345353 super (NbGrader , self ).start ()
346354 self .authenticator = Authenticator (parent = self )
0 commit comments