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

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

Conversation

patchback[bot]
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
29 checks passed
@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