Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2017年12月29日 11:36:24 -0800

On 2017年12月29日 11:12:11 -0800
Ethan Smith <[email protected]> wrote:
> 
> > Agreed as well. If I make the effort of having a dataclass inherit
> > from a base class, I probably don't want the base class' methods to be
> > silently overriden by machine-generated methods. Of course, that can
> > be worked around by using multiple inheritance, you just need to be
> > careful and add a small amount of class definition boilerplate.
> 
> I am not sure exactly what you mean by "worked around by using multiple
> inheritance".
I mean you can write:
class _BaseClass:
 def __repr__(self):
 # ...
@dataclass
class _DataclassMixin:
 # your attribute definitions here
class FinalClass(_BaseClass, _BaseDataclass):
 pass
Yes, it's tedious and verbose :-)
Regards
Antoine.
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to