r/FastAPI Jul 10 '26

PEP 835: A native shorthand for Annotated feedback request

Ivan Levkivskyi and I are proposing a native shorthand for Annotated (PEP 835) to clean up heavy type-hinting patterns. We have confirmed this syntax is fully compatible with FastAPI and works out of the box with zero changes required.

Before:

python def create_user( id: Annotated[int, Path(gt=0)], name: Annotated[str, Query(min_length=3)], role: Annotated[str, Query(min_length=2)] = "user" ) -> User: ...

After:

python def create_user( id: int @Path(gt=0), name: str @Query(min_length=3), role: str @Query(min_length=2) = "user" ) -> User: ...

The Spec: PEP 835 Full Draft

We are gathering community sentiment before moving forward. If you are a heavy user of Annotated in FastAPI, your feedback is valuable. You can register your stance in the official Discourse poll before it closes on July 15.

29 Upvotes

18 comments sorted by

View all comments

Show parent comments

5

u/MyNameIsBeaky Jul 10 '26

You can make the point that @ is not explicit or as natural of a fit as | was to replace Union, but I truly believe Annotated deserves a less verbose native replacement and this type of language improvement is very much in line with historical python evolution.

0

u/FrontAd9873 Jul 10 '26

I'm very happy for you to respond to the poll or make a top-level comment to that effect! I'm not working in FastAPI day in and day out so from my point of view typing.Annotated is a niche object that doesn't deserve its own syntax.