From 05008c27b73da640b63c0d335c65ade517c0eb84 Mon Sep 17 00:00:00 2001 From: Steffen Zeile <48187781+Kaniee@users.noreply.github.com> Date: Wed, 17 Jan 2024 02:17:34 +0100 Subject: gh-88531 Fix dataclass __post_init__/__init__ interplay documentation (gh-107404) * Simplify __post_init__ example usage. It applies to all base classes, not just dataclasses. --- Doc/library/dataclasses.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/dataclasses.rst b/Doc/library/dataclasses.rst index bbbbcb0..cde147d 100644 --- a/Doc/library/dataclasses.rst +++ b/Doc/library/dataclasses.rst @@ -536,10 +536,10 @@ class :meth:`~object.__init__` methods. If the base class has an :meth:`~object. that has to be called, it is common to call this method in a :meth:`__post_init__` method:: - @dataclass class Rectangle: - height: float - width: float + def __init__(self, height, width): + self.height = height + self.width = width @dataclass class Square(Rectangle): -- cgit v0.12