Closed has2k1 closed 5 months ago
Hi @has2k1, thanks for the report :slightly_smiling_face:
I'd be more to open to a fundamental change that adds docstrings to parameters and returned/received/yielded values. This would play well with PEP 727 and our griffe-typingdoc extension supporting it, or with potential successors of this PEP.
Adding a new kind of objects would be a bad design choice IMO. This would open the door to many more different kinds of objects, complicating the API a lot. That's a no-go to me :blush:
I'd be more to open to a fundamental change that adds docstrings to parameters
I think for parameters it would not be a fundamental change. Ignoring PEP 727 (but knowing that it could bring proper runtime docstrings to all parameters), this could be as small as giving dc.Parameter
a few more attributes. Then deal with PEP 727 later.
History
PR #252 removed
InitVar
parameters from the list of dataclass members (and attributes). This was correct.New Problem
There is no way to get access to the docstrings of the
InitVar
parameters. Class parameters (dc.Parameter
) do not have docstrings, only the core objects (dc.Object
) do and now classes only keep track of those objects that are members (dc.Class.members
).Brainstorming a solution
To be useful, the type of
InitVar
parameters should be derived fromdc.Object
. Then they have.docstring
,.lines
,.lineno
, e.t.c.But none of the current subclasses
[Alias, Attribute, Class, Function, Module]
is suitable.Possible options are:
InitVar
InitVariable
InitParameter
ClassParameter
DataclassParameter
With this kind of solution, the new class category would have to be used for one of:
Option 2. seems like the better choice, but some (most) dataclass parameters are also attributes and that would complicate the solution.
That leaves option 1.
Then where should these "InitVar" objects be stored?
Maybe have them back in
dc.Class.members
. This shouldn't be the problem if they are not of typedc.Attribute
and therefore do not show up indc.Class.attributes
. This would effectively makedc.Class.members
a lookup for all objects statically defined in the class namespace.