Message405903
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. |
|
Date |
User |
Action |
Args |
2021-11-07 13:48:49 | eryksun | set | recipients:
+ eryksun, docs@python |
2021-11-07 13:48:49 | eryksun | set | messageid: <1636292929.46.0.399386691948.issue45742@roundup.psfhosted.org> |
2021-11-07 13:48:49 | eryksun | link | issue45742 messages |
2021-11-07 13:48:49 | eryksun | create | |
|