-
- Notifications
You must be signed in to change notification settings - Fork 3k
Allow returning Literals in __new__ #15687
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
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 |
This comment has been minimized.
This comment has been minimized.
Bumping because python/typeshed#6069 and python/typeshed#10465 depend on this. |
This comment has been minimized.
This comment has been minimized.
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Thank you @ilevkivskyi for helping with this much appreciated! |
Unblocks python/typeshed#10465