Why does Python implement dataclasses.dataclass
as a class decorator and not as a base class? I think it would be at least clearer from the conceptual point of view to have it as a base class: the __init__
method seems to be the only thing a dataclass decorator adds to a class, and adding methods and attributes is what any straightforward base class in usually intended to do. Why to implement a decorator that intrinsically modifies a class? Base classes are just meant for this.
Also, having a "Dataclass
" base class would make easier for users to modify its behaviour in case any particular working mechanism is needed, one would just have to overwrite base class' methods when inheriting the dataclass.
Since it clearly has been made this way for some reason I'm trying to figure out why. The only thing that comes to my mind might be some performance-related thing, I think inheriting a class should be slower that just passing a class through a function, however I'm not sure dataclasses are meant to be highly performant - nor the Python language itself - and in any case for that we have named tuples.