]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-88531 Fix dataclass __post_init__/__init__ interplay documentation (gh-107404)
authorSteffen Zeile <48187781+Kaniee@users.noreply.github.com>
Wed, 17 Jan 2024 01:17:34 +0000 (02:17 +0100)
committerGitHub <noreply@github.com>
Wed, 17 Jan 2024 01:17:34 +0000 (20:17 -0500)
* Simplify __post_init__ example usage. It applies to all base classes, not just dataclasses.

Doc/library/dataclasses.rst

index bbbbcb00d8fef834af77997e3f53779b50f69420..cde147d1cbb501b37b289fc5417fb96e3ae96f3c 100644 (file)
@@ -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):