Repeating some points I already made in the other topic:
Ergonomics
Seeing as the motivator behind this is ergonomics and readability, I’m not convinced this proposal meaningfully improves things.
The PEP cites, as it’s primary real-world example of negative impacts of Annotated:
This ergonomic barrier was notably evident in the withdrawal of PEP 727 (Documentation Metadata). The extreme verbosity of the syntax in function signatures was a primary factor in its community pushback. A native shorthand makes such metadata-heavy standards significantly more viable.
This is, in my opinion, simply not correct. Looking at the proposed PEP 727, we can compare actual FastAPI source code with, and without PEP 835:
def __init__(
self: AppType,
*,
debug: Annotated[
bool,
Doc(
"""
Boolean indicating if debug tracebacks should be returned on server
errors.
Read more in the
[Starlette docs for Applications](https://www.starlette.dev/applications/#instantiating-the-application).
"""
),
] = False,
vs. how it would look with a shorthand syntax:
def __init__(
self: AppType,
*,
debug: bool @ (
Doc(
"""
Boolean indicating if debug tracebacks should be returned on server
errors.
Read more in the
[Starlette docs for Applications](https://www.starlette.dev/applications/#instantiating-the-application).
"""
),
) = False,
The verbosity is identical, and does not come from Annotated, but from the proposed Doc type, putting documentation inside the function signature.
Other examples included are also neither more terse nor readable, and some, seem even worse:
async def read_items(q: (str | None) @ Query(max_length=50) = None):
...
is more involved than
async def read_items(q: Annotated[str | None, Query(max_length=50)] = None):
...
This particular instance could also be solved in a different way, without requiring new syntax, if it were allowed to dynamically produce TypeForms to be used in annotations, subclass Annotated, or any other method of marking a type “transparent” to the type checker. Then we could write:
async def read_items(q: Query[str | None](max_length=50) = None):
...
Usefulness to the broader ecosystem
The PEP mentions only the Pydantic + FastAPI ecosystem as benefiting from this, and while libraries making use of type annotations are become more and more common, support for this seems to be focused on a particular niche (although one has to consider the massive popularity of those libraries mentioned in the PEP).
Many potential downsides and pitfalls have been brought up here already, so the usefulness of this should probably outweigh those. Hearing from users / maintainers of other libraries making extensive use of Annotated would be great for this.