]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-88531 Fix dataclass __post_init__/__init__ interplay documentation (gh...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 17 Jan 2024 01:33:09 +0000 (02:33 +0100)
committerGitHub <noreply@github.com>
Wed, 17 Jan 2024 01:33:09 +0000 (01:33 +0000)
* 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>
Doc/library/dataclasses.rst

index 915ff05d98a711d098c0688dd35a95cb51554cdd..a1066c748a77620667ede3375d682a3656aee52e 100644 (file)
@@ -529,10 +529,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):