On Thu, Dec 9, 2021 at 3:08 PM Christopher Barker <python...@gmail.com>
wrote:

> On Thu, Dec 9, 2021 at 11:08 AM Simão Afonso <
> simao.afo...@powertools-tech.com> wrote:
>
>> Shouldn't typing be encouraged on dataclasses, at least?
>
>
> Typing shouldn’t be encouraged for any particular class, nor the language
> itself. Typing policy is a matter for the project/organization to decide.
>
> But Annotations are required by dataclasses in any case. That’s how the
> decorator identifies fields.
>
> The contents of those annotations are up to the user.
>
> -CHB
>
>
Since not everyone uses dataclasses and to avoid confusion: what you mean
here is that type HINTS are required by dataclasses, not Annotations. An
Annotated is a type of type hint that contains an annotation, which we're
loosely calling a member docstring in this thread (currently, a "member
docstring" is not really a thing that exists, unless you count a comment or
a string nearby the statement creating the member).

On Thu, Dec 9, 2021 at 2:01 PM Simão Afonso <
simao.afo...@powertools-tech.com> wrote:

> I'm using docstrings bellow the attributes (analogous to functions and
> classes), I think it works well.
> It helps with distinguishing the class docstring from the arguments.
>
> On 2021-12-08 13:25:55, Ricky Teachey wrote:
> > On Wed, Dec 8, 2021 at 1:20 PM Paul Bryan <pbr...@anode.ca> wrote:
> > > 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.
> >
> > I think this would be better than nothing. But it is a little verbose.
> And
> > it requires you to supply the type hint.
> >
> > I use type hinting, but I don't want to use it every time I provide an
> > Annotation/docstring.
>
> In this case, why not use the current behaviour of putting the docstring
> below the attribute?
>
> Shouldn't typing be encouraged on dataclasses, at least?


What is meant here by "the current behaviour"? Member docstrings are
currently not a feature supported by the language. If you like putting a
string under the member definition for reference, that sounds really nice.
But baking it into the language so that the docstring has to come right
after the member seems limiting to me.

This location requirement makes a lot of sense for modules and classes. But
for class members, I'd really like to be able to organize the docstring
location in a more flexible way, like (using Steven's proposed syntax):

class Steel:
    """A simple material model of steel."""

    # parameters
    modulus :: "the linear elastic modulus"
    nu :: "the poisson's ratio"
    gamma: "the density"

    # values
    modulus: float = 29e6  # ksi
    nu: float = 0.3
    gamma: float = 490  # lbs per cu ft



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

Reply via email to