Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0209dc1

Browse files
committed
Clarify that hash randomization is on by default
1 parent a562ed0 commit 0209dc1

1 file changed

Lines changed: 16 additions & 17 deletions

File tree

Doc/using/cmdline.rst

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -229,23 +229,22 @@ Miscellaneous options
229229

230230
.. cmdoption:: -R
231231

232-
Turn on hash randomization, so that the :meth:`__hash__` values of str, bytes
233-
and datetime objects are "salted" with an unpredictable random value.
234-
Although they remain constant within an individual Python process, they are
235-
not predictable between repeated invocations of Python.
236-
237-
This is intended to provide protection against a denial-of-service caused by
238-
carefully-chosen inputs that exploit the worst case performance of a dict
239-
construction, O(n^2) complexity. See
232+
Kept for compatibility. On Python 3.3 and greater, hash randomization is
233+
turned on by default.
234+
235+
On previous versions of Python, this option turns on hash randomization,
236+
so that the :meth:`__hash__` values of str, bytes and datetime
237+
are "salted" with an unpredictable random value. Although they remain
238+
constant within an individual Python process, they are not predictable
239+
between repeated invocations of Python.
240+
241+
Hash randomization is intended to provide protection against a
242+
denial-of-service caused by carefully-chosen inputs that exploit the worst
243+
case performance of a dict construction, O(n^2) complexity. See
240244
http://www.ocert.org/advisories/ocert-2011-003.html for details.
241245

242-
Changing hash values affects the order in which keys are retrieved from a
243-
dict. Although Python has never made guarantees about this ordering (and it
244-
typically varies between 32-bit and 64-bit builds), enough real-world code
245-
implicitly relies on this non-guaranteed behavior that the randomization is
246-
disabled by default.
247-
248-
See also :envvar:`PYTHONHASHSEED`.
246+
:envvar:`PYTHONHASHSEED` allows you to set a fixed value for the hash
247+
seed secret.
249248

250249
.. versionadded:: 3.2.3
251250

@@ -486,8 +485,8 @@ These environment variables influence Python's behavior.
486485

487486
.. envvar:: PYTHONHASHSEED
488487

489-
If this variable is set to ``random``, a random value is used to seed the
490-
hashes of str, bytes and datetime objects.
488+
If this variable is not set or set to ``random``, a random value is used
489+
to seed the hashes of str, bytes and datetime objects.
491490

492491
If :envvar:`PYTHONHASHSEED` is set to an integer value, it is used as a fixed
493492
seed for generating the hash() of the types covered by the hash

0 commit comments

Comments
 (0)