Skip to content

gh-158889: Fix recursive lookup of the iconv filesystem codec - #162843

Open
MakStashkevich wants to merge 1 commit into
python:mainfrom
MakStashkevich:fix/gh-158889
Open

MakStashkevich wants to merge 1 commit into
python:mainfrom
MakStashkevich:fix/gh-158889

Conversation

@MakStashkevich

@MakStashkevich MakStashkevich commented Nov 29, 2026 •

Copy link
Copy Markdown

Fixes #158889.

Clearing the codec caches causes an iconv-backed filesystem encoding to go through the built-in codec search again. Importing a codec module requires encoding the module path with that same filesystem codec, which re-enters the search.

Remember the built-in module miss for the filesystem encoding once the iconv fallback supplies it. Add a regression test that clears both caches and checks that a non-ASCII path still encodes and decodes.

Testing

  • Fedora 44 with hy_AM.armscii8 and UTF-8 mode disabled. The regression test fails with RecursionError before the fix and passes after it. The full test_codecs module passes with the fix.
  • Fedora 44 with C.UTF-8. test_codecs, test_sys, test_locale, and test_embed pass.

@python-cla-bot

python-cla-bot Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@picnixz picnixz added the AI-needs-explanation AI-assisted work that needs further explanation and follow up from the contributor label Nov 29, 2026
@bedevere-app

bedevere-app Bot commented Nov 29, 2026

Copy link
Copy Markdown

Thank you for your interest in contributing to Python. This is a community-driven project, and we want it to be a welcoming place to learn and collaborate.

Contributors are responsible for reviewing and understanding what they submit, checking its claims, and being able to explain changes in their own words. This helps reviewers focus on the contribution and leaves more time to support other contributors.

This contribution appears to have been authored with AI assistance. Please explain your contribution in your own words and describe how you checked its correctness.

Please read our guidelines for using AI tools.

@picnixz picnixz added AI-guidelines-not-met The contribution does not meet our guidelines for using AI tools and is closed automatically. and removed AI-needs-explanation AI-assisted work that needs further explanation and follow up from the contributor labels Nov 29, 2026
@bedevere-app

bedevere-app Bot commented Nov 29, 2026

Copy link
Copy Markdown

Thank you for your interest in contributing to Python. This is a community-driven project, and we want it to be a welcoming place to learn and collaborate.

Contributors are responsible for reviewing and understanding what they submit, checking its claims, and being able to explain changes in their own words. This helps reviewers focus on the contribution and leaves more time to support other contributors.

We believe this contribution does not meet our guidelines for using AI tools, so we're closing it. If you think we've misunderstood your contribution, please let us know. You're welcome to explain your approach or ask questions about the guidelines.

Please read our guidelines for using AI tools.

@bedevere-app bedevere-app Bot closed this Nov 29, 2026
@picnixz

picnixz commented Nov 29, 2026

Copy link
Copy Markdown
Member

Sorry applied the wrong label, I wanted the AI explanation.

@MakStashkevich

Copy link
Copy Markdown
Author

Thanks for clarifying. After the codec caches are cleared, looking up the filesystem encoding tries to import a codec module. Resolving that module’s path needs the same encoding, so the lookup recurses. The fix remembers that there’s no built-in module for this encoding and lets the lookup proceed to iconv().

On Fedora 44 with hy_AM.armscii8 and UTF-8 mode disabled, the regression test failed with RecursionError before the fix and passed afterward. The full test_codecs module also passed in that locale.

Could you reopen the PR for review?

@picnixz picnixz reopened this Nov 29, 2026
@picnixz picnixz removed the AI-guidelines-not-met The contribution does not meet our guidelines for using AI tools and is closed automatically. label Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unlimited loop on trying to import the module of the filesystem encoding if iconv() is used

2 participants