Skip to content

Improve tuple.__add__ type #5522

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
May 26, 2021
Merged

Improve tuple.__add__ type #5522

merged 1 commit into from
May 26, 2021

Conversation

JelleZijlstra
Copy link
Member

Noticed this while browsing the stub. This feels safe but we'll see what mypy-primer has to say.

Noticed this while browsing the stub. This feels safe but we'll see what mypy-primer has to say.
@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

kopf (https://github.com/nolar/kopf.git)
+ kopf/_cogs/structs/dicts.py:297: error: Unsupported operand types for + ("Tuple[str, ...]" and "Tuple[_K]")
+ kopf/_cogs/structs/dicts.py:323: error: Unsupported operand types for + ("Tuple[str, ...]" and "Tuple[_K]")
+ kopf/cli.py:95: error: Unsupported operand types for + ("Tuple[Union[str, Pattern[Any]], ...]" and "Tuple[Optional[str]]")

@Akuli
Copy link
Collaborator

Akuli commented May 22, 2021

The errors in kopf/.../dicts.py seem to be problems in the code being checked, as they expect an unbounded typevar to be str. But the second error doesn't make sense to me. It seems like Tuple[Optional[str]] somehow doesn't convert to Tuple[Optional[str], ...] so that it could be added to the other Tuple[Foo, ...].

@JelleZijlstra
Copy link
Member Author

Yes, seems related to mypy treating fixed-size and arbitrary-size tuples as very different types internally.

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

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

This is an improvement. As the primer output shows it catches real type problems. The mypy bug it exposes seems to be fairly corner-casey to me and I think it's fine to # type: ignore it until it's fixed in mypy. Is there already a mypy bug about this?

@srittau srittau merged commit c4da375 into master May 26, 2021
@srittau srittau deleted the JelleZijlstra-patch-1 branch May 26, 2021 20:17
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.

3 participants