@@ -120,8 +120,8 @@ def magics_class(cls: _T) -> _T:
120120 application code becomes active, in practice this should not pose any
121121 problems.
122122 """
123- cls .registered = True # type: ignore[attr-defined]
124- cls .magics = dict (line = magics ["line" ], cell = magics ["cell" ]) # type: ignore[attr-defined]
123+ cls .registered = True
124+ cls .magics = dict (line = magics ["line" ], cell = magics ["cell" ])
125125 magics ["line" ] = {}
126126 magics ["cell" ] = {}
127127 return cls
@@ -206,6 +206,7 @@ def _method_magic_marker(
206206 # This is a closure to capture the magic_kind. We could also use a class,
207207 # but it's overkill for just that one bit of state.
208208 def magic_deco (arg : _F | str ) -> _F | Callable [[_F ], _F ]:
209+ retval : _F | Callable [[_F ], _F ]
209210 if callable (arg ):
210211 # "Naked" decorator call (just @foo, no args)
211212 func = arg
@@ -253,18 +254,19 @@ def magic_deco(arg: _F | str) -> _F | Callable[[_F], _F]:
253254
254255 ip : InteractiveShell = get_ipython ()
255256
257+ retval : _F | Callable [[_F ], _F ]
256258 if callable (arg ):
257259 # "Naked" decorator call (just @foo, no args)
258260 func = arg
259261 name = func .__name__
260- ip .register_magic_function (func , magic_kind , name )
262+ ip .register_magic_function (func , magic_kind , name ) # type: ignore[arg-type]
261263 retval = arg
262264 elif isinstance (arg , str ):
263265 # Decorator called with arguments (@foo('bar'))
264266 name = arg
265267
266268 def mark (func : _F , * a : Any , ** kw : Any ) -> _F :
267- ip .register_magic_function (func , magic_kind , name )
269+ ip .register_magic_function (func , magic_kind , name ) # type: ignore[arg-type]
268270 return func
269271
270272 retval = mark
@@ -389,7 +391,7 @@ class MagicsManager(Configurable):
389391 ).tag (config = True )
390392
391393 @observe ("auto_magic" )
392- def _auto_magic_changed (self , change ) :
394+ def _auto_magic_changed (self , change : dict [ str , Any ]) -> None :
393395 assert self .shell is not None
394396 self .shell .automagic = change ["new" ]
395397
@@ -629,7 +631,7 @@ def __init__(
629631 )
630632 if shell is not None :
631633 if hasattr (shell , "configurables" ):
632- shell .configurables .append (self )
634+ shell .configurables .append (self ) # type: ignore[arg-type]
633635 if hasattr (shell , "config" ):
634636 kwargs .setdefault ("parent" , shell )
635637
@@ -687,7 +689,9 @@ def format_latex(self, strng: str) -> str:
687689 strng = newline_re .sub (r"\\textbackslash{}n" , strng )
688690 return strng
689691
690- def parse_options (self , arg_str , opt_str , * long_opts , ** kw ):
692+ def parse_options (
693+ self , arg_str : str , opt_str : str , * long_opts : str , ** kw : Any
694+ ) -> tuple [Any , Any ]:
691695 """Parse options passed to an argument string.
692696
693697 The interface is similar to that of :func:`getopt.getopt`, but it
@@ -737,10 +741,10 @@ def parse_options(self, arg_str, opt_str, *long_opts, **kw):
737741 if len (args ) >= 1 :
738742 # If the list of inputs only has 0 or 1 thing in it, there's no
739743 # need to look for options
740- argv = arg_split (arg_str , posix , strict )
744+ argv = arg_split (arg_str , posix , strict ) # type: ignore[no-untyped-call]
741745 # Do regular option processing
742746 try :
743- opts , args = getopt (argv , opt_str , long_opts )
747+ opts , args = getopt (argv , opt_str , long_opts ) # type: ignore[arg-type]
744748 except GetoptError as e :
745749 raise UsageError (
746750 '%s (allowed: "%s"%s)'
@@ -769,23 +773,15 @@ def parse_options(self, arg_str, opt_str, *long_opts, **kw):
769773 odict [o ] = a
770774
771775 # Prepare opts,args for return
772- opts = Struct (odict ) # type: ignore[assignment]
776+ opts = Struct (odict ) # type: ignore[assignment, no-untyped-call ]
773777 if mode == "string" :
774778 if preserve_non_opts :
775- args = remainder_arg_str .lstrip ()
779+ args = remainder_arg_str .lstrip () # type: ignore[assignment]
776780 else :
777- args = " " .join (args )
781+ args = " " .join (args ) # type: ignore[assignment]
778782
779783 return opts , args
780784
781- def default_option (self , fn , optstr ):
782- """Make an entry in the options_table for fn, with value optstr"""
783- assert False , "is this even called?"
784- if fn not in self .lsmagic ():
785- error ("%s is not a magic function" % fn )
786- self .options_table [fn ] = optstr
787-
788-
789785class MagicAlias :
790786 """An alias to another magic function.
791787
@@ -797,7 +793,13 @@ class MagicAlias:
797793 `%alias_magic` magic function to create and register a new alias.
798794 """
799795
800- def __init__ (self , shell , magic_name , magic_kind , magic_params = None ):
796+ def __init__ (
797+ self ,
798+ shell : InteractiveShell ,
799+ magic_name : str ,
800+ magic_kind : _MagicKind ,
801+ magic_params : str | None = None ,
802+ ) -> None :
801803 self .shell = shell
802804 self .magic_name = magic_name
803805 self .magic_params = magic_params
@@ -808,9 +810,9 @@ def __init__(self, shell, magic_name, magic_kind, magic_params=None):
808810
809811 self ._in_call = False
810812
811- def __call__ (self , * args , ** kwargs ) :
813+ def __call__ (self , * args : Any , ** kwargs : Any ) -> Any :
812814 """Call the magic alias."""
813- fn = self .shell .find_magic (self .magic_name , self .magic_kind )
815+ fn = self .shell .find_magic (self .magic_name , self .magic_kind ) # type: ignore[no-untyped-call]
814816 if fn is None :
815817 raise UsageError ("Magic `%s` not found." % self .pretty_target )
816818
0 commit comments