I believe a Annotated[..., str] could become an attribute docstring if
by consensus we deem it to be so. I can't see any disadvantages,
perhaps save for the verbosity of `Annotated`. It certainly seems like
an advantage to use an existing mechanism rather than define a new one
that would appear to require changes to the interpreter.

On Wed, 2021-12-08 at 13:04 -0500, Ricky Teachey wrote:
> On Wed, Dec 8, 2021 at 12:46 PM Paul Bryan <pbr...@anode.ca> wrote:
> > I propose there is already a viable option in typing.Annotated.
> > Example: 
> > 
> > @dataclass
> > class InventoryItem:
> >     """Class for keeping track of an item in inventory."""
> >     
> >     name: Annotated[str, "Short name of the item."]
> >     unit_price: Annotated[float, "Price per unit in dollar."]
> >     ...
> > 
> > 
> > I've been using this in production code for about a year (with code
> > that generates OpenAPI document), with additional validation
> > constraints, and it's proving to be quite usable. 
> > 
> > Paul
> > 
> 
> 
> As I noted in the previous thread, a big downside IMO of using
> Annotated for docstrings is it really makes the help() output quite
> messy. The "docstrings" appear in at least 5 different places (as
> part of the Annotation objects).
> 
> This could be fixed, I guess. But that would skip over a question
> that gets raised here, which is: are a docstring and an annotation
> really the same thing? Are there disadvantages to assuming they are?
> 
> ---
> Ricky.
> 
> "I've never met a Kentucky man who wasn't either thinking about going
> home or actually going home." - Happy Chandler
> 
> > 

_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/DCQNO4OS3COA5CAIB2FVXRQAIXDIOKCD/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to