22
33# Copyright (c) IPython Development Team.
44# Distributed under the terms of the Modified BSD License.
5+ from __future__ import annotations
56
67import argparse
78import copy
@@ -236,7 +237,7 @@ class Config(dict): # type:ignore[type-arg]
236237
237238 """
238239
239- def __init__ (self , * args , ** kwds ) :
240+ def __init__ (self , * args : t . Any , ** kwds : t . Any ) -> None :
240241 dict .__init__ (self , * args , ** kwds )
241242 self ._ensure_subconfig ()
242243
@@ -273,15 +274,15 @@ def merge(self, other):
273274
274275 self .update (to_update )
275276
276- def collisions (self , other : " Config" ) -> t . Dict [str , t .Any ]:
277+ def collisions (self , other : Config ) -> dict [str , t .Any ]:
277278 """Check for collisions between two config objects.
278279
279280 Returns a dict of the form {"Class": {"trait": "collision message"}}`,
280281 indicating which values have been ignored.
281282
282283 An empty dict indicates no collisions.
283284 """
284- collisions : t . Dict [str , t .Any ] = {}
285+ collisions : dict [str , t .Any ] = {}
285286 for section in self :
286287 if section not in other :
287288 continue
@@ -490,7 +491,7 @@ def _log_default(self):
490491
491492 return get_logger ()
492493
493- def __init__ (self , log = None ):
494+ def __init__ (self , log : t . Any = None ) -> None :
494495 """A base class for config loaders.
495496
496497 log : instance of :class:`logging.Logger` to use.
@@ -532,7 +533,7 @@ class FileConfigLoader(ConfigLoader):
532533 here.
533534 """
534535
535- def __init__ (self , filename , path = None , ** kw ) :
536+ def __init__ (self , filename : str , path : str | None = None , ** kw : t . Any ) -> None :
536537 """Build a config loader for a filename and path.
537538
538539 Parameters
@@ -795,12 +796,12 @@ class ArgParseConfigLoader(CommandLineConfigLoader):
795796
796797 def __init__ (
797798 self ,
798- argv : t . Optional [ t . List [ str ]] = None ,
799- aliases : t . Optional [ t . Dict [ Flags , str ]] = None ,
800- flags : t . Optional [ t . Dict [ Flags , str ]] = None ,
799+ argv : list [ str ] | None = None ,
800+ aliases : dict [ Flags , str ] | None = None ,
801+ flags : dict [ Flags , str ] | None = None ,
801802 log : t .Any = None ,
802- classes : t . Optional [ t . List [t .Type [ t . Any ]]] = None ,
803- subcommands : t . Optional [ SubcommandsDict ] = None ,
803+ classes : list [ type [t .Any ]] | None = None ,
804+ subcommands : SubcommandsDict | None = None ,
804805 * parser_args : t .Any ,
805806 ** parser_kw : t .Any ,
806807 ) -> None :
@@ -899,17 +900,15 @@ def _create_parser(self):
899900 def _add_arguments (self , aliases , flags , classes ):
900901 raise NotImplementedError ("subclasses must implement _add_arguments" )
901902
902- def _argcomplete (
903- self , classes : t .List [t .Any ], subcommands : t .Optional [SubcommandsDict ]
904- ) -> None :
903+ def _argcomplete (self , classes : list [t .Any ], subcommands : SubcommandsDict | None ) -> None :
905904 """If argcomplete is enabled, allow triggering command-line autocompletion"""
906905 pass
907906
908907 def _parse_args (self , args ):
909908 """self.parser->self.parsed_data"""
910909 uargs = [cast_unicode (a ) for a in args ]
911910
912- unpacked_aliases : t . Dict [str , str ] = {}
911+ unpacked_aliases : dict [str , str ] = {}
913912 if self .aliases :
914913 unpacked_aliases = {}
915914 for alias , alias_target in self .aliases .items ():
@@ -957,7 +956,7 @@ def _convert_to_config(self):
957956class _FlagAction (argparse .Action ):
958957 """ArgParse action to handle a flag"""
959958
960- def __init__ (self , * args , ** kwargs ) :
959+ def __init__ (self , * args : t . Any , ** kwargs : t . Any ) -> None :
961960 self .flag = kwargs .pop ("flag" )
962961 self .alias = kwargs .pop ("alias" , None )
963962 kwargs ["const" ] = Undefined
@@ -983,8 +982,8 @@ class KVArgParseConfigLoader(ArgParseConfigLoader):
983982 parser_class = _KVArgParser # type:ignore[assignment]
984983
985984 def _add_arguments (self , aliases , flags , classes ):
986- alias_flags : t . Dict [str , t .Any ] = {}
987- argparse_kwds : t . Dict [str , t .Any ]
985+ alias_flags : dict [str , t .Any ] = {}
986+ argparse_kwds : dict [str , t .Any ]
988987 paa = self .parser .add_argument
989988 self .parser .set_defaults (_flags = [])
990989 paa ("extra_args" , nargs = "*" )
@@ -1108,9 +1107,7 @@ def _handle_unrecognized_alias(self, arg: str) -> None:
11081107 """
11091108 self .log .warning ("Unrecognized alias: '%s', it will have no effect." , arg )
11101109
1111- def _argcomplete (
1112- self , classes : t .List [t .Any ], subcommands : t .Optional [SubcommandsDict ]
1113- ) -> None :
1110+ def _argcomplete (self , classes : list [t .Any ], subcommands : SubcommandsDict | None ) -> None :
11141111 """If argcomplete is enabled, allow triggering command-line autocompletion"""
11151112 try :
11161113 import argcomplete # noqa
@@ -1132,7 +1129,7 @@ class KeyValueConfigLoader(KVArgParseConfigLoader):
11321129 Use KVArgParseConfigLoader
11331130 """
11341131
1135- def __init__ (self , * args , ** kwargs ) :
1132+ def __init__ (self , * args : t . Any , ** kwargs : t . Any ) -> None :
11361133 warnings .warn (
11371134 "KeyValueConfigLoader is deprecated since Traitlets 5.0."
11381135 " Use KVArgParseConfigLoader instead." ,
0 commit comments