python / python/cpython

compileall doesn't recompile when invalidation mode changes even if timestamps match

Open
#117,204 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

type-bug
Dominant language
Python
Stars
77.2k
Forks
36k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:
λ rm -rf __pycache__                                                                                                                            130 
λ python -m compileall x.py --invalidation-mode timestamp
Compiling 'x.py'...
λ python -m compileall x.py --invalidation-mode timestamp
λ python -m compileall x.py --invalidation-mode checked-hash

λ python
>>> import importlib.util
>>> with open("__pycache__/x.cpython-311.pyc", "rb") as f:
...     d = f.read()
... 
>>> d[:4]
b'\xa7\r\r\n'
>>> d[4:8]
b'\x00\x00\x00\x00'

λ rm -rf __pycache__
λ python -m compileall x.py --invalidation-mode checked-hash
Compiling 'x.py'...

λ python
>>> with open("__pycache__/x.cpython-311.pyc", "rb") as f:
...     d = f.read()
... 
>>> d[:4]
b'\xa7\r\r\n'
>>> d[4:8]
b'\x03\x00\x00\x00'
CPython versions tested on:

3.11

Operating systems tested on:

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior with x.py using python -m compileall and inspect the generated file in pycache. Start at the compileall command entry point and compare repeated timestamp and checked-hash runs. Done means changing the invalidation mode causes recompilation or otherwise updates the pyc header even when timestamps match.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.