Closed has2k1 closed 3 months ago
Parameters for dataclasses are currently dynamically created when accessing the class' parameters
property. Seeing that the logic can get quite complex, and based on the fact that this parameters
property cannot be easily extended by users or extensions, I think we should change the logic and generate an __init__
method object when visiting class decorated with @dataclasses.dataclass
. Extensions for third-party libs (Pydantic, attrs, whatever) could then do the same, without any special code in Griffe itself.
I haven't looked at the how the parameters are generated, but I have a temporary solution that inspects ExprCall
parameters and I only do the check for dataclasses.
Obviously this does not handle the cases when field(init=False)
is hidden inside another function.
Yes, that's what we'll use in Griffe too (thanks for the link). Just not in the parameters property as it's not extensible :)
Regarding indirections (hiding the field call in other functions), that won't be supported statically, and users will have to rely on dynamic analysis.
Here are failing tests.
Then there are the perhaps more complicated cases to deal with statically where the
field
class is wrapped inside another function e.g.