Browse Source

bpo-35923: Update the BuiltinImporter to use loader._ORIGIN instead of a hard-coded value (GH-15651)

pull/13783/head
Dong-hee Na 6 years ago
committed by Brett Cannon
parent
commit
145cf1f50c
  1. 6
      Lib/importlib/_bootstrap.py
  2. 2
      Misc/NEWS.d/next/Library/2019-09-03-01-41-35.bpo-35923.lYpKbY.rst
  3. 1509
      Python/importlib.h

6
Lib/importlib/_bootstrap.py

@ -713,6 +713,8 @@ class BuiltinImporter:
"""
_ORIGIN = "built-in"
@staticmethod
def module_repr(module):
"""Return repr for the module.
@ -720,14 +722,14 @@ class BuiltinImporter:
The method is deprecated. The import machinery does the job itself.
"""
return '<module {!r} (built-in)>'.format(module.__name__)
return f'<module {module.__name__!r} ({BuiltinImporter._ORIGIN})>'
@classmethod
def find_spec(cls, fullname, path=None, target=None):
if path is not None:
return None
if _imp.is_builtin(fullname):
return spec_from_loader(fullname, cls, origin='built-in')
return spec_from_loader(fullname, cls, origin=cls._ORIGIN)
else:
return None

2
Misc/NEWS.d/next/Library/2019-09-03-01-41-35.bpo-35923.lYpKbY.rst

@ -0,0 +1,2 @@
Update :class:`importlib.machinery.BuiltinImporter` to use ``loader._ORIGIN``
instead of a hardcoded value. Patch by Dong-hee Na.

1509
Python/importlib.h
File diff suppressed because it is too large
View File

Loading…
Cancel
Save