Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernise built-in submodule importer #97

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions runtime/site3.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,29 +66,28 @@
# Submodule importing ##########################################################

# Allow Python to import submodules.
import imp
import importlib.machinery
import importlib.util


class BuiltinSubmoduleImporter(object):
class BuiltinSubmoduleImporter:

def find_module(self, name, path=None):
@staticmethod
def find_spec(fullname, path=None, target=None):
if path is None:
return None

if "." not in name:
if "." not in fullname:
return None

if name in sys.builtin_module_names:
return self

return None
if fullname not in sys.builtin_module_names:
return None

def load_module(self, name):
f, pathname, desc = imp.find_module(name, None)
return imp.load_module(name, f, pathname, desc)
i = importlib.machinery.BuiltinImporter
return importlib.util.spec_from_loader(fullname, i, origin=i._ORIGIN)


sys.meta_path.append(BuiltinSubmoduleImporter())
sys.meta_path.append(BuiltinSubmoduleImporter)

# Windows Startup ##############################################################

Expand Down