Shorthand syntax for Annotated (Type @ [metadata])

I propose a shorthand inspired by PEP 604:

int@[ann1, ann2] instead of Annotated[int, ann1, ann2]

The @ operator

It mirrors decorators, extending the mental model of attaching metadata to type expressions.

The list literal

It separates the base type from metadata, handles multiple annotations without ambiguity and is consistent with how we pass parameters to generics…

This is just a quick temperature check. I am happy to flesh things out if there is interest in a formal PEP.

2 Likes

There was a recent discussion about this and related ideas: Dedicated syntax for `Annotated` - #34 by blhsing

3 Likes

Thanks for providing some context. My read of the previous discussion is that @ was a favored candidate. People liked the int @ Range(...) syntax, but consensus stalled over the ambiguity of chaining (e.g., int @ ann1 @ ann2).
A mandatory list literal (int@[ann1, ann2]) avoids those concerns.

1 Like