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

__post_init__ and repeated decorator produces max recursion depth #43

Closed dand-oss closed 3 years ago

dand-oss commented 3 years ago
from dataclassy import dataclass

@dataclass
class Base:
    a: int = 0

@dataclass
class Inherit(Base):
    b: int = 0

    def __post_init__(self) -> None:
        pass

inst = Inherit()

Traceback (most recent call last):
  File "test.py", line 17, in <module>
    inst = Inherit()
  File "<string>", line 4, in __init__
  File "<string>", line 4, in __init__
  File "<string>", line 4, in __init__
  [Previous line repeated 995 more times]
RecursionError: maximum recursion depth exceeded
biqqles commented 3 years ago

The cause is the renaming of __init__ to __post_init__ here. Both functions are supported for post-initialisation processing but the former is a historical artifact at this point. I've been thinking of removing it as no one seems to use it and it's confusing, this bug makes me think I should. Removing the two lines linked resolves it.

biqqles commented 3 years ago

Fixed - will postpone removing __init__ aliasing to a later issue.