-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
add overload to tuple.__new__ to better express an empty tuple #7454
Conversation
Ah, looks like CI is unhappy:
I see that most |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
It's unclear to me way mypy primer explodes, but I think it's related to |
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.
Ah, I think I'm following now. Using
|
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 |
I'm not sure either, will look into it soon. I think the first error on |
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
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 <>
I'm not sure this change is worth it if we lose correct typing for subclasses of |
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 |
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]
|
For both # test.py
class X(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)