ericvsmith / dataclasses

Apache License 2.0
587 stars 53 forks source link

Option to see code generated from Dataclasses #139

Closed pylang closed 5 years ago

pylang commented 5 years ago

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

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.

ericvsmith commented 5 years ago

Please open an enhancement issue on bugs.python.org. This tracker is just for bugs in the backport to 3.6. Thanks.