Skip to content

gh-162531: clean up stale pyo references in the build and zipimport - #162532

Merged
hugovk merged 3 commits into
python:mainfrom
tonghuaroot:cleanup-pyo-references-20261124
Nov 30, 2026
Merged

hugovk merged 3 commits into
python:mainfrom
tonghuaroot:cleanup-pyo-references-20261124

Conversation

@tonghuaroot

@tonghuaroot tonghuaroot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

clean up legacy .pyo references in build and install scripts, and keep the zipimport changes to comments and assertions.

https://discuss.python.org/t/updating-old-patch-to-run-on-3-16-getting-weird-errors/110249/9

@hugovk hugovk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, here's some more we can clean up:

*.py[co]) ;; \

*.pyo

*.py[co]) ;; \

if name.endswith('.pyo'): return 0

if fn.endswith('.pyc') or fn.endswith('.pyo'):

if name.endswith(('.pyc', '.pyo')):

echo Deleting .pyc/.pyo files ...
del /s "%root%\Lib\*.pyc" "%root%\Lib\*.pyo"

Comment thread Lib/zipimport.py Outdated
# non-package .pyc, and .py entries. The .pyc entries
# are swapped by initzipimport() if we run in optimized mode. Also,
# '/' is replaced by path_sep there.
# Search for packages before modules, and for bytecode before source.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep these comment diffs to a minimum:

Suggested change
# Search for packages before modules, and for bytecode before source.
# _zip_searchorder defines how we search for a module in the Zip
# archive: we first search for a package __init__, then for
# non-package .pyc, and .py entries.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, updated the cleanup paths and kept the zipimport comment changes minimal.

Comment thread Lib/zipimport.py Outdated
if _importing_zlib:
# Someone has a zlib.py[co] in their Zip file
# let's avoid a stack overflow.
# Importing zlib from the archive would recurse.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Importing zlib from the archive would recurse.
# Someone has a zlib.pyc in their Zip file
# let's avoid a stack overflow.

Comment thread Lib/zipimport.py Outdated
if _importing_zstd:
# Someone has a _zstd.py[co] in their Zip file
# let's avoid a stack overflow.
# Importing _zstd from the archive would recurse.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Importing _zstd from the archive would recurse.
# Someone has a _zstd.pyc in their Zip file
# let's avoid a stack overflow.

Comment thread Lib/zipimport.py Outdated
# Given the contents of a .py[co] file, unmarshal the data
# and return the code object. Raises ImportError it the magic word doesn't
# match, or if the recorded .py[co] metadata does not match the source.
# Unmarshal the code object from a .pyc file.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Unmarshal the code object from a .pyc file.
# Given the contents of a .pyc file, unmarshal the data
# and return the code object. Raises ImportError it the magic word doesn't
# match, or if the recorded .pyc metadata does not match the source.

Comment thread Lib/zipimport.py
def _get_pyc_source(self, path):
# strip 'c' or 'o' from *.py[co]
assert path[-1:] in ('c', 'o')
assert path.endswith('.pyc')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert path.endswith('.pyc')
# # strip 'c' from *.pyc
assert path.endswith('.pyc')

@tonghuaroot
tonghuaroot requested review from a team as code owners November 24, 2026 15:00

@hugovk hugovk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ned-deily ned-deily left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in Mac/ LGTM.

@hugovk
hugovk merged commit b248bf1 into python:main Nov 30, 2026
56 checks passed
@hugovk hugovk added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Nov 30, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @tonghuaroot for the PR, and @hugovk for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Thanks @tonghuaroot for the PR, and @hugovk for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Sorry, @tonghuaroot and @hugovk, I could not cleanly backport this to 3.14 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker b248bf191685221bbe5080aa8f8631246a63d731 3.14

@bedevere-app

bedevere-app Bot commented Nov 30, 2026

Copy link
Copy Markdown

GH-162862 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Nov 30, 2026
@hugovk

hugovk commented Nov 30, 2026

Copy link
Copy Markdown
Member

@tonghuaroot Would you like to do the 3.14 backport? Thank you.

@bedevere-app

bedevere-app Bot commented Nov 30, 2026

Copy link
Copy Markdown

GH-162866 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 Nov 30, 2026
hugovk pushed a commit that referenced this pull request Nov 30, 2026
…mport (GH-162532) (#162862)

gh-162531: clean up stale pyo references in the build and zipimport (GH-162532)
(cherry picked from commit b248bf1)

Co-authored-by: tonghuaroot (童话) <tonghuaroot@gmail.com>
hugovk pushed a commit that referenced this pull request Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants