New submission from STINNER Victor <[email protected]>:
Python pretends that hash randomization is always enabled, but it's not:
$ PYTHONHASHSEED=0 python3 -c 'import sys; print(sys.flags.hash_randomization)'
1
vstinner@apu$ PYTHONHASHSEED=0 python3 -c 'import sys; print(hash("abc"))'
4596069200710135518
vstinner@apu$ PYTHONHASHSEED=0 python3 -c 'import sys; print(hash("abc"))'
4596069200710135518
vstinner@apu$ PYTHONHASHSEED=0 python3 -c 'import sys; print(hash("abc"))'
4596069200710135518
=> sys.flags.hash_randomization must be zero
Moreover, the -R flag is always ignored, it's not possible to override the
PYTHONHASHSEED environment variable:
vstinner@apu$ PYTHONHASHSEED=0 python3 -R -c 'import sys;
print(sys.flags.hash_randomization)'
1
vstinner@apu$ PYTHONHASHSEED=0 python3 -R -c 'import sys; print(hash("abc"))'
4596069200710135518
vstinner@apu$ PYTHONHASHSEED=0 python3 -R -c 'import sys; print(hash("abc"))'
4596069200710135518
vstinner@apu$ PYTHONHASHSEED=0 python3 -R -c 'import sys; print(hash("abc"))'
4596069200710135518
I expect that -R enables hash randomization and overrides PYTHONHASHSEED
environment variable.
Attached PR fixes these issues and adds an unit test.
----------
messages: 308343
nosy: vstinner
priority: normal
severity: normal
status: open
title: PYTHONHASHSEED=0 python3 -R should enable hash randomization
versions: Python 3.7
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue32329>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com