-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
False negatives with dict.__(r)or__
#10678
Comments
In actual fact, the issue is our stubs for Lines 1122 to 1129 in aa39b99
We currently claim that Ideally we'd make this change, but I think we tried it recently, and it caused an unfortunate number of false positives: diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi
index 71cccee16..cf4f857c5 100644
--- a/stdlib/builtins.pyi
+++ b/stdlib/builtins.pyi
@@ -1120,13 +1120,13 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
if sys.version_info >= (3, 9):
def __class_getitem__(cls, __item: Any) -> GenericAlias: ...
@overload
- def __or__(self, __value: Mapping[_KT, _VT]) -> dict[_KT, _VT]: ...
+ def __or__(self, __value: dict[_KT, _VT]) -> dict[_KT, _VT]: ...
@overload
- def __or__(self, __value: Mapping[_T1, _T2]) -> dict[_KT | _T1, _VT | _T2]: ...
+ def __or__(self, __value: dict[_T1, _T2]) -> dict[_KT | _T1, _VT | _T2]: ...
@overload
- def __ror__(self, __value: Mapping[_KT, _VT]) -> dict[_KT, _VT]: ...
+ def __ror__(self, __value: dict[_KT, _VT]) -> dict[_KT, _VT]: ...
@overload
- def __ror__(self, __value: Mapping[_T1, _T2]) -> dict[_KT | _T1, _VT | _T2]: ...
+ def __ror__(self, __value: dict[_T1, _T2]) -> dict[_KT | _T1, _VT | _T2]: ...
# dict.__ior__ should be kept roughly in line with MutableMapping.update()
@overload # type: ignore[misc]
def __ior__(self, __value: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ... |
Okay, making the type hints more accurate here is actually less disruptive than I thought it would be! See #10679 (comment) |
Thank you for picking this up so quickly. |
I have code equivalent to the following:
mypy
does not error.My environment has:
mypy==1.5.1
types-requests==2.31.0.2
At runtime I get:
I would expect an
[operator]
error. For example, if I swap theCaseInsensitiveDict()
for1
, I get:I am happy to contribute, but I'm not sure what change is needed. I imagine a change is needed in https://github.com/python/typeshed/blob/main/stubs/requests/requests/structures.pyi.
The text was updated successfully, but these errors were encountered: