Skip to content

bpo-32554: Deprecate hashing arbitrary types in random.seed()#15382

Merged
rhettinger merged 3 commits into
python:masterfrom
rhettinger:deterministic_seed
Aug 22, 2019
Merged

bpo-32554: Deprecate hashing arbitrary types in random.seed()#15382
rhettinger merged 3 commits into
python:masterfrom
rhettinger:deterministic_seed

Conversation

@rhettinger
Copy link
Copy Markdown
Contributor

@rhettinger rhettinger commented Aug 22, 2019

Copy link
Copy Markdown
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am just interesting, why implement a warning in random.Random.seed() instead of _random.Random.seed()?

Comment thread Doc/library/random.rst Outdated

.. deprecated:: 3.9
In the future, the *seed* must be one of the following types:
:class:`NoneType`, :class:`int`, :class:`float`, :class:`str`,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no an entry for NoneType, so the link will not work.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is float because of seed(time.time())?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Comment thread Lib/random.py Outdated
elif not isinstance(a, (type(None), int, float, str, bytes, bytearray)):
_warn('Seeding based on hashing is deprecated\n'
'since Python 3.9 and will be removed in a subsequent '
'version. The only \nsupported seed types are: None, '
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would break a string literal and a line after \n for readability

Comment thread Doc/whatsnew/3.9.rst Outdated
possible seed value. Unfortunately, some of those types are not
guaranteed to have a deterministic hash value. After Python 3.9,
the module will restrict its seeds to *None*, :class:`int`,
:class:`float`, :class:`str`, :class:`bytes`, and :class:`bytearray'.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:class:`float`, :class:`str`, :class:`bytes`, and :class:`bytearray'.
:class:`float`, :class:`str`, :class:`bytes`, and :class:`bytearray`.

@rhettinger rhettinger merged commit d0cdeaa into python:master Aug 22, 2019
@rhettinger rhettinger deleted the deterministic_seed branch August 22, 2019 16:19
lisroach pushed a commit to lisroach/cpython that referenced this pull request Sep 10, 2019
DinoV pushed a commit to DinoV/cpython that referenced this pull request Jan 14, 2020
websurfer5 pushed a commit to websurfer5/cpython that referenced this pull request Jul 20, 2020
@Kodiologist
Copy link
Copy Markdown
Contributor

Excuse my density and lateness, but why was this feature deprecated and removed instead of being fixed? Couldn't you use a non-random hash? The Python standard library already provides a wide variety of hashes in hashlib.

@serhiy-storchaka
Copy link
Copy Markdown
Member

It is unrelated. hashlib does not allow you to make a hash from arbitrary object.

ngnpope added a commit to ngnpope/mimesis that referenced this pull request Nov 26, 2021
Makes the following changes:

- Added `float` to the `Union` for `Seed`.
- Added `None` to the `Union` for `Seed`.
- Replaced `Optional[Seed]` with `Seed` everywhere.

See the following links for details:

- https://bugs.python.org/issue32554
- python/cpython#15382
- https://docs.python.org/3.9/library/random.html#random.seed

Currently `typeshed` is still using `Any`.
ngnpope added a commit to ngnpope/mimesis that referenced this pull request Nov 26, 2021
Makes the following changes:

- Added `float` to the `Union` for `Seed`.
- Added `None` to the `Union` for `Seed`.
- Replaced `Optional[Seed]` with `Seed` everywhere.

See the following links for details:

- https://bugs.python.org/issue32554
- python/cpython#15382
- https://docs.python.org/3.9/library/random.html#random.seed

Currently `typeshed` is still using `Any`.
ngnpope added a commit to ngnpope/mimesis that referenced this pull request Nov 27, 2021
Makes the following changes:

- Added `float` to the `Union` for `Seed`.
- Added `None` to the `Union` for `Seed`.
- Replaced `Optional[Seed]` with `Seed` everywhere.

See the following links for details:

- https://bugs.python.org/issue32554
- python/cpython#15382
- https://docs.python.org/3.9/library/random.html#random.seed

Currently `typeshed` is still using `Any`.
ngnpope added a commit to ngnpope/mimesis that referenced this pull request Nov 30, 2021
Makes the following changes:

- Added `float` to the `Union` for `Seed`.
- Added `None` to the `Union` for `Seed`.
- Replaced `Optional[Seed]` with `Seed` everywhere.

See the following links for details:

- https://bugs.python.org/issue32554
- python/cpython#15382
- https://docs.python.org/3.9/library/random.html#random.seed

Currently `typeshed` is still using `Any`.
lk-geimfari pushed a commit to lk-geimfari/mimesis that referenced this pull request Nov 30, 2021
Makes the following changes:

- Added `float` to the `Union` for `Seed`.
- Added `None` to the `Union` for `Seed`.
- Replaced `Optional[Seed]` with `Seed` everywhere.

See the following links for details:

- https://bugs.python.org/issue32554
- python/cpython#15382
- https://docs.python.org/3.9/library/random.html#random.seed

Currently `typeshed` is still using `Any`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants