Skip to content

[PR #13029/8cff1286 backport][8.3.x] fix AttributeError crash when using --import-mode=importlib#13037

Merged
nicoddemus merged 1 commit into8.3.xfrom
patchback/backports/8.3.x/8cff12865691b14b4bce70e0e304524619be385d/pr-13029
Dec 7, 2024
Merged

[PR #13029/8cff1286 backport][8.3.x] fix AttributeError crash when using --import-mode=importlib#13037
nicoddemus merged 1 commit into8.3.xfrom
patchback/backports/8.3.x/8cff12865691b14b4bce70e0e304524619be385d/pr-13029

Conversation

@patchback
Copy link

@patchback patchback bot commented Dec 7, 2024

This is a backport of PR #13029 as merged into main (8cff128).

closes #13026 .

  • Include new tests or update existing tests when applicable.
  • Allow maintainers to push and squash when merging my commits.
  • Create a new changelog file in the changelog folder.

Only parent modules with the __path__ attribute can be used by the find_spec function, and most of the standard library does not meet this condition.

https://github.com/python/cpython/blob/3.9/Lib/importlib/_bootstrap_external.py#L1223

   def _find_parent_path_names(self):
        """Returns a tuple of (parent-module-name, parent-path-attr-name)"""
        parent, dot, me = self._name.rpartition('.')
        if dot == '':
            # This is a top-level module. sys.path contains the parent path.
            return 'sys', 'path'
        # Not a top-level module. parent-module.__path__ contains the
        #  parent path.
        return parent, '__path__'

So this PR adds a condition check.

Only parent modules with the `__path__` attribute can be used by the `find_spec` function, and most of the standard library does not meet this condition.

Fixes #13026 .

(cherry picked from commit 8cff128)
@nicoddemus nicoddemus enabled auto-merge (squash) December 7, 2024 13:42
@nicoddemus nicoddemus merged commit 179b690 into 8.3.x Dec 7, 2024
@nicoddemus nicoddemus deleted the patchback/backports/8.3.x/8cff12865691b14b4bce70e0e304524619be385d/pr-13029 branch December 7, 2024 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants