From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Wed, 17 Jan 2024 01:33:02 +0000 (+0100) Subject: [3.12] gh-88531 Fix dataclass __post_init__/__init__ interplay documentation (gh... X-Git-Tag: v3.12.2~162 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=12c6424205561f45edbc1041faa8080de2d8def2;p=thirdparty%2FPython%2Fcpython.git [3.12] gh-88531 Fix dataclass __post_init__/__init__ interplay documentation (gh-107404) (#114162) * Simplify __post_init__ example usage. It applies to all base classes, not just dataclasses. (cherry picked from commit 05008c27b73da640b63c0d335c65ade517c0eb84) Co-authored-by: Steffen Zeile <48187781+Kaniee@users.noreply.github.com> --- diff --git a/Doc/library/dataclasses.rst b/Doc/library/dataclasses.rst index 1b2f6d454dab..020818a0812f 100644 --- a/Doc/library/dataclasses.rst +++ b/Doc/library/dataclasses.rst @@ -534,10 +534,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):