From adf2005c6ac6cee0004402feb2946fe99c0dccd0 Mon Sep 17 00:00:00 2001 From: Peter Ebden Date: Thu, 17 Sep 2026 16:18:03 +0100 Subject: [PATCH] Handle 'stub' modules that don't have a __spec__ --- tools/please_pex/ChangeLog | 4 ++++ tools/please_pex/VERSION | 2 +- tools/please_pex/pex/plz.py | 7 ++++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/please_pex/ChangeLog b/tools/please_pex/ChangeLog index 429937e..1083187 100644 --- a/tools/please_pex/ChangeLog +++ b/tools/please_pex/ChangeLog @@ -1,3 +1,7 @@ +Version 3.0.4 +------------- + * Handle 'stub' modules that don't have a __spec__ + Version 3.0.3 ------------- * Fix `importlib.resources` for some usages relating to packages in module_dir (#324) diff --git a/tools/please_pex/VERSION b/tools/please_pex/VERSION index 75a22a2..b0f2dcb 100644 --- a/tools/please_pex/VERSION +++ b/tools/please_pex/VERSION @@ -1 +1 @@ -3.0.3 +3.0.4 diff --git a/tools/please_pex/pex/plz.py b/tools/please_pex/pex/plz.py index aa396e1..1f5cadb 100644 --- a/tools/please_pex/pex/plz.py +++ b/tools/please_pex/pex/plz.py @@ -154,9 +154,10 @@ def create_module(self, spec): # Carry over submodule_search_locations from the real module's spec, otherwise # importlib.resources (which relies on it to find a package's files) breaks once # the module's __spec__ gets overwritten with this one. - real_spec = module.__spec__ - spec.submodule_search_locations = real_spec.submodule_search_locations - self._real_specs[spec.name] = real_spec + real_spec = getattr(module, "__spec__", None) + if real_spec is not None: + spec.submodule_search_locations = real_spec.submodule_search_locations + self._real_specs[spec.name] = real_spec sys.modules[spec.name] = module return module