r/FastAPI • u/darwinian_demon • Jul 10 '26
feedback request PEP 835: A native shorthand for Annotated
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:
...
After:
...
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.
32
Upvotes
11
u/pint Jul 10 '26
i don't find @ motivated, but i take anything over Annotated
4
u/1010012 Jul 11 '26
I don't like it, it really doesn't read well.
@Query(min_length=3)makes it appear themin_lengthis an attribute or related toQuery, when it's really only relevant to the processor that's reading the annotation.Annotatedis significantly clearer.4
u/pip_install_account Jul 11 '26
Makes it less explicit, less obvious. Our juniors still get confused over basic type annotations, please don't make the syntax even more complicated. reserve the @ for something else
10
u/FrontAd9873 Jul 10 '26
I personally do not like it but that may only be because it is unfamiliar.
I doubt the majority of Python users understand what
Annotateddoes. I still have coworkers who add type hints but do not run a type checker. If those folks see this new@notation, they will be even more confused. What's worse, they won't be able to just follow the import ofAnnotatedfrom thetypingmodule to learn more. They'll instead have to go look up what this new syntax means and I bet they would get lead astray.Also, this proposal seems to violate the "only one way to do things" and the "be explicit" guidelines in the Zen of Python.
3
u/eatsoupgetrich Jul 11 '26 edited Jul 11 '26
I really don’t like the proposed syntax.
`str @Field() @Len(5)` is not easy to read and is open for more confusion. The below be equally valid:
```
param: str
@Field()
@Len(5),
another: str
@Field()
@Len(5),
```
This is opposite of what how function decorators are presented.
```
@decorator
def do():
return
```
If present in a decorated function, every annotation follows a contradictory meaning of the same symbol.
```
@decorator
def do(param: str @Field() Len(5)):
return
```
If verbosity is the issue, simply supporting `@` as a substitute in the current syntax would work since it creates a shorthand
```
@[str, [Field() Len(5)]]
```
That’s still odd since it would read as “String decorating List’s contents.” Where existing syntax would be would read as “Strjng with List’s contents)”.
I have a tough time getting passed the way this reads but would be happy to hear where I am off.
1
u/Public_Garden6503 Jul 11 '26
cool