From 6a8de2e8f61bc65e71708d5e5a34cc67f235b7e5 Mon Sep 17 00:00:00 2001 From: Erik Welch Date: Wed, 15 Jun 2022 13:22:44 -0500 Subject: [PATCH 1/2] Fix Tlz error in Python 3.11 (alpha) --- .github/workflows/test.yml | 13 ++++++++++++- tlz/_build_tlz.py | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8fcc27b6..2ebc80c1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,18 @@ jobs: fail-fast: false matrix: os: ["ubuntu-latest"] - python-version: [3.5, 3.6, 3.7, 3.8, 3.9, "3.10", "pypy-3.6", "pypy-3.7", "pypy-3.8"] + python-version: + - "3.5" + - "3.6" + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11.0-alpha - 3.11.0" + - "pypy-3.6" + - "pypy-3.7" + - "pypy-3.8" + - "pypy-3.9" steps: - name: Checkout uses: actions/checkout@v2 diff --git a/tlz/_build_tlz.py b/tlz/_build_tlz.py index f29eed1b..863199da 100644 --- a/tlz/_build_tlz.py +++ b/tlz/_build_tlz.py @@ -96,6 +96,8 @@ def __init__(self, name, loader): self.cached = None self.parent = None self.has_location = False + # Added in Python 3.11 (to improve circular imports or their errors?) + self._uninitialized_submodules = [] tlz_loader = TlzLoader() From dfbc3d60d33362babe759f6e2c6d3d87f1de06a7 Mon Sep 17 00:00:00 2001 From: Erik Welch Date: Wed, 15 Jun 2022 14:00:20 -0500 Subject: [PATCH 2/2] Use `importlib.machinery.ModuleSpec` instead of `TlzSpec` --- tlz/_build_tlz.py | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/tlz/_build_tlz.py b/tlz/_build_tlz.py index 863199da..3ac78369 100644 --- a/tlz/_build_tlz.py +++ b/tlz/_build_tlz.py @@ -2,9 +2,10 @@ import types import toolz from importlib import import_module +from importlib.machinery import ModuleSpec -class TlzLoader(object): +class TlzLoader: """ Finds and loads ``tlz`` modules when added to sys.meta_path""" def __init__(self): self.always_from_toolz = { @@ -36,7 +37,7 @@ def find_module(self, fullname, path=None): # pragma: py3 no cover def load_module(self, fullname): # pragma: py3 no cover if fullname in sys.modules: # pragma: no cover return sys.modules[fullname] - spec = TlzSpec(fullname, self) + spec = ModuleSpec(fullname, self) module = self.create_module(spec) sys.modules[fullname] = module self.exec_module(module) @@ -45,7 +46,7 @@ def load_module(self, fullname): # pragma: py3 no cover def find_spec(self, fullname, path, target=None): # pragma: no cover package, dot, submodules = fullname.partition('.') if package == 'tlz': - return TlzSpec(fullname, self) + return ModuleSpec(fullname, self) def create_module(self, spec): return types.ModuleType(spec.name) @@ -86,20 +87,6 @@ def exec_module(self, module): module.__dict__[k] = submodule -class TlzSpec(object): - def __init__(self, name, loader): - self.name = name - self.loader = loader - self.origin = None - self.submodule_search_locations = [] - self.loader_state = None - self.cached = None - self.parent = None - self.has_location = False - # Added in Python 3.11 (to improve circular imports or their errors?) - self._uninitialized_submodules = [] - - tlz_loader = TlzLoader() sys.meta_path.append(tlz_loader) tlz_loader.exec_module(sys.modules['tlz'])