Uh oh!
There was an error while loading. Please reload this page.
remove dict.__or__ overloads - #14284
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
srittau
commented
Dec 9, 2025
For reference, the overloads were added in #10427 due to @AlexWaygood's comment. Are those concerns not valid anymore? (At first glace at |
randolf-scholz
commented
Dec 9, 2025
These overloads shouldn't be necessary at all, and they lead to type checker divergence, but there is a very old bug in |
srittau
commented
Dec 9, 2025
Considering the passing tests and the positive primer output, I'd be willing to accept this change, whether the mypy bug is fixed or not. But I'd like to hear Alex's opinion, since he brought the issue up in the original PR. |
That's probably more so because We even get some very bad cases like |
srittau
commented
Dec 9, 2025
Then new code will have to use |
AlexWaygood
commented
Dec 9, 2025
I'm a bit ill right now but happy to take a look later this week (please ping me again if I forget) |
srittau
commented
Dec 15, 2025
@AlexWaygood Friendly ping. |
Diff from mypy_primer, showing the effect of this PR on open source code: rotki (https://github.com/rotki/rotki)
+ rotkehlchen/chain/evm/decoding/aave/v3/decoder.py:520: error: Unused "type: ignore" comment [unused-ignore]
artigraph (https://github.com/artigraph/artigraph)
- tests/arti/internal/test_mappings.py:40: error: No overload variant of "__or__" of "dict" matches argument type "frozendict[Never, int]" [operator]+ tests/arti/internal/test_mappings.py:40: error: Unsupported operand types for | ("dict[str, int]" and "frozendict[Never, int]") [operator]- tests/arti/internal/test_mappings.py:40: note: Possible overload variants:- tests/arti/internal/test_mappings.py:40: note: def __or__(self, dict[str, int], /) -> dict[str, int]- tests/arti/internal/test_mappings.py:40: note: def [_T1, _T2] __or__(self, dict[_T1, _T2], /) -> dict[str | _T1, int | _T2] |
AlexWaygood
left a comment
There was a problem hiding this comment.
LGTM. I think these overloads were only added in #10427 for "consistency" with collections.OrderedDict.__or__, collections.defaultdict.__or__, and similar. But unlike those classes, dict.__or__ always returns a dict, not Self, so the same concerns don't apply here:
>>> classFoo(dict): ...
... >>> type(Foo({}) | {})
<class 'dict'>and I agree that the divergences between type checkers here are unfortunate.
Happy to land this if you take it out of draft! (Which I can do myself, but I don't want to do that to your PR if you're still uncertain about it :-) |
randolf-scholz
commented
Mar 8, 2026
@AlexWaygood Done. What about the sister PR #14282 ? I did a rebase and let's see if the primer has changed, bit I am afraid this equivalent change for |
AlexWaygood
commented
Mar 8, 2026
I agree that in theory the overloads there should also be redundant, but if the mypy_primer hit is as bad as it was last time then that might be prohibitive, unfortunately :/ |
Uh oh!
There was an error while loading. Please reload this page.
randolf-scholz
commented
Mar 8, 2026
Yes it is. The thing is mypy has this very old bug classVec[T]:
defget(self) ->T: ...
defset(self, index: int, value: T) ->None: ...
def__add__[S](self, other: "Vec[S]", /) ->"Vec[T | S]": returnVec()
defpprint(arg: Vec[object]) ->None: ...
defdemo(ints: Vec[int], strs: Vec[str]):
pprint(ints+strs) # ❌️ mypy false positiveand I am not seeing it get solved any time soon. I tried to get my hands dirty as well, but it is messy and arduous. (randolf-scholz/mypy#4) |
AlexWaygood
commented
Mar 8, 2026
yeah, bidirectional inference is hard... |
AlexWaygood
commented
Mar 8, 2026
Also, sorry again for letting this slip for so long. I was pretty ill over a lot of December and then lost track of it after the Christmas period :-( |
randolf-scholz
commented
Mar 8, 2026
No worries. Btw did you see #15297 (comment) ? |
Identifies two typeshed PRs responsible for 139 new ecosystem diagnostics: - python/typeshed#14284 (dict.__or__ overload removal): ~150 diagnostics - python/typeshed#15470 (set/frozenset canonicalization): ~3 diagnostics https://claude.ai/code/session_016z9Bez4viqJyDJAeZMQbWo
This reverts commit bfb7342.
See #14283. Sibling PR for #14282.