https://github.com/python/cpython/commit/12c6424205561f45edbc1041faa8080de2d8def2
commit: 12c6424205561f45edbc1041faa8080de2d8def2
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: AA-Turner <[email protected]>
date: 2024-01-17T01:33:02Z
summary:

[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 <[email protected]>

files:
M Doc/library/dataclasses.rst

diff --git a/Doc/library/dataclasses.rst b/Doc/library/dataclasses.rst
index 1b2f6d454dab65..020818a0812f0c 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):

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to