Skip to content

Fix joining of fixed-length tuples with mismatching lengths #8333

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

Merged
merged 1 commit into from
Feb 3, 2020

Conversation

intgr
Copy link
Contributor

@intgr intgr commented Jan 26, 2020

For example: Tuple[bool, int] + Tuple[bool] becomes Tuple[int, ...]

Previously Mypy simply punted and returned object.

This solves part of #4975. The other missing handling of fixed tuple + variadic tuple will be implemented separately, if this PR goes well. :)

@intgr intgr force-pushed the join-mismatching-length-fixed-tuples branch 2 times, most recently from e4900ba to 0bc852b Compare January 26, 2020 13:58
@intgr intgr changed the title Fix joining of fixed tuples with mismatching lengths Fix joining of fixed-length tuples with mismatching lengths Jan 26, 2020
@intgr intgr force-pushed the join-mismatching-length-fixed-tuples branch from 0bc852b to c7b9a46 Compare January 26, 2020 15:19
@intgr intgr requested a review from msullivan January 29, 2020 10:56
@JukkaL
Copy link
Collaborator

JukkaL commented Jan 29, 2020

Thanks! Looks good. Maybe also add simple data-driven test (in test-data/unit/check-tuples.test), just in case?

@intgr intgr removed the request for review from msullivan January 29, 2020 23:45
@intgr intgr force-pushed the join-mismatching-length-fixed-tuples branch 2 times, most recently from e5c1e86 to 5263a51 Compare January 31, 2020 01:37
@intgr
Copy link
Contributor Author

intgr commented Jan 31, 2020

I discovered some awkward behavior when attempting to create a sub-subclass of NamedTuple. Seems that NamedTuple never supported this, but doesn't raise an error either :)

from typing import Tuple, NamedTuple

class NTup1(NamedTuple):
    a: bool
class NTup2(NTup1):
    b: bool

tup1 = None  # type: NTup1
tup2 = None  # type: NTup2

tup1 = tup2  # This should be an error, a 2-tuple type is not compatible with 1-tuple

def bla(x: NTup1): ...
bla(tup2)  # This should be an error, a 2-tuple type is not compatible with 1-tuple

@intgr
Copy link
Contributor Author

intgr commented Jan 31, 2020

Pushed additional tests. Is this what you had in mind?

@intgr intgr force-pushed the join-mismatching-length-fixed-tuples branch from 5263a51 to ffded6b Compare February 2, 2020 01:46
@intgr
Copy link
Contributor Author

intgr commented Feb 2, 2020

Rebased after conflicts from merging #8335.

@intgr intgr force-pushed the join-mismatching-length-fixed-tuples branch 2 times, most recently from e1e1333 to ed011c3 Compare February 2, 2020 09:03
For example:
Tuple[bool, int] + Tuple[bool] becomes Tuple[int, ...]

Previously Mypy simply punted and returned `object`.

The handling of fixed tuple + variadic tuple will be implemented
separately.
@intgr intgr force-pushed the join-mismatching-length-fixed-tuples branch from ed011c3 to c2a1971 Compare February 2, 2020 10:30
@JukkaL
Copy link
Collaborator

JukkaL commented Feb 3, 2020

I discovered some awkward behavior when attempting to create a sub-subclass of NamedTuple.

Could you file a separate issue about this?

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

Thanks! Looks good now.

@JukkaL JukkaL merged commit 39d6bde into python:master Feb 3, 2020
sthagen added a commit to sthagen/python-mypy that referenced this pull request Feb 3, 2020
Fix joining of fixed-length tuples with mismatching lengths (python#8333)
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.

2 participants