Open alwaysmpe opened 1 month ago
To fix this, we can add a tp_iter
slot to TypeAliasType that produces Unpack[self]
. Something very similar already exists for TypeVarTuple; in fact we can probably reuse the same C function. If anyone reading this is interested, please file a PR! Otherwise I'll do it myself at some point.
I reclassified this as a feature request because it's adding a new capability to TypeAliasType, which we only do in new feature versions. However, we'll be able to backport this behavior to typing-extensions for the benefit of earlier Python versions.
I'll have a look but make zero promises as I've never touched the cpython code base before so anyone else is welcome.
I'll have a look but make zero promises as I've never touched the cpython code base before so anyone else is welcome.
FYI, you need to modify Objects/typevarobject.c
file (add a tp_iter
slot to _PyTypeAlias_Type
). See typevartuple_iter
as reference implementation.
I'd actually recommend to use typevartuple_iter
directly; it looks like it should work unchanged. However, the function should be renamed for clarity in that case.
Bug report
Bug description:
Discussed in microsoft/pyright#9343 @JelleZijlstra asked 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 on pyright playground and is crashing at runtime which I believe is a bug in cpython. The code:
When I run this locally I get
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 of
python -V -V
CPython versions tested on:
3.13 3.14
Operating systems tested on:
Linux