Skip to content

Commit 606ea77

Browse files
authored
Simplify __post_init__ example usage
1 parent f5166d1 commit 606ea77

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

Doc/library/dataclasses.rst

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -536,17 +536,15 @@ class :meth:`~object.__init__` methods. If the base class has an :meth:`~object.
536536
that has to be called, it is common to call this method in a
537537
:meth:`__post_init__` method::
538538

539-
@dataclass
540539
class Rectangle:
541-
height: float
542-
width: float
540+
def __init__(self, height, width):
541+
self.height = height
542+
self.width = width
543543

544544
@dataclass
545545
class Square(Rectangle):
546546
side: float
547-
height: float = field(init=False)
548-
width: float = field(init=False)
549-
547+
550548
def __post_init__(self):
551549
super().__init__(self.side, self.side)
552550

0 commit comments

Comments
 (0)