-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
bool |= bool
complains about incompatible assignment type
#4386
Comments
This patch to typeshed makes the above pass: $ git diff stdlib/3
diff --git a/stdlib/3/builtins.pyi b/stdlib/3/builtins.pyi
index f2cea0f..74eb806 100644
--- a/stdlib/3/builtins.pyi
+++ b/stdlib/3/builtins.pyi
@@ -537,6 +537,30 @@ class memoryview(Sized, Container[bytes]):
class bool(int):
def __init__(self, o: object = ...) -> None: ...
+ @overload # type: ignore
+ def __and__(self, x: bool) -> bool: ...
+ @overload # type: ignore
+ def __and__(self, x: int) -> int: ...
+ @overload # type: ignore
+ def __or__(self, x: bool) -> bool: ...
+ @overload # type: ignore
+ def __or__(self, x: int) -> int: ...
+ @overload # type: ignore
+ def __xor__(self, x: bool) -> bool: ...
+ @overload # type: ignore
+ def __xor__(self, x: int) -> int: ...
+ @overload # type: ignore
+ def __rand__(self, x: bool) -> bool: ...
+ @overload # type: ignore
+ def __rand__(self, x: int) -> int: ...
+ @overload # type: ignore
+ def __ror__(self, x: bool) -> bool: ...
+ @overload # type: ignore
+ def __ror__(self, x: int) -> int: ...
+ @overload # type: ignore
+ def __rxor__(self, x: bool) -> bool: ...
+ @overload # type: ignore
+ def __rxor__(self, x: int) -> int: ...
class slice:
start = ... # type: Optional[int] though I'm concerned about the If this seems OK, I'll turn it into a PR :) |
This is an interesting case indeed. I believe the fix should probably happen in typeshed, so please open an issue there. Thanks! |
Thanks, opened python/typeshed#1793! |
After looking at this carefully, it seems to me that the |
IIRC we looked at that before and it seemed complicated; maybe you can find an older issue for the overload on e.g. |
Ah, this was already discussed in #1684, and closed in favor of python/typeshed#649, but I didn't see anything discussing the specific issue of needing the |
I couldn't find any definitive specification on this other than PEP 285
Here's the input program (which I expect to cause no linting errors)
However it results in the following:
It seems that PEP 285 is implemented faithfully in the versions of python I was able to check:
The text was updated successfully, but these errors were encountered: