I'm sure this has been considered, but can an option be added to view code generated from a dataclass?
Background
According to R. Hettinger's talkDataclasses: The code generator to end all code generators - PyCon 2018, namdedtuple once had a verbose option to view generated code of an instance. This feature was later removed in Python 3.7 because "no one ever said anything nice to me [Raymond] about that feature". Consequently, I think seeing generated code would be a helpful addition to dataclasses.
Uses
learning about dataclasses: people who are trying to understand how dataclasses work can quickly implement a dataclass and compare it to its generated code . They can learn specifically what boilerplate is being reduced.
lazy boilerplate implementation: dataclasses are used to bypass boilerplate code, but there are cases where one prefers a regular class over a dataclass (e.g. size, simplicity, teaching). Let's say I want to write a class with 20 attributes. Rather than adding def __init__(...) and self.attr_1 = attr_1, self.attr_2 = attr_2, etc. twenty times by hand, it could be faster to implement a dataclass, copy the verbose code and continue the implementation.
There appears to be some interest in such a feature based on this post and this project that inspects dataclasses.
Why?
I imagine a verbose option is more useful in dataclasses rather than namedtuples because the first is considered a substitute to classes (a container of potentially complex code), while the second substitutes tuples (a simpler data structure). Intrinsically, classes are abstract data structures - one needs to inspect each class to understand how each one works. Tuples however, are basic data structures - they all share a common behavior because they are share the same type, thus we need not inspect each instance to understand how any particular one works. Due to the varied application of dataclasses, I contend there is a stronger need to see its code as compared to namedtuples.
Request
I'm sure this has been considered, but can an option be added to view code generated from a dataclass?
Background
According to R. Hettinger's talk Dataclasses: The code generator to end all code generators - PyCon 2018,
namdedtuple
once had a verbose option to view generated code of an instance. This feature was later removed in Python 3.7 because "no one ever said anything nice to me [Raymond] about that feature". Consequently, I think seeing generated code would be a helpful addition to dataclasses.Uses
def __init__(...)
andself.attr_1 = attr_1
,self.attr_2 = attr_2
, etc. twenty times by hand, it could be faster to implement a dataclass, copy the verbose code and continue the implementation.There appears to be some interest in such a feature based on this post and this project that inspects dataclasses.
Why?
I imagine a verbose option is more useful in dataclasses rather than namedtuples because the first is considered a substitute to classes (a container of potentially complex code), while the second substitutes tuples (a simpler data structure). Intrinsically, classes are abstract data structures - one needs to inspect each class to understand how each one works. Tuples however, are basic data structures - they all share a common behavior because they are share the same type, thus we need not inspect each instance to understand how any particular one works. Due to the varied application of dataclasses, I contend there is a stronger need to see its code as compared to namedtuples.
I appreciate your feedback. Many thanks.