Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2k
add overload to tuple.__new__ to better express an empty tuple#7454
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
xavdid commented Mar 7, 2022
Ah, looks like CI is unhappy:
I see that most |
This comment has been minimized.
This comment has been minimized.
Uh oh!
There was an error while loading. Please reload this page.
This comment has been minimized.
This comment has been minimized.
srittau commented Mar 8, 2022
It's unclear to me way mypy primer explodes, but I think it's related to |
xavdid commented Mar 8, 2022
Sure thing! added in d556d17; hope that comment is descriptive enough- I don't quite follow the issue. |
This comment has been minimized.
This comment has been minimized.
xavdid commented Mar 8, 2022
Ah, I think I'm following now. Using
|
srittau commented Mar 8, 2022
I'm not totally sure what's going on here myself. primer output looks much better, although it's weird that the remaining problems are in mypy itself. Maybe a mypy developer could look over this? Cc @JukkaL@hauntsaninja |
hauntsaninja commented Mar 8, 2022 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
I'm not sure either, will look into it soon. I think the first error on |
xavdid commented Mar 8, 2022
Thanks for taking a look! Let me know if there's anything else I can do to be helpful. |
This will be broken by python/typeshed#7454
hauntsaninja commented Mar 9, 2022 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Here, python/mypy#12319 will fix the errors from the plugin. I unfortunately don't have a fix for the errors from I also filed python/mypy#12320 since it looks like a similar issue could crop up in other parts of mypy's codebase. |
This will be broken by python/typeshed#7454 Co-authored-by: hauntsaninja <>
JelleZijlstra commented Mar 9, 2022
I'm not sure this change is worth it if we lose correct typing for subclasses of |
AlexWaygood commented Mar 9, 2022
Empty tuples and tuple subclasses are both reasonably common, but I can't say I've ever seen an example of an empty tuple subclass instance. And for non-empty tuple subclass instances, we'll still have correct type inference, as that overload still returns |
AlexWaygood commented Apr 3, 2022 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Seems like this change might also fix |
Diff from mypy_primer, showing the effect of this PR on open source code: mypy (https://github.com/python/mypy) + mypy/config_parser.py:182: error: Argument 1 to "map" has incompatible type overloaded function; expected "Callable[[str], AnyStr]" [arg-type] |
AlexWaygood commented Jul 2, 2022
For both # test.pyclassX(tuple): ... reveal_type(X()) # Revealed type is "test.X"So this doesn't seem to cause any regressions in that regard. |
This PR adds an overload to the
tuple()constructor to specify that an empty tuple is returned, notTuple[Any]. It covers the following code snippet (using the Pylance type checker):The docs specify that:
This is my first typeshed PR, so please feel free to correct any mistakes I've made!
For more context, see: microsoft/pylance-release#2445 (comment)