PEP 727: Documentation Metadata in Typing

There a couple of issues with current PEP version wrt. type and doc annotations:

  1. name: Annotated[str, Doc("The user's name")] — requires type, what if someone only wants a doc? There’s no standalone Doc in the PEP.
  2. UserName: TypeAlias = Annotated[str, Doc("The user's name")] — confuses what is being annotated. Arguably, some function arg name: UserName should get doc slapped on it; instead, doc is slapped on an alias.

What would be awesome is being able to express any of the below:

name: "User's preferred personal name"
name: str @ "User's preferred name" 
name: "User's preferred name" @ str
name: str

Specifically, have doc decoupled from type by default.

(I’m abusing matrix multiplication operator because as a stand-in for hypothetical syntax that would allow several annotations on a single object)

4 Likes