Skip to content

tuple slice should not propagate fallback#16154

Merged
hauntsaninja merged 6 commits intopython:masterfrom
graingert:tuple-fallback-fix
Oct 1, 2023
Merged

tuple slice should not propagate fallback#16154
hauntsaninja merged 6 commits intopython:masterfrom
graingert:tuple-fallback-fix

Conversation

@graingert
Copy link
Copy Markdown
Contributor

@graingert graingert commented Sep 21, 2023

Fixes #8776

NamedTuple (or any other tuple subtype) slicing should not propagate the fallback

@graingert
Copy link
Copy Markdown
Contributor Author

I want to add #8776 (comment) as a test case, but I'm not sure where

Comment thread mypy/types.py

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
Copy link
Copy Markdown
Contributor Author

@graingert graingert Sep 21, 2023

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

@graingert graingert marked this pull request as ready for review September 21, 2023 13:47
@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Collaborator

@hauntsaninja hauntsaninja left a 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.

@graingert
Copy link
Copy Markdown
Contributor Author

@hauntsaninja ok conflicts resolved

@github-actions

This comment has been minimized.

@hauntsaninja
Copy link
Copy Markdown
Collaborator

Tests are failing, let me know if you could use assistance on getting your nice #8776 (comment) example in a test

Comment thread mypy/types.py Outdated
@github-actions

This comment has been minimized.

@graingert
Copy link
Copy Markdown
Contributor Author

@hauntsaninja ok I added that test

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Oct 1, 2023

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Copy link
Copy Markdown
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@hauntsaninja hauntsaninja merged commit 99ba048 into python:master Oct 1, 2023
@graingert graingert deleted the tuple-fallback-fix branch October 1, 2023 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect Error with NamedTuple slices ?

2 participants