Skip to content

Use normalized tuples for fallback calculation #19111

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sterliakov
Copy link
Collaborator

Fixes #19105. I haven't checked this with namedtuples magic, nor am I certain that this is the best way.

Copy link
Contributor

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

@sterliakov sterliakov marked this pull request as ready for review May 19, 2025 02:11
@sterliakov
Copy link
Collaborator Author

@ilevkivskyi sorry to bother you again, I'd appreciate a review - this PR fixes a crash and you should be well familiar with the affected part. Thanks!

Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

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

Thanks, unfortunately this whole normalization story is a bit tricky (partially because of design limitations of semanal_typeags.py). FWIW I think for now some "reactive" bug fixing is OK, but at some point we may need to think about tightening this a bit more.

# https://github.com/python/mypy/issues/19105
from typing import Unpack

class A(tuple[Unpack[tuple[int]]]): ...
Copy link
Member

Choose a reason for hiding this comment

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

Could you please also add a test for

class C(tuple[Unpack[tuple[int, ...]]]): ...

(unless there is already such test case)? I am not sure we properly handle such types. Also maybe test not just class creation, but some tuple ops as well, such as e.g. unpacking etc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Surprisingly we don't have such a test too, but it was already working before my patch - *tuple[int, ...] is not a trivial unpack. But your feeling is overall correct - I'm able to make it crash with

a: A
tuple(a)

and also get a terrible diagnostic on

b: B
_, = b  # E: Variadic tuple unpacking requires a star target

despite B clearly not being variadic. I'll move this to draft for now, there's little benefit from merging a crash fix that causes a next one immediately...

@sterliakov sterliakov marked this pull request as draft May 19, 2025 20:40
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.

class S(tuple[*tuple[()]]) crashes mypy
2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy