Skip to content

Commit

Permalink
Merge pull request #97 from mal/modernise-importer
Browse files Browse the repository at this point in the history
Modernise built-in submodule importer
  • Loading branch information
renpytom authored Dec 17, 2024
2 parents c9412db + 8ad987d commit d219c29
Showing 1 changed file with 11 additions and 12 deletions.
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

0 comments on commit d219c29

Please sign in to comment.