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

Unpacking TypeAliasType to tuple of types using * errors at runtime, Unpack doesn't #126085

Closed
Labels
@alwaysmpe

Description

@alwaysmpe

Bug report

Bug description:

Discussed inmicrosoft/pyright#9343@JelleZijlstraasked me to open this issue.

I'm writing classes using variadic generic code and as a minimal example I have the below code which raises no type errors onpyright playground and is crashing at runtime which I believe is a bug in cpython. The code:

from __future__importannotationsfromtypingimportUnpack,assert_type,TypeAliastypeFooArgT=tuple[str,str]# deprecated but works at runtimeFooArgAliasT:TypeAlias=tuple[str,str]classFoo[*Arg]:passtypeFooT=Foo[str,*FooArgT]typeFooUT=Foo[str,Unpack[FooArgT]]classBarAU(Foo[str,*FooArgAliasT]):passclassBarU(Foo[str,Unpack[FooArgT]]):passdeffoo_fn(t_arg:FooT,ut_arg:FooUT):assert_type(t_arg,FooT)assert_type(t_arg,FooUT)assert_type(t_arg,Foo[str,Unpack[FooArgT]])assert_type(t_arg,Foo[str,*FooArgT])assert_type(ut_arg,FooT)assert_type(ut_arg,FooUT)assert_type(ut_arg,Foo[str,Unpack[FooArgT]])assert_type(ut_arg,Foo[str,*FooArgT])classBar(Foo[str,*FooArgT]):pass

When I run this locally I get

Traceback (most recent call last):  File "...", line 31, in <module>    class Bar(Foo[str, *FooArgT]):                  ^^^^^^^^^^^^^TypeError: Value after * must be an iterable, not typing.TypeAliasType

By my understanding, the 3 class declarations are equivalent, pyright checks pass and from my understanding of the documentation cpython should allow unpacking of the aliased TypeVarTuple.

I'm running python3.13.0 in wsl installed using pyenv, output ofpython -V -V

Python 3.13.0 (main, Oct 24 2024, 00:12:39) [GCC 11.4.0]

CPython versions tested on:

3.13
3.14

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2026 Movatter.jp