Skip to content

Commit 4110471

Browse files
committed
Simplify __post_init__ example usage
1 parent f5166d1 commit 4110471

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

Doc/library/dataclasses.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -536,16 +536,14 @@ 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)
549547

550548
def __post_init__(self):
551549
super().__init__(self.side, self.side)

0 commit comments

Comments
 (0)