Skip to content

gh-157384: Accept non-ASCII names in PyImport_CreateModuleFromInitfunc() - #157390

Open
itamaro wants to merge 1 commit into
python:mainfrom
itamaro:gh-116146-initfunc-nonascii
Open

itamaro wants to merge 1 commit into
python:mainfrom
itamaro:gh-116146-initfunc-nonascii

Conversation

@itamaro

@itamaro itamaro commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

The builtin loader info encoded the module name as ASCII, so a non-ASCII spec name failed with UnicodeEncodeError even for multi-phase init modules, which support such names when loaded dynamically. Fall back to UTF-8 and mark the name as non-ASCII, so that multi-phase init works and single-phase init is rejected with the same error as for dynamically loaded extensions.

AI assisted with Claude Fable 5.1

…nitfunc()

The builtin loader info encoded the module name as ASCII, so a
non-ASCII spec name failed with UnicodeEncodeError even for multi-phase
init modules, which support such names when loaded dynamically.  Fall
back to UTF-8 and mark the name as non-ASCII, so that multi-phase init
works and single-phase init is rejected with the same error as for
dynamically loaded extensions.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HoZE3WdRWQshvinfBZ137N
@encukou

encukou commented Sep 14, 2026

Copy link
Copy Markdown
Member

Out of curiosity (and to inform future prioritization), did this actually come up in practice?

PyInit is soft-deprecated so I'm not too happy adding features, but yeah, this is a valid bugfix.

As a nitpick, mödul isn't a good test name -- it's always encoded in the source, so the fact that it's a mangled word doesn't help readers; also the following d needs the workaround in the C literals.
Consider "mod\N{MICRO SIGN}_sp", or even "mod\N{SNAKE}_sp"?

@itamaro

itamaro commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

Out of curiosity (and to inform future prioritization), did this actually come up in practice?

no, this didn't come up in the real world, it was something claude flagged while looking into the single-phase init issue.

I don't feel strongly about this fix, if you think it's not worth it, we can drop it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review needs backport to 3.15 pre-release feature fixes, bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants