A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2017-December/151499.html below:

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

[Python-Dev] Concerns about method overriding and subclassing with dataclasses [Python-Dev] Concerns about method overriding and subclassing with dataclassesAntoine Pitrou solipsis at pitrou.net
Fri Dec 29 14:18:43 EST 2017
On Fri, 29 Dec 2017 11:12:11 -0800
Ethan Smith <ethan at ethanhs.me> 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.
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4