diff --git a/.gitignore b/.gitignore index 55eb5646c6e24f..ae5d3971d68397 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,6 @@ *.orig *.pyc *.pyd -*.pyo *.rej *.swp *~ diff --git a/InternalDocs/interpreter.md b/InternalDocs/interpreter.md index 75acdf596a7f30..48cd501758ee02 100644 --- a/InternalDocs/interpreter.md +++ b/InternalDocs/interpreter.md @@ -334,14 +334,13 @@ argument in a special way (like `FORMAT_VALUE` or `MAKE_FUNCTION`). If you make a change here that can affect the output of bytecode that is already in existence and you do not change the magic number, make -sure to delete your old .py(c|o) files! Even though you will end up changing +sure to delete your old .pyc files! Even though you will end up changing the magic number if you change the bytecode, while you are debugging your work you may be changing the bytecode output without constantly bumping up the magic number. This can leave you with stale .pyc files that will not be recreated. -Running `find . -name '*.py[co]' -exec rm -f '{}' +` should delete all .pyc -files you have, forcing new ones to be created and thus allow you test out your -new bytecode properly. Run `make regen-importlib` for updating the +Run `make pycremoval` to delete the .pyc files in your source tree before +testing your new bytecode. Run `make regen-importlib` for updating the bytecode of frozen importlib files. You have to run `make` again after this to recompile the generated C files. diff --git a/Lib/zipimport.py b/Lib/zipimport.py index 97ad77aa41ae2a..5bf40d3361c2ff 100644 --- a/Lib/zipimport.py +++ b/Lib/zipimport.py @@ -288,9 +288,7 @@ def __repr__(self): # _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. The .pyc entries -# are swapped by initzipimport() if we run in optimized mode. Also, -# '/' is replaced by path_sep there. +# non-package .pyc, and .py entries. _zip_searchorder = ( (path_sep + '__init__.pyc', True, True), (path_sep + '__init__.py', False, True), @@ -616,7 +614,7 @@ def _read_directory(archive): def _get_decompress_func(): global _importing_zlib if _importing_zlib: - # Someone has a zlib.py[co] in their Zip file + # Someone has a zlib.pyc in their Zip file # let's avoid a stack overflow. _bootstrap._verbose_message('zipimport: zlib UNAVAILABLE') raise ZipImportError("can't decompress data; zlib not available") @@ -685,9 +683,9 @@ def _eq_mtime(t1, t2): return abs(t1 - t2) <= 1 -# 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. +# Given the contents of a .pyc file, unmarshal the data +# and return the code object. Raises ImportError if the magic word doesn't +# match, or if the recorded .pyc hash fails validation. def _unmarshal_code(self, pathname, fullpath, fullname, data): exc_details = { 'name': fullname, @@ -761,8 +759,8 @@ def _parse_dostime(d, t): # or (0, 0) if no source is available. def _get_mtime_and_size_of_source(self, path): try: - # strip 'c' or 'o' from *.py[co] - assert path[-1:] in ('c', 'o') + # strip 'c' from *.pyc + assert path.endswith('.pyc') path = path[:-1] toc_entry = self._get_files()[path] # fetch the time stamp of the .py file for comparison @@ -779,8 +777,8 @@ def _get_mtime_and_size_of_source(self, path): # contents of the matching .py file, or None if no source # is available. def _get_pyc_source(self, path): - # strip 'c' or 'o' from *.py[co] - assert path[-1:] in ('c', 'o') + # strip 'c' from *.pyc + assert path.endswith('.pyc') path = path[:-1] try: diff --git a/Mac/BuildScript/build-installer.py b/Mac/BuildScript/build-installer.py index 0db92cff47c6eb..2bb0364f0a5531 100755 --- a/Mac/BuildScript/build-installer.py +++ b/Mac/BuildScript/build-installer.py @@ -1553,7 +1553,7 @@ def buildInstaller(): # Zap all compiled files for dirpath, _, filenames in os.walk(os.path.join(WORKDIR, '_root')): for fn in filenames: - if fn.endswith('.pyc') or fn.endswith('.pyo'): + if fn.endswith('.pyc'): os.unlink(os.path.join(dirpath, fn)) outdir = os.path.join(WORKDIR, 'installer') diff --git a/Mac/Extras.install.py b/Mac/Extras.install.py index 41bfa53d616307..227aa11cd3dc41 100644 --- a/Mac/Extras.install.py +++ b/Mac/Extras.install.py @@ -15,7 +15,6 @@ def isclean(name): if name.endswith('~'): return 0 if name.endswith('.BAK'): return 0 if name.endswith('.pyc'): return 0 - if name.endswith('.pyo'): return 0 if name.endswith('.orig'): return 0 return 1 diff --git a/Mac/Makefile.in b/Mac/Makefile.in index 32e3a0f55c5d71..dfeafc04ff3bd0 100644 --- a/Mac/Makefile.in +++ b/Mac/Makefile.in @@ -204,7 +204,7 @@ install_Python: case $$i in \ *CVS) ;; \ *.svn) ;; \ - *.py[co]) ;; \ + *.pyc) ;; \ *.orig) ;; \ *~) ;; \ *idx) \ diff --git a/Makefile.pre.in b/Makefile.pre.in index c861735332dc4a..8577c9fd96c828 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -2804,7 +2804,7 @@ libinstall: all $(srcdir)/Modules/xxmodule.c do \ case $$i in \ *CVS) ;; \ - *.py[co]) ;; \ + *.pyc) ;; \ *.orig) ;; \ *~) ;; \ *) \ @@ -3214,7 +3214,7 @@ TAGS:: .PHONY: pycremoval pycremoval: -find $(srcdir) -depth -name '__pycache__' -exec rm -rf {} ';' - -find $(srcdir) -name '*.py[co]' -exec rm -f {} ';' + -find $(srcdir) -name '*.pyc' -exec rm -f {} ';' .PHONY: rmtestturds rmtestturds: @@ -3240,7 +3240,7 @@ clean-retain-profile: pycremoval find . -name '*.lst' -exec rm -f {} ';' find build -name 'fficonfig.h' -exec rm -f {} ';' || true find build -name '*.py' -exec rm -f {} ';' || true - find build -name '*.py[co]' -exec rm -f {} ';' || true + find build -name '*.pyc' -exec rm -f {} ';' || true -rm -f pybuilddir.txt -rm -f _bootstrap_python -rm -rf web_example python.mjs python.wasm python*.symbols python*.map diff --git a/Misc/NEWS.d/next/Build/2026-11-24-12-10-57.gh-issue-162531.Gw3bY8.rst b/Misc/NEWS.d/next/Build/2026-11-24-12-10-57.gh-issue-162531.Gw3bY8.rst new file mode 100644 index 00000000000000..83e76237725df8 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2026-11-24-12-10-57.gh-issue-162531.Gw3bY8.rst @@ -0,0 +1,2 @@ +Remove obsolete references to ``.pyo`` files from the build, install and +clean scripts. Python has not created ``.pyo`` files since 3.5 (:pep:`488`). diff --git a/PCbuild/rmpyc.py b/PCbuild/rmpyc.py index 0b58f687729f7e..410b01220f6e0b 100644 --- a/PCbuild/rmpyc.py +++ b/PCbuild/rmpyc.py @@ -8,8 +8,7 @@ def deltree(root): npyc = 0 for root, dirs, files in os.walk(root): for name in files: - # to be thorough - if name.endswith(('.pyc', '.pyo')): + if name.endswith('.pyc'): npyc += 1 os.remove(join(root, name)) diff --git a/Tools/buildbot/clean.bat b/Tools/buildbot/clean.bat index fe252a916b1c24..02368a779a2122 100644 --- a/Tools/buildbot/clean.bat +++ b/Tools/buildbot/clean.bat @@ -9,8 +9,8 @@ echo Deleting build call "%pcbuild%\build.bat" -t Clean -k %* call "%pcbuild%\build.bat" -t Clean -k -d %* -echo Deleting .pyc/.pyo files ... -del /s "%root%\Lib\*.pyc" "%root%\Lib\*.pyo" +echo Deleting .pyc files ... +del /s "%root%\Lib\*.pyc" echo Deleting test leftovers ... rmdir /s /q "%root%\build"