Skip to content

Add _Cond, _UnpackMap, _GetAssociated to represent our syntax - #126

Open
msullivan wants to merge 1 commit into
mainfrom
ast-versions
Open

msullivan wants to merge 1 commit into
mainfrom
ast-versions

Conversation

@msullivan

@msullivan msullivan commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

The plan here is that we will start moving to an AST-first setup
(based on eventually PEP 849) in which we get an AST and translate
that into typing objects.

Currently, _UnpackMap is set up like:
_UnpackMap[Target, T, Body] is equivalent to
*[Body for T in Iter[Target]], and T needs to be
an already declared TypeVar.
(An optional 4th argument allows putting an if.)

An alternative would be to have it be
_UnpackMap[Target, lambda T: Body].

Thoughts? That's already kind of how we write GenericCallable,
though I'm not sure that GenericCallable is really done in an
acceptable way right now...

All add versions for all the boolean operations, _And, _All, etc.

I think my idea is that they will be semi-stable APIs, like a lot of the existing
typing stuff: they get used by introspection code but aren't really public APIs.

Originally I had planned for them to be non-underscore-prefixed public APIs,
and we could still do that if we wanted (for backporting without needing to
do any shenanigans?). Part of why I moved away from that was realizing
that we also have all the boolean operators, so there would kind of be a lot of them.

@msullivan
msullivan requested review from 1st1 and dnwpark September 30, 2026 21:21
@msullivan msullivan changed the title Add Cond, UnpackMap, GetAssociated to represent our syntax Add _Cond, _UnpackMap, _GetAssociated to represent our syntax Oct 1, 2026
@msullivan

Copy link
Copy Markdown
Collaborator Author

Oh, an advantage of the lambda syntax would be that it would mirror the Python scoping behavior of a comprehension better, which maybe we want.

The plan here is that we will start moving to an AST-first setup
(based on eventually PEP 849) in which we get an AST and translate
that into `typing` objects.

Currently, UnpackMap is set up like:
`UnpackMap[Body, T, Target]` is equivalent to
`*[Body for T in Iter[Target]]`, and `T` needs to be
an already declared `TypeVar`.
(An optional 4th argument allows putting an `if`.)

An alternative would be to have it be
`UnpackMap[Body, lambda T: Target]`.

Thoughts? That's already kind of how we write `GenericCallable`,
though I'm not sure that `GenericCallable` is really done in an
acceptable way right now...

This branch has not been deployed

No deployments
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.

1 participant