-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
Make None
compatible with SupportsBool
protocol
#15889
base: master
Are you sure you want to change the base?
Changes from 3 commits
bc684ea
ef1f9cc
a76db8c
8d8aa0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2857,7 +2857,7 @@ c1: SupportsClassGetItem = C() | |
|
||
[case testNoneVsProtocol] | ||
# mypy: strict-optional | ||
from typing_extensions import Protocol | ||
from typing_extensions import Literal, Protocol | ||
|
||
class MyHashable(Protocol): | ||
def __hash__(self) -> int: ... | ||
|
@@ -2890,6 +2890,22 @@ class SupportsStr(Protocol): | |
def ss(s: SupportsStr) -> None: pass | ||
ss(None) | ||
|
||
class SupportsBool(Protocol): | ||
def __bool__(self) -> bool: ... | ||
|
||
class SupportsBoolLiteralTrue(Protocol): | ||
def __bool__(self) -> Literal[True]: ... | ||
|
||
class SupportsBoolLiteralFalse(Protocol): | ||
def __bool__(self) -> Literal[False]: ... | ||
|
||
def sb(s: SupportsBool) -> None: pass | ||
sb(None) | ||
def sblt(s: SupportsBoolLiteralTrue) -> None: pass | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure that this is correct. https://github.com/python/typeshed/blob/ef758b66c0947a73f6225cac0568f3f068cd61d4/stdlib/types.pyi#L627-L629 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you're right, it's not correct behavior, but tests passed. How I can fix it? Maybe we have other bug? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm implemented check into |
||
sblt(None) | ||
def sblf(s: SupportsBoolLiteralFalse) -> None: pass | ||
sblf(None) | ||
|
||
class HashableStr(Protocol): | ||
def __str__(self) -> str: ... | ||
def __hash__(self) -> int: ... | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, add two more protocols to the test:
def __bool__(self) -> Literal[True]: ...
anddef __bool__(self) -> Literal[False]: ...
Other than that - it looks good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for review! I add tests with
Literal
return types, take a look, please