[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 22:27:36 EDT 2018


Rick Teachey <ricky at teachey.org> added the comment:

The init method that comes up for int, str, float, etc is just the object init:

assert int.__init__ is object.__init__

Probably the thing to do is grab any init methods that aren't the object.__init__ while stripping out the dataclass-created init methods? Maybe something like:

import warnings

if cls.__dataclass_params__.init:
    for pcls in cls.mro():
        if pcls.__init__ is not object.__init__:
            try:
                d_params = getattr(pcls, "__dataclass_params__")
            except AttributeError:
                warnings.warn('Found a not called init')
            else:
                if not d_params.init:
                    warnings.warn('Found a custom dataclass init')

----------

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


More information about the Python-bugs-list mailing list