Skip to content

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

Open
tonghuaroot wants to merge 2 commits into
python:mainfrom
tonghuaroot:cleanup-pyo-references-20261124
Open

tonghuaroot wants to merge 2 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!

Comment on lines +1 to +2
``make pycremoval`` no longer removes legacy ``.pyo`` files outside
``__pycache__`` directories.

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
``make pycremoval`` no longer removes legacy ``.pyo`` files outside
``__pycache__`` directories.
Remove obsolete references to ``.pyo`` files from the build, install and
clean scripts. Python has not created ``.pyo`` files since 3.5 (:pep:`488`).

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