[issue44365] Bad dataclass post-init example

2021-10-31 Thread da2ce7


da2ce7  added the comment:

I have made a slightly more comprehensive example. See file attached.

Please consider for the updated documentation.

--
nosy: +da2ce7
Added file: https://bugs.python.org/file50414/dataclass_inheritance_test.py

___
Python tracker 
<https://bugs.python.org/issue44365>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44365] Bad dataclass post-init example

2021-10-31 Thread da2ce7


da2ce7  added the comment:

Upon Self Review, I think that this slightly updated version is a bit more 
illustrative.

--
Added file: https://bugs.python.org/file50415/dataclass_inheritance_v2_test.py

___
Python tracker 
<https://bugs.python.org/issue44365>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44365] Bad dataclass post-init example

2021-10-31 Thread da2ce7


da2ce7  added the comment:

Amazingly, the original example needs a very small change to make it work as 
expected:

@dataclass
class Rectangle:
height: float
width: float

@dataclass
class Square(Rectangle):
side: float
height: float = field(init=False)
width: float = field(init=False)

def __post_init__(self) -> None:
super().__init__(self.side, self.side)

I discover this now, after playing around for a while.
Attached is the simplified version of my expanded example testcase.

--
Added file: https://bugs.python.org/file50416/dataclass_inheritance_v3_test.py

___
Python tracker 
<https://bugs.python.org/issue44365>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com