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 21, 2023
1 parent 13c3597 commit f13a3cc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion 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 a nested function or a generator
expression, which implicitly creates a nested function.)

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 Expand Up @@ -1845,7 +1852,6 @@ are always available. They are listed here in alphabetical order.
:func:`super`, see `guide to using super()
<https://rhettinger.wordpress.com/2011/05/26/super-considered-super/>`_.


.. _func-tuple:
.. class:: tuple()
tuple(iterable)
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 f13a3cc

Please sign in to comment.