@@ -275,7 +275,7 @@ def _requires_frozen_wrapper(self, fullname):
275275def _load_module_shim (self , fullname ):
276276 """Load the specified module into sys.modules and return it.
277277
278- This method is deprecated. Use loader.exec_module instead.
278+ This method is deprecated. Use loader.exec_module() instead.
279279
280280 """
281281 msg = ("the load_module() method is deprecated and slated for removal in "
@@ -292,24 +292,16 @@ def _load_module_shim(self, fullname):
292292# Module specifications #######################################################
293293
294294def _module_repr (module ):
295- # The implementation of ModuleType.__repr__().
295+ """ The implementation of ModuleType.__repr__()."""
296296 loader = getattr (module , '__loader__' , None )
297- if hasattr (loader , 'module_repr' ):
298- # As soon as BuiltinImporter, FrozenImporter, and NamespaceLoader
299- # drop their implementations for module_repr. we can add a
300- # deprecation warning here.
297+ if spec := getattr (module , "__spec__" , None ):
298+ return _module_repr_from_spec (spec )
299+ elif hasattr (loader , 'module_repr' ):
301300 try :
302301 return loader .module_repr (module )
303302 except Exception :
304303 pass
305- try :
306- spec = module .__spec__
307- except AttributeError :
308- pass
309- else :
310- if spec is not None :
311- return _module_repr_from_spec (spec )
312-
304+ # Fall through to a catch-all which always succeeds.
313305 # We could use module.__class__.__name__ instead of 'module' in the
314306 # various repr permutations.
315307 try :
0 commit comments