mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
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.
This commit is contained in:
parent
2e385e2592
commit
e4314e05d5
2 changed files with 1192 additions and 1241 deletions
|
@ -994,25 +994,11 @@ class _SpecMethods:
|
|||
"""Convenience wrapper around spec objects to provide spec-specific
|
||||
methods."""
|
||||
|
||||
# The various spec_from_* functions could be made factory methods here.
|
||||
|
||||
def __init__(self, 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):
|
||||
"""Return the repr to use for the module."""
|
||||
# We mostly replicate _module_repr() using the spec attributes.
|
||||
|
@ -1171,14 +1157,8 @@ class _SpecMethods:
|
|||
# have exec_module() implemented, we can add a deprecation
|
||||
# warning here.
|
||||
spec = self.spec
|
||||
# The module must be in sys.modules!
|
||||
try:
|
||||
_warnings
|
||||
except NameError:
|
||||
# We must be importing builtins in setup().
|
||||
spec.loader.load_module(spec.name)
|
||||
else:
|
||||
spec.loader.load_module(spec.name)
|
||||
# The module must be in sys.modules at this point!
|
||||
module = sys.modules[spec.name]
|
||||
if getattr(module, '__loader__', None) is None:
|
||||
try:
|
||||
|
|
2405
Python/importlib.h
2405
Python/importlib.h
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue