STINNER Victor <vstin...@python.org> added the comment:

I would prefer to mimick importlib._bootstrap_external which uses:

def _pack_uint32(x):
    """Convert a 32-bit integer to little-endian."""
    return (int(x) & 0xFFFFFFFF).to_bytes(4, 'little')

Using 64-bit timestamp (PR 19651), treat timestamp as unsigned (PR 9892 and PR 
19708) have drawback:

* 64-bit timestamp make .pyc files larger
* unsigned timestamp no longer support timestamp before 1969 which can cause 
practical issues

"& 0xFFFFFFFF" looks dead simple, uses a fixed size of 4 bytes and doesn't have 
any limitation of year 2038.

The timestamp doesn't have to be exact. In practice, it sounds very unlikely 
that two timestamps are equal when compared using (ts1 & 0xFFFFFFFF) == (ts2 & 
0xFFFFFFFF). I expect file modification times to be close by a few days, not 
separated by 2**32 seconds (136 years).

Use hash based .pyc to avoid any issuse with file modification time: it should 
make Python more deterministic (more "reproducible").
https://docs.python.org/dev/reference/import.html#pyc-invalidation

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue34990>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to