Message402495
I landed here after investigating this surprising result:
# test_case.py
from random import Random
from typing import Sequence, Union
_RandSeed = Union[None, int, Sequence[int]]
class MyRandom(Random):
def __init__(
self,
seed: _RandSeed = None,
):
if seed is not None and not isinstance(seed, int):
seed = sum(seed)
super().__init__(seed)
MyRandom([1, 2])
Output:
python ./test_case.py
Traceback (most recent call last):
File "/…/./test_case.py", line 16, in
<module>
MyRandom([1, 2])
TypeError: unhashable type: 'list'
In my observation, the Random class aspires to be an interface (and default implementation), but doesn't really live up to those aspirations. (See also https://github.com/python/typeshed/issues/6063.) I suspect nudging Random closer to its claims was the point of this proposal. I'm kind of sad it (or something like it) was rejected in favor of a process that will probably take years. Is there a reason not to do both, meaning heal what lives in the standard library now to live up to its own marketing *and* work toward a better interface in the future? |
|
Date |
User |
Action |
Args |
2021-09-23 14:09:31 | posita | set | recipients:
+ posita, tim.peters, rhettinger, mark.dickinson, pitrou, vstinner, serhiy.storchaka |
2021-09-23 14:09:31 | posita | set | messageid: <1632406171.9.0.578525802857.issue40346@roundup.psfhosted.org> |
2021-09-23 14:09:31 | posita | link | issue40346 messages |
2021-09-23 14:09:31 | posita | create | |
|