Message395427
https://docs.python.org/3/library/dataclasses.html#post-init-processing
https://github.com/python/cpython/blob/3.9/Doc/library/dataclasses.rst#post-init-processing
In the example, a base class "Rectangle" is defined, and then a "Square" class inherits from it.
On reading the example, it seems like the Square class is meant to be used like:
>>> square = Square(5)
Since the Square class seems to be supposed to be a "shortcut" to creating a Rectangle with equal sides.
However, the Rectangle class has two required init arguments, and when Square inherits from it, those arguments are still required, so using Square like in the above example, with a single argument, results in an error:
>>> square = Square(5)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: __init__() missing 2 required positional arguments: 'width' and 'side'
To "properly" use the Square class, it'd need to be instantiated like so:
>>> square = Square(0, 0, 5)
>>> square
Square(height=5, width=5, side=5)
Which, in my opinion, is completely counter-intuitive, and basically invalidates this example. |
|
Date |
User |
Action |
Args |
2021-06-09 15:33:08 | MicaelJarniac | set | recipients:
+ MicaelJarniac, docs@python |
2021-06-09 15:33:08 | MicaelJarniac | set | messageid: <1623252788.44.0.375918246935.issue44365@roundup.psfhosted.org> |
2021-06-09 15:33:08 | MicaelJarniac | link | issue44365 messages |
2021-06-09 15:33:08 | MicaelJarniac | create | |
|