mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
gh-113212: Improve error message & document zero-arg super inside nested functions and generator expressions (GH-113307)
This commit is contained in:
parent
237e2cff00
commit
4a3d2419bb
4 changed files with 51 additions and 3 deletions
|
|
@ -1800,6 +1800,13 @@ are always available. They are listed here in alphabetical order.
|
|||
the second argument is a type, ``issubclass(type2, type)`` must be true (this
|
||||
is useful for classmethods).
|
||||
|
||||
When called directly within an ordinary method of a class, both arguments may
|
||||
be omitted ("zero-argument :func:`!super`"). In this case, *type* will be the
|
||||
enclosing class, and *obj* will be the first argument of the immediately
|
||||
enclosing function (typically ``self``). (This means that zero-argument
|
||||
:func:`!super` will not work as expected within nested functions, including
|
||||
generator expressions, which implicitly create nested functions.)
|
||||
|
||||
There are two typical use cases for *super*. In a class hierarchy with
|
||||
single inheritance, *super* can be used to refer to parent classes without
|
||||
naming them explicitly, thus making the code more maintainable. This use
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue