Skip to content

bpo-38735: Don't fail when importing from / with sys.pycache_prefix set #30456

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

Merged
merged 6 commits into from
Aug 18, 2025

Conversation

encukou
Copy link
Member

@encukou encukou commented Jan 7, 2022

This fixes the issue, but testing it would require putting a file in the root directory.

https://bugs.python.org/issue38735

gh-#82916

@github-actions
Copy link

github-actions bot commented Feb 7, 2022

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Feb 7, 2022
@serhiy-storchaka
Copy link
Member

You can test it without writing a file.

>>> from importlib.util import cache_from_source
>>> import os
>>> os.chdir('/')
>>> cache_from_source('spam.py')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    cache_from_source('spam.py')
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^
  File "<frozen importlib._bootstrap_external>", line 558, in cache_from_source
IndexError: string index out of range

@encukou encukou merged commit d8a9466 into python:main Aug 18, 2025
41 checks passed
@encukou encukou deleted the cacheprefix-slash branch August 18, 2025 11:53
@encukou encukou added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Aug 18, 2025
@miss-islington-app
Copy link

Thanks @encukou for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Thanks @encukou for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 18, 2025
…et (pythonGH-30456)

(cherry picked from commit d8a9466)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 18, 2025
…et (pythonGH-30456)

(cherry picked from commit d8a9466)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-app
Copy link

bedevere-app bot commented Aug 18, 2025

GH-137905 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Aug 18, 2025
@bedevere-app
Copy link

bedevere-app bot commented Aug 18, 2025

GH-137906 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Aug 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Stale PR or inactive for long period of time.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants