[New-bugs-announce] [issue33452] add user notification that parent init will not be called in dataclass init method

Rick Teachey report at bugs.python.org
Wed May 9 16:50:00 EDT 2018


New submission from Rick Teachey <ricky at teachey.org>:

The dataclasses module is incredibly easy to use. This is a good thing. BUT one downside is it will definitely be utilized by people who don't have a thorough understanding of how it does what it does.

Even for me, despite having a very good understanding of how it works, after heavily using it on a project for about 3 weeks now I made a mistake like the one below:

class ImportantMixin:
    def __init__(self):
        super().__init__()
        important_task()

@dataclass
class NaiveDClass(ImportantMixin):
  data1 = int
  data2 = int

I then went on along my merry way. Obviously, ImportantMixin.__init__ never gets called and I didn't realize this until it was a bigger problem than it should have been (should have written better tests! but I digress).

It would seem like a good idea for the dataclasses module to let the user know they did this, probably via the warning system. Seems like it would be relatively easy to do: if there is an init method being create, just inspect the MRO for any previously defined init methods that weren't created by dataclasses.

Thanks.

----------
components: Library (Lib)
messages: 316331
nosy: Ricyteach, eric.smith
priority: normal
severity: normal
status: open
title: add user notification that parent init will not be called in dataclass init method
type: enhancement
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33452>
_______________________________________


More information about the New-bugs-announce mailing list