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/JUGZ6UJHQQCCQNH7MCGMGJG6WZD4QAQJ/ Code of Conduct: http://python.org/psf/codeofconduct/