Skip to content

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

Merged
itamaro merged 1 commit into
python:3.15from
miss-islington:backport-230917f-3.15
Oct 19, 2026
Merged

itamaro merged 1 commit into
python:3.15from
miss-islington:backport-230917f-3.15

Conversation

@miss-islington

@miss-islington miss-islington commented Oct 19, 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

…thonGH-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)

Co-authored-by: Harjoth Khara <harjoth.khara@gmail.com>
@read-the-docs-community

Copy link
Copy Markdown

@itamaro
itamaro enabled auto-merge (squash) October 19, 2026 18:30
@itamaro
itamaro merged commit 47e4ba6 into python:3.15 Oct 19, 2026
62 checks passed
@miss-islington
miss-islington deleted the backport-230917f-3.15 branch October 19, 2026 18:55
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.

3 participants