Thinking more about my example here:

On Tue, Dec 14, 2021 at 01:50:45AM +1100, Steven D'Aprano wrote:

>     class MyClass:
>         """Blah blah blah.
> 
>         Variable annotations of the form Annotated[T, 'string', *args]
>         always interpret the string in the second position as a 
>         docstring. If you want to use Annotated but without a docstring,
>         put None in the second position.
>         """
>         spam: Annotated[int, 'Yummy meat-like product']
>         eggs: Annotated[float, 'Goes well with spam', Domain[0, 1]]
>         cheese: Sequence[str]  # No docstring.

perhaps a better convention might be that the docstring is the *last* 
item in the Annotated metadata, rather than the second item (after the 
initial type).

The will allow people to use arbitrarily long augmented types, and 
follow it with the docstring:

    spam: Annotated[int,
                    Positive,
                    GreaterThan[1],
                    Union[Odd|Literal[2]],
                    Prime,
                    Wibble,
                    Wobble,
                    "Doc string goes here..."
                    ]=2,

That will also help ensure that the docstring stands out visually, as it 
will be last in the list, not stuck in the middle.


-- 
Steve
_______________________________________________
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/5KHCYOCDKJDIM3KU2FCLB3XSXRS6IEHM/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to