-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Use normalized tuples for fallback calculation #19111
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
Changes from all commits
9b6f908
3989212
bebdf28
0aaa011
8bb25fa
03a0a5b
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 |
---|---|---|
|
@@ -2666,3 +2666,30 @@ def identity(smth: _FT) -> _FT: | |
class S(tuple[Unpack[Ts]], Generic[T, Unpack[Ts]]): | ||
def f(self, x: T, /) -> T: ... | ||
[builtins fixtures/tuple.pyi] | ||
|
||
[case testNoCrashSubclassingTupleWithTrivialUnpack] | ||
# https://github.com/python/mypy/issues/19105 | ||
from typing import Unpack | ||
|
||
class A(tuple[Unpack[tuple[int]]]): ... | ||
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. Could you please also add a test for class C(tuple[Unpack[tuple[int, ...]]]): ... (unless there is already such test case)? I am not sure we properly handle such types. Also maybe test not just class creation, but some tuple ops as well, such as e.g. unpacking etc. 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. Surprisingly we don't have such a test too, but it was already working before my patch - a: A
tuple(a) and also get a terrible diagnostic on b: B
_, = b # E: Variadic tuple unpacking requires a star target despite B clearly not being variadic. I'll move this to draft for now, there's little benefit from merging a crash fix that causes a next one immediately... |
||
class B(tuple[Unpack[tuple[()]]]): ... | ||
|
||
a: A | ||
reveal_type(tuple(a)) # N: Revealed type is "builtins.tuple[builtins.int, ...]" | ||
(x,) = a | ||
|
||
b: B | ||
(_,) = b # E: Need more than 0 values to unpack (1 expected) | ||
[builtins fixtures/tuple.pyi] | ||
|
||
[case testNoCrashSubclassingTupleWithVariadicUnpack] | ||
# https://github.com/python/mypy/issues/19105 | ||
from typing import Unpack | ||
|
||
class A(tuple[Unpack[tuple[int, ...]]]): ... | ||
|
||
a: A | ||
tuple(a) | ||
(x,) = a | ||
(_,) = a | ||
[builtins fixtures/tuple.pyi] |
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.
This looks like a duplicate work, did you try deleting the accept just above? (if you delete it, don't forget to update the comment)
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.
That breaks one test:
Removing this line makes both errors on alias instantiation disappear. That's quite expected since
get_proper_type
calls_expand_once
, so it is not equivalent to simply accepting the target alias - we do not want to ignore args here. We can limit that to only accepting if args are non-empty, but I don't think this can result in any significant speedup.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.
OK, this is kind of unfortunate. We already accept args in isolation at the very start (see super call), then we accept expansion, and finally the target in isolation. But I guess this is the price to pay for having both: