2121# separately in different functions.
2222
2323import ast
24+ from collections .abc import Sequence
2425import configparser
2526import importlib .abc
27+ from importlib .machinery import ModuleSpec
2628import importlib .util
2729import inspect
2830import io
3133import re
3234import string
3335import sys
36+ import types
3437
3538
3639class DimensionError (ValueError ):
@@ -147,8 +150,8 @@ def read(self, filename, encoding=None):
147150 """
148151
149152 def get_options ():
150- options = set ()
151- for sect , opts in self ._sections .items ():
153+ options : set [ str ] = set ()
154+ for sect , opts in self ._sections .items (): # type:ignore[attr-defined]
152155 if sect == "rcParams" :
153156 continue
154157 options .update (f"{ sect } .{ opt } " for opt in opts .keys ())
@@ -172,13 +175,13 @@ def get_options():
172175 def read_kwargs (self , ** kwargs ):
173176 """Read configuration options from keyword arguments."""
174177 # Dictionary of values to load.
175- d = {}
178+ d : dict [ str , dict [ str , str ]] = {}
176179
177180 # Option -> section lookup table.
178181 lookup = {}
179182
180183 # Go through all existing options.
181- for section , options in self ._sections .items ():
184+ for section , options in self ._sections .items (): # type:ignore[attr-defined]
182185 # Can't specify rcParams through kwargs.
183186 if section == "rcParams" :
184187 continue
@@ -342,9 +345,9 @@ def in_tracking_dir(self, type, fn):
342345 # If we can compute a relative path, it must be within the directory.
343346 fn = pathlib .Path (fn ).resolve ()
344347 for path in paths :
345- path = pathlib .Path (path ).resolve ()
348+ resolved = pathlib .Path (path ).resolve ()
346349 try :
347- fn .relative_to (path )
350+ fn .relative_to (resolved )
348351 except ValueError :
349352 continue
350353 return True
@@ -498,10 +501,14 @@ class ImportTracker(importlib.abc.MetaPathFinder):
498501
499502 def __init__ (self ):
500503 super ().__init__ ()
501- self ._avoid_recursion = set ()
502- self .imported = set ()
503-
504- def find_spec (self , fullname , path , target = None ):
504+ self ._avoid_recursion : set [str ] = set ()
505+
506+ def find_spec (
507+ self ,
508+ fullname : str ,
509+ path : Sequence [str ] | None ,
510+ target : types .ModuleType | None = None ,
511+ ) -> ModuleSpec | None :
505512 # According to PEP451, this is mostly intended for a reload. I can't see a way
506513 # (without calling importlib._bootstrap._find_spec, which should not be imported
507514 # according to the note at the top of the module) to pass this information on.
@@ -553,7 +560,7 @@ def _install_standard_file_trackers():
553560 sys .meta_path .insert (0 , ImportTracker ())
554561
555562
556- def _install_extra_file_trackers (trackers ):
563+ def _install_extra_file_trackers (trackers : list [ str ] ):
557564 """Internal: install requested extra file trackers.
558565
559566 Parameters
@@ -729,7 +736,7 @@ def setup_figure(
729736 # matplotlib.is_interactive()) don't appear to propagate when IPython runs a script
730737 # so we can't test those.
731738 try :
732- ipython = get_ipython ()
739+ ipython = get_ipython () # type:ignore[name-defined]
733740 except NameError :
734741 pass
735742 else :
0 commit comments