Unpacking TypeAliasType
to tuple of types using *
errors at runtime, Unpack
doesn't, pyright passes, bug in cpython or pyright?
#9343
-
I'm writing classes using variadic generic code and as a minimal example I have the below code which raises no type errors on pyright playground and is crashing at runtime which I believe is a bug in cpython, would like some advice if possible. The code: from __future__ import annotations
from typing import Unpack, assert_type
type FooArgT = tuple[str, str]
class Foo[*Arg]:
pass
type FooT = Foo[str, *FooArgT]
type FooUT = Foo[str, Unpack[FooArgT]]
class BarU(Foo[str, Unpack[FooArgT]]):
pass
def foo_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])
class Bar(Foo[str, *FooArgT]):
pass When I run this locally, I get:
By my understanding, the 2 class declarations are equivalent, pyright checks pass and cpython should allow unpacking of the aliased I'm running python3.13.0 in wsl installed using pyenv, output of
Or should I just pack in this whole python thing and go back to c++? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
@JelleZijlstra, what do you think? Should |
Beta Was this translation helpful? Give feedback.
I think we should make this work at runtime. @alwaysmpe could you open an issue on https://github.com/python/cpython about this?