This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients docs@python, eryksun
Date 2021-11-07.13:48:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1636292929.46.0.399386691948.issue45742@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2021-11-07 13:48:49eryksunsetrecipients: + eryksun, docs@python
2021-11-07 13:48:49eryksunsetmessageid: <1636292929.46.0.399386691948.issue45742@roundup.psfhosted.org>
2021-11-07 13:48:49eryksunlinkissue45742 messages
2021-11-07 13:48:49eryksuncreate