Conversation
Mypy already accepts a name of type Any as a base class, but treated args[1] as a generic type application, so *args entries typed as Any were rejected. Index into a known tuple type in base-class position and reuse the existing Any/type/Type[Any] rule without relaxing non-Any bases.
Contributor
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
|
Can you check this additional test case I generated by modifying one of yours to add nesting (added alongside the ones you added) passes as it should? (I don't think that it does in your current version) pyright 1.1.414 says that the following associated standalone snippet is fine and outputs the expected type for the nested unpack (and pyrefly 1.3.1 also agrees it typechecks): Thanks |
Flatten Unpack[Tuple[...]] before reading a literal index so *tuple[int, *tuple[Any]] is treated like tuple[int, Any].
Author
|
The nested case failed because unpack-in-tuple short-circuited indexing. Nested |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #21998
class C(args[1])failed even when that slot isAny. Names of typeAnyalready work as dynamic bases; tuple indexes didn't. I allowAny/type/Type[Any]indexes and still reject everything else.x = args[1]; class C(x)still needs an annotation — bases are resolved before inference.Tested with the new cases in
check-classes.test(pytest mypy/test/testcheck.py).