Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e4314e0

Browse files
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.
1 parent 2e385e2 commit e4314e0

2 files changed

Lines changed: 1191 additions & 1240 deletions

File tree

Lib/importlib/_bootstrap.py

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -994,25 +994,11 @@ class _SpecMethods:
994994
"""Convenience wrapper around spec objects to provide spec-specific
995995
methods."""
996996

997+
# The various spec_from_* functions could be made factory methods here.
998+
997999
def __init__(self, spec):
9981000
self.spec = spec
9991001

1000-
@classmethod
1001-
def from_module(cls, module):
1002-
"""Create a spec from a module's attributes."""
1003-
try:
1004-
spec = module.__spec__
1005-
except AttributeError:
1006-
try:
1007-
loader = spec.__loader__
1008-
except AttributeError:
1009-
spec = _find_spec(module.__name__)
1010-
if spec is None:
1011-
spec = spec_from_loader(module.__name__, loader)
1012-
else:
1013-
spec = spec_from_loader(module.__name__, loader)
1014-
return cls(spec)
1015-
10161002
def module_repr(self):
10171003
"""Return the repr to use for the module."""
10181004
# We mostly replicate _module_repr() using the spec attributes.
@@ -1171,14 +1157,8 @@ def _load_backward_compatible(self):
11711157
# have exec_module() implemented, we can add a deprecation
11721158
# warning here.
11731159
spec = self.spec
1174-
# The module must be in sys.modules!
1175-
try:
1176-
_warnings
1177-
except NameError:
1178-
# We must be importing builtins in setup().
1179-
spec.loader.load_module(spec.name)
1180-
else:
1181-
spec.loader.load_module(spec.name)
1160+
spec.loader.load_module(spec.name)
1161+
# The module must be in sys.modules at this point!
11821162
module = sys.modules[spec.name]
11831163
if getattr(module, '__loader__', None) is None:
11841164
try:

0 commit comments

Comments
 (0)