Matt Bogosian <[email protected]> added the comment:
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?
----------
nosy: +posita
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue40346>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com