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

[typing: PEP 646]:*tuple[int, int] is improperly evaluated byget_type_hints #101015

Closed
Labels
topic-typingtriagedThe issue has been accepted as valid by a triager.type-bugAn unexpected behavior, bug, or error
@hjalmarlucius

Description

@hjalmarlucius

Bug report

Unpack information oftyping.GenericAlias is not transferred from string annotations to interpreted annotations.typing.Unpacked works as expected.

A fix could be to addif getattr(t, "__unpacked__", False): return next(iter(GenericAlias(t.__origin__, ev_args))) clause here:

cpython/Lib/typing.py

Lines 373 to 374 in6492492

ifisinstance(t,GenericAlias):
returnGenericAlias(t.__origin__,ev_args)

NOTE: This bug is in typing's internal API and I don't think there's issues in the public API (but haven't looked hard). However, this issue pops up quickly if you try to do anything wrt PEP 646 typing at runtime.

Minimal example

fromtypingimportForwardReffromtypingimportTypeVarTupleTs=TypeVarTuple("Ts")typ=ForwardRef("*Ts")._evaluate({}, {"Ts":Ts},frozenset())asserttyp==next(iter(Ts))# <-- PASSES AS EXPECTEDtyp=ForwardRef("*tuple[int]")._evaluate({}, {},frozenset())asserttyp==tuple[int]# <-- PASSES BUT SHOULDN'Tasserttyp==next(iter(tuple[int]))# <-- SHOULD PASS BUT DOESN'T

Your environment

Python 3.11

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic-typingtriagedThe issue has been accepted as valid by a triager.type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp