Closed as not planned
Description
Hi. I would like to propose that a dictionary accepts a mapping to the or operation. Something like:
class dict(MutableMapping[_KT, _VT]):
...
@overload
def __or__(self, __value: Mapping[_KT, _VT]) -> dict[_KT, _VT]: ...
@overload
def __or__(self, __value: Mapping[_T1, _T2]) -> dict[_KT | _T1, _VT | _T2]: ...
It would be useful in scenarios like the following:
from collections.abc import Mapping
from typing import cast
a = cast(Mapping[str, int], {"a": 1})
{"b": 2} | a
At this point, pyright complains with # error: Operator "|" not supported for types "dict[str, int]" and "Mapping[str, int]"
.
I referenced this problem in this issue. Thanks.
Metadata
Metadata
Assignees
Labels
No labels