bpo-32554: Deprecate hashing arbitrary types in random.seed()#15382
Conversation
serhiy-storchaka
left a comment
There was a problem hiding this comment.
I am just interesting, why implement a warning in random.Random.seed() instead of _random.Random.seed()?
|
|
||
| .. deprecated:: 3.9 | ||
| In the future, the *seed* must be one of the following types: | ||
| :class:`NoneType`, :class:`int`, :class:`float`, :class:`str`, |
There was a problem hiding this comment.
There is no an entry for NoneType, so the link will not work.
There was a problem hiding this comment.
Is float because of seed(time.time())?
| 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, ' |
There was a problem hiding this comment.
I would break a string literal and a line after \n for readability
| 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'. |
There was a problem hiding this comment.
| :class:`float`, :class:`str`, :class:`bytes`, and :class:`bytearray'. | |
| :class:`float`, :class:`str`, :class:`bytes`, and :class:`bytearray`. |
|
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 |
|
It is unrelated. |
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`.
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`.
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`.
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`.
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`.
https://bugs.python.org/issue32554