mirror of
https://github.com/python/cpython.git
synced 2025-09-28 03:13:48 +00:00
[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 05008c27b7
)
Co-authored-by: Steffen Zeile <48187781+Kaniee@users.noreply.github.com>
This commit is contained in:
parent
b201a6a1f1
commit
12c6424205
1 changed files with 3 additions and 3 deletions
|
@ -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
|
that has to be called, it is common to call this method in a
|
||||||
:meth:`__post_init__` method::
|
:meth:`__post_init__` method::
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class Rectangle:
|
class Rectangle:
|
||||||
height: float
|
def __init__(self, height, width):
|
||||||
width: float
|
self.height = height
|
||||||
|
self.width = width
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Square(Rectangle):
|
class Square(Rectangle):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue