Skip to content

tuple slice should not propagate fallback#16154

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

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

Conversation

@graingert

@graingert graingert commented Sep 21, 2023

Copy link
Copy Markdown
Contributor

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

@graingert graingert Sep 21, 2023

Copy link
Copy Markdown
Contributor Author

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.

@hauntsaninja hauntsaninja left a comment

Copy link
Copy Markdown
Collaborator

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

github-actions Bot commented Oct 1, 2023

Copy link
Copy Markdown
Contributor

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

@hauntsaninja hauntsaninja left a comment

Copy link
Copy Markdown
Collaborator

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