The .pyc file includes a hash of the source file content, which Python will compare against the source at runtime to determine if the .pyc file needs to be regenerated.
py_compile/PycInvalidationMode.CHECKED_HASH
PycInvalidationMode.CHECKED_HASH