Message402495
| Author |
posita |
| Recipients |
mark.dickinson, pitrou, posita, rhettinger, serhiy.storchaka, tim.peters, vstinner |
| Date |
2021年09月23日.14:09:31 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1632406171.9.0.578525802857.issue40346@roundup.psfhosted.org> |
| In-reply-to |
| Content |
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? |
|