-
-
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
Allow returning Literals in __new__ #15687
base: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
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 tests to this change :)
This comment has been minimized.
This comment has been minimized.
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, also add an @overload
case you are proposing to typeshed
This comment has been minimized.
This comment has been minimized.
This reverts commit 79cb39e.
This comment has been minimized.
This comment has been minimized.
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.
Let's ask for an extra pair of eyes.
@ilevkivskyi would you, please? :)
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.
Looks good, added a suggestion to improve the tests.
This comment has been minimized.
This comment has been minimized.
Somehow |
@Gobot1234 Yes, I think you likely need to add Lines 195 to 207 in cfd01d9
|
Thank you, never would have spotted that! Everything should work now |
This comment has been minimized.
This comment has been minimized.
FWIW you are doing something weird with the fixtures. Try placing your updated definitions of |
Like this? [case testOverride__new__WithLiteralReturnPassing]
from typing import Literal
class Falsy:
def __bool__(self) -> Literal[False]: pass
reveal_type(bool(Falsy())) # N: Revealed type is "Literal[False]"
reveal_type(int()) # N: Revealed type is "Literal[0]"
[file builtins.py]
from typing import Literal, Protocol, overload
class str: pass
class dict: pass
class float: pass
class int:
def __new__(cls) -> Literal[0]: pass
class _Truthy(Protocol):
def __bool__(self) -> Literal[True]: pass
class _Falsy(Protocol):
def __bool__(self) -> Literal[False]: pass
class bool(int):
@overload
def __new__(cls, __o: _Truthy) -> Literal[True]: pass
@overload
def __new__(cls, __o: _Falsy) -> Literal[False]: pass
def __new__(cls, __o: object):
pass
[typing fixtures/typing-medium.pyi] It doesn't seem to work |
No, move all that stuff from |
Doing so doesn't seem to have changed anything, sorry if I'm misunderstanding |
Hm, to debug this, try adding |
bool is Any |
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Unblocks python/typeshed#10465