Commit e4314e05 authored by Eric Snow's avatar Eric Snow

Issue 19713: Remove PEP 451-related code that should have been factored out.

This code was an artifact of issuing a DeprecationWarning for the lack
of loader.exec_module().  However, we have deferred such warnings to
later Python versions.
parent 2e385e25
...@@ -994,25 +994,11 @@ class _SpecMethods: ...@@ -994,25 +994,11 @@ class _SpecMethods:
"""Convenience wrapper around spec objects to provide spec-specific """Convenience wrapper around spec objects to provide spec-specific
methods.""" methods."""
# The various spec_from_* functions could be made factory methods here.
def __init__(self, spec): def __init__(self, spec):
self.spec = spec self.spec = spec
@classmethod
def from_module(cls, module):
"""Create a spec from a module's attributes."""
try:
spec = module.__spec__
except AttributeError:
try:
loader = spec.__loader__
except AttributeError:
spec = _find_spec(module.__name__)
if spec is None:
spec = spec_from_loader(module.__name__, loader)
else:
spec = spec_from_loader(module.__name__, loader)
return cls(spec)
def module_repr(self): def module_repr(self):
"""Return the repr to use for the module.""" """Return the repr to use for the module."""
# We mostly replicate _module_repr() using the spec attributes. # We mostly replicate _module_repr() using the spec attributes.
...@@ -1171,14 +1157,8 @@ class _SpecMethods: ...@@ -1171,14 +1157,8 @@ class _SpecMethods:
# have exec_module() implemented, we can add a deprecation # have exec_module() implemented, we can add a deprecation
# warning here. # warning here.
spec = self.spec spec = self.spec
# The module must be in sys.modules! spec.loader.load_module(spec.name)
try: # The module must be in sys.modules at this point!
_warnings
except NameError:
# We must be importing builtins in setup().
spec.loader.load_module(spec.name)
else:
spec.loader.load_module(spec.name)
module = sys.modules[spec.name] module = sys.modules[spec.name]
if getattr(module, '__loader__', None) is None: if getattr(module, '__loader__', None) is None:
try: try:
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment