Skip to content

Support star unpacking of operators, aliases, and tuples#70

Merged
msullivan merged 1 commit intomainfrom
unpack
Feb 2, 2026
Merged

Support star unpacking of operators, aliases, and tuples#70
msullivan merged 1 commit intomainfrom
unpack

Conversation

@msullivan
Copy link
Collaborator

Aliases and tuples weren't working for a simple reason, which is that
unpacking a types.GenericAlias with a * doesn't produce an Unpack,
but produces a types.GenericAlias with __unpacked__ set. Since we
didn't consider that, we would simply lose track of it. Fix that by
stripping unpacked, evaling the inner type, and adding an Unpack.

Built-in operators didn't work because _GenericAlias produces an
_UnpackGenericAlias when iterated, and _UnpackGenericAlias raises
an exception when it is passed to a variadic generic if it's body is
either sort of generic alias but isn't a tuple. Fix that by a bunch
of annoying overloading of what aliases our operators produce.

And then, with the annoying parts done, we just need to actually
implement the unpacking of tuple types.

Aliases and tuples weren't working for a simple reason, which is that
unpacking a types.GenericAlias with a `*` doesn't produce an `Unpack`,
but produces a `types.GenericAlias` with `__unpacked__` set.  Since we
didn't consider that, we would simply lose track of it.  Fix that by
stripping __unpacked__, evaling the inner type, and adding an Unpack.

Built-in operators didn't work because `_GenericAlias` produces an
`_UnpackGenericAlias` when iterated, and `_UnpackGenericAlias` raises
an exception when it is passed to a variadic generic if it's body is
either sort of generic alias but isn't a tuple.  Fix that by a bunch
of annoying overloading of what aliases our operators produce.

And then, with the annoying parts done, we just need to actually
implement the unpacking of tuple types.
@msullivan msullivan requested a review from dnwpark January 30, 2026 23:36
@vercel
Copy link

vercel bot commented Jan 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
python-typemap Ready Ready Preview, Comment Jan 30, 2026 11:37pm

@msullivan msullivan merged commit 84ef843 into main Feb 2, 2026
5 checks passed
@msullivan msullivan deleted the unpack branch February 2, 2026 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants