Skip to content

Commit

Permalink
pythongh-113212: Document zero-arg super() inside nested functions …
Browse files Browse the repository at this point in the history
…and generator expressions
  • Loading branch information
WolframAlph committed Dec 22, 2023
1 parent 2912970 commit 944ab83
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Doc/library/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve :py:class:`super` error messages.

0 comments on commit 944ab83

Please sign in to comment.