1818import enum
1919from functools import lru_cache
2020import glob
21+ import importlib
2122import importlib .metadata
2223import inspect
2324import os
@@ -874,7 +875,13 @@ def import_plugin(self, modname: str, consider_entry_points: bool = False) -> No
874875 return
875876
876877 try :
877- __import__ (importspec )
878+ if sys .version_info >= (3 , 11 ):
879+ mod = importlib .import_module (importspec )
880+ else :
881+ # On Python 3.10, import_module breaks
882+ # testing/test_config.py::test_disable_plugin_autoload.
883+ __import__ (importspec )
884+ mod = sys .modules [importspec ]
878885 except ImportError as e :
879886 raise ImportError (
880887 f'Error importing plugin "{ modname } ": { e .args [0 ]} '
@@ -883,7 +890,6 @@ def import_plugin(self, modname: str, consider_entry_points: bool = False) -> No
883890 except Skipped as e :
884891 self .skipped_plugins .append ((modname , e .msg or "" ))
885892 else :
886- mod = sys .modules [importspec ]
887893 self .register (mod , modname )
888894
889895
@@ -2122,7 +2128,7 @@ def _resolve_warning_category(category: str) -> type[Warning]:
21222128 klass = category
21232129 else :
21242130 module , _ , klass = category .rpartition ("." )
2125- m = __import__ (module , None , None , [ klass ] )
2131+ m = importlib . import_module (module )
21262132 cat = getattr (m , klass )
21272133 if not issubclass (cat , Warning ):
21282134 raise UsageError (f"{ cat } is not a Warning subclass" )
0 commit comments