Shorthand syntax for Annotated (Type @ [metadata])

I’m curious why none of the alternatives discussed in Dedicated syntax for `Annotated` were considered in the PEP under Alternatives Considered. Especially the favoured style of foo: [int, “something”] seems to address a few of the issues raised here, doesn’t require overloading an operator, naturally composes across multiline statements and is, imo, easier to read because it’s clearly scoped through the brackets.

Especially when adding multiple annotations, the @ syntax gets difficult to comprehend: name: str @ Field(min_length=3, max_length=50) @ Alias("Name") = "Anonymous" is a lot harder to parse for me than name: [str, Field(min_length=3, max_length=50), Alias("Name")] = "Anonymous", as the latter is clearly grouped by its brackets.

Even if not chosen, it would be nice to see this included in the PEP as a rejected alternative, with reasoning as to why it was rejected.

4 Likes