When does Python rebuild a .pyc? Timestamp vs hash-based invalidation
By default CPython trusts a .pyc if the source's mtime and size match. When that misses edits, how checked-hash and unchecked-hash pycs differ, and how to use compileall (Python 3.14.8 docs).
DevelopmentPythonCPythonBytecode