Eryk Sun <[email protected]> added the comment:
Apparently -R is still implemented in Python 3, even though hash randomization
is enabled by default now. Unlike Python 2, in Python 3 -R overrides the
PYTHONHASHSEED environment variable, making it effectively the same as
"PYTHONHASHSEED=random". For example:
Python 2.7.18
$ PYTHONHASHSEED=37 python2
>>> import sys; sys.flags.hash_randomization
37
>>> hash('spam')
-3063226141675644153
$ PYTHONHASHSEED=37 python2 -R
>>> import sys; sys.flags.hash_randomization
37
>>> hash('spam')
-3063226141675644153
Python 3.11
$ PYTHONHASHSEED=37 python3 -q
>>> import sys; sys.flags.hash_randomization
1
>>> hash('spam')
7085596773562191897
$ PYTHONHASHSEED=37 python3 -q
>>> hash('spam')
7085596773562191897
$ PYTHONHASHSEED=37 python3 -qR
>>> import sys; sys.flags.hash_randomization
1
>>> hash('spam')
-6544739063919843911
$ PYTHONHASHSEED=37 python3 -qR
>>> hash('spam')
5363435507110042548
Python 3 no longer reports the seed value in sys.flags.hash_randomization, so I
repeated the 3.11 examples twice to show that PYTHONHASHSEED works, except when
-R overrides it.
----------
nosy: +eryksun -180909
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue45742>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com