[proxy] web.archive.org← back | site home | direct (HTTPS) ↗ | proxy home | ◑ dark◐ light
/ mypy Public
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

Fix joining of Sequence (e.g. variadic tuple) and fixed-length tuple #8335

Merged
merged 1 commit into from Jan 31, 2020

Conversation

Copy link
Contributor

intgr commented Jan 26, 2020

For example:

  • Tuple[int] + Tuple[bool, ...] becomes Tuple[int, ...]
  • List[int] + Tuple[bool, ...] becomes Sequence[int]

This solves the other part of issue #4975 (along with PR #8333) and also issue #8074. Previously Mypy simply punted and returned object.

intgr requested a review from msullivan Jan 29, 2020
Copy link
Collaborator

JukkaL commented Jan 29, 2020

As discussed elsewhere, also testing subclasses of tuple would be a good idea.

intgr removed the request for review from msullivan Jan 29, 2020
intgr force-pushed the join-sequence-and-fixed-tuple branch from 5c552bb to 129cda7 Compare Jan 31, 2020
For example:
* Tuple[int] + Tuple[bool, ...] becomes Tuple[int, ...]
* List[int] + Tuple[bool, ...] becomes Sequence[int]

Previously Mypy simply punted and returned `object`.
intgr force-pushed the join-sequence-and-fixed-tuple branch from 129cda7 to 8bb19cf Compare Jan 31, 2020
Copy link
Contributor Author

intgr commented Jan 31, 2020

I added test testTupleSubclassJoin, does that cover what you had in mind?

JukkaL approved these changes Jan 31, 2020
Copy link
Collaborator

JukkaL left a comment

Thanks, looks good! This is a nice type inference improvement.

Copy link
Contributor

theodoretliu commented Feb 2, 2020

Quick question: why is subclassing "automatically" handled by this PR? This is more just for my curiosity, does the "default fallback" function automatically find the ancestor of the class?

Copy link
Contributor Author

intgr commented Feb 2, 2020

@theodoretliu The tuple_fallback function returns a variadic tuple in place of a fixed-length tuple. But most tuple subclasses only support fixed-length operation, it cannot construct NamedTuple[int, ...] so it has to fall back to builtin.tuple class for tuple subclasses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants