mirror of
https://github.com/python/cpython.git
synced 2025-08-29 21:25:01 +00:00
Implement InspectLoader for BuiltinImporter.
This commit is contained in:
parent
7aa21f75c1
commit
a113ac58be
7 changed files with 91 additions and 32 deletions
|
@ -173,6 +173,16 @@ def _check_name(method):
|
|||
return inner
|
||||
|
||||
|
||||
def _requires_builtin(fxn):
|
||||
"""Decorator to verify the named module is built-in."""
|
||||
def wrapper(self, fullname):
|
||||
if fullname not in sys.builtin_module_names:
|
||||
raise ImportError("{0} is not a built-in module".format(fullname))
|
||||
return fxn(self, fullname)
|
||||
_wrap(wrapper, fxn)
|
||||
return wrapper
|
||||
|
||||
|
||||
def _suffix_list(suffix_type):
|
||||
"""Return a list of file suffixes based on the imp file type."""
|
||||
return [suffix[0] for suffix in imp.get_suffixes()
|
||||
|
@ -204,10 +214,9 @@ class BuiltinImporter:
|
|||
@classmethod
|
||||
@set_package
|
||||
@set_loader
|
||||
@_requires_builtin
|
||||
def load_module(cls, fullname):
|
||||
"""Load a built-in module."""
|
||||
if fullname not in sys.builtin_module_names:
|
||||
raise ImportError("{0} is not a built-in module".format(fullname))
|
||||
is_reload = fullname in sys.modules
|
||||
try:
|
||||
return imp.init_builtin(fullname)
|
||||
|
@ -216,6 +225,24 @@ class BuiltinImporter:
|
|||
del sys.modules[fullname]
|
||||
raise
|
||||
|
||||
@classmethod
|
||||
@_requires_builtin
|
||||
def get_code(cls, fullname):
|
||||
"""Return None as built-in modules do not have code objects."""
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
@_requires_builtin
|
||||
def get_source(cls, fullname):
|
||||
"""Return None as built-in modules do not have source code."""
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
@_requires_builtin
|
||||
def is_package(cls, fullname):
|
||||
"""Return None as built-in module are never packages."""
|
||||
return False
|
||||
|
||||
|
||||
class FrozenImporter:
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue