-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
tuple slice should not propagate fallback #16154
Conversation
for more information, see https://pre-commit.ci
I want to add #8776 (comment) as a test case, but I'm not sure where |
@@ -2416,13 +2416,14 @@ def copy_modified( | |||
items = self.items | |||
return TupleType(items, fallback, self.line, self.column) | |||
|
|||
def slice(self, begin: int | None, end: int | None, stride: int | None) -> TupleType: | |||
def slice( | |||
self, begin: int | None, end: int | None, stride: int | None, *, fallback: Instance | None |
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.
fallback should always be named_type("builtins.tuple")
but I'm not sure how to make one without access to a TypeChecker
instance
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.
Thanks, merge conflicts aside, this looks good to me. test-data/unit/check-tuples.test
is probably a good place for the test you suggest.
@hauntsaninja ok conflicts resolved |
This comment has been minimized.
This comment has been minimized.
Tests are failing, let me know if you could use assistance on getting your nice #8776 (comment) example in a test |
This comment has been minimized.
This comment has been minimized.
@hauntsaninja ok I added that test |
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
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.
Thank you!
Fixes #8776
NamedTuple (or any other tuple subtype) slicing should not propagate the fallback