Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

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.

jorenham reacted with rocket emoji
@github-actions

This comment has been minimized.

@sterliakovsterliakov marked this pull request as ready for reviewMay 19, 2025 02:11
@sterliakov
Copy link
CollaboratorAuthor

@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

@ilevkivskyiilevkivskyi 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 ofsemanal_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

classC(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
CollaboratorAuthor

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:Atuple(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...

jorenham reacted with eyes emoji
@sterliakovsterliakov marked this pull request as draftMay 19, 2025 20:40
@jorenham
Copy link
Contributor

Does this perhaps also cover (part of)#17282?

@sterliakov
Copy link
CollaboratorAuthor

@jorenham probably not

jorenham reacted with thumbs up emoji

@github-actions

This comment has been minimized.

@sterliakovsterliakov marked this pull request as ready for reviewJuly 5, 2025 18:10
@github-actions
Copy link
Contributor

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

Copy link
Member

@ilevkivskyiilevkivskyi left a comment

Choose a reason for hiding this comment

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

LG, but I have one question.

# the expansion, most likely it will result in the same kind of error.
get_proper_type(t).accept(self)
ift.aliasisnotNone:
t.alias.accept(self)
Copy link
Member

Choose a reason for hiding this comment

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

This looks like a duplicate work, did you try deleting the accept just above? (if you delete it, don't forget to update the comment)

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

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

That breaks one test:

[case testValidTypeAliasValues]from typing import TypeVar, Generic, ListT = TypeVar("T", int, str)S = TypeVar("S", int, bytes)class C(Generic[T]): ...class D(C[S]): ...  # E: Invalid type argument value for "C"U = TypeVar("U")A = List[C[U]]x: A[bytes]  # E: Value of type variable "T" of "C" cannot be "bytes"V = TypeVar("V", bound=int)class E(Generic[V]): ...B = List[E[U]]y: B[str]  # E: Type argument "str" of "E" must be a subtype of "int"

Removing this line makes both errors on alias instantiation disappear. That's quite expected sinceget_proper_type calls_expand_once, so it is not equivalent to simply accepting the target alias - we do not want to ignore args here. We can limit that to only accepting if args are non-empty, but I don't think this can result in any significant speedup.

Copy link
Member

Choose a reason for hiding this comment

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

OK, this is kind of unfortunate. We already accept args in isolation at the very start (see super call), then we accept expansion, and finally the target in isolation. But I guess this is the price to pay for having both:

  • Support for unrestricted type vars in alias definitions
  • Doing some in-place patching in this visitor

@ilevkivskyiilevkivskyi merged commit2e5d7ee intopython:masterJul 22, 2025
20 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@ilevkivskyiilevkivskyiilevkivskyi approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

class S(tuple[*tuple[()]]) crashes mypy

3 participants

@sterliakov@jorenham@ilevkivskyi

[8]ページ先頭

©2009-2025 Movatter.jp