biqqles / dataclassy

A fast and flexible reimplementation of data classes
https://pypi.org/project/dataclassy
Mozilla Public License 2.0
81 stars 9 forks source link

User-defined __init__ not detected when declared on subclass #21

Closed kgreav closed 3 years ago

kgreav commented 3 years ago

As of version 0.7.0 it looks like inheritance no longer works the way it used to. I assume this is a bug as there was no breaking change documented, but lmk if I'm wrong.

Basically this used to work:

@dataclass
class Derps(object):
    name: str = ""

class Terps(Derps):
    _test: int = 0

    def __init__(self, test: int):
        self._test = test

Terps(test=3)

But as of version 0.7.0 throws:

Terps(test=3)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: __init__() got an unexpected keyword argument 'test'

I suspect this is in relation to the __post_init__ changes. If I get time tomorrow/on the weekend I'll have a look, but you may have a better idea than me :)

biqqles commented 3 years ago

It is probably that it doesn't correctly detect __init__ being defined on a subclass. I will take a look.

biqqles commented 3 years ago

OK, fixed locally by adding a marker for dataclassy-defined functions. I just want to write some tests before confirming as fixed.

kgreav commented 3 years ago

excellent, thanks a bunch

biqqles commented 3 years ago

Sorry, it took me way longer than expected to get around to pushing this.

kgreav commented 3 years ago

No worries, I shall upgrade soon to keep testing the latest version.