Skip to content

[3.14] gh-141276: Avoid compiling zipimport source in get_filename (GH-153799) - #161504

Open
itamaro wants to merge 2 commits into
python:3.14from
itamaro:backport-153799-to-3.14
Open

itamaro wants to merge 2 commits into
python:3.14from
itamaro:backport-153799-to-3.14

Conversation

@itamaro

@itamaro itamaro commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

zipimporter.get_filename() compiled source modules just to work out the
module's file name. find_spec() calls it through spec_from_loader(), so
importing a source module from a ZIP archive compiled it twice and emitted
every SyntaxWarning twice.

get_filename() now returns before reading or compiling the source.
As a result, a SyntaxError in a zipped source module is now raised by
exec_module() rather than by find_spec() or get_filename(), and
the source isn't compiled twice during import, which matches
the filesystem-based loaders.
(cherry picked from commit 230917f)

Co-authored-by: Harjoth Khara harjoth.khara@gmail.com

…ame (pythonGH-153799)

`zipimporter.get_filename()` compiled source modules just to work out the
module's file name. `find_spec()` calls it through `spec_from_loader()`, so
importing a source module from a ZIP archive compiled it twice and emitted
every `SyntaxWarning` twice.

`get_filename()` now returns before reading or compiling the source.
As a result, a `SyntaxError` in a zipped source module is now raised by
`exec_module()` rather than by `find_spec()` or `get_filename()`, and
the source isn't compiled twice during import, which matches
the filesystem-based loaders.

(cherry picked from commit 230917f)
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.

2 participants