8000 gh-113212: Document zero-arg `super()` inside nested functions and ge… · python/cpython@f13a3cc · GitHub
[go: up one dir, main page]

Skip to content

Commit f13a3cc

Browse files
committed
gh-113212: Document zero-arg super() inside nested functions and generator expressions
1 parent 13c3597 commit f13a3cc

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Doc/library/functions.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1800,6 +1800,13 @@ are always available. They are listed here in alphabetical order.
18001800
the second argument is a type, ``issubclass(type2, type)`` must be true (this
18011801
is useful for classmethods).
18021802

1803+
When called directly within an ordinary method of a class, both arguments may
1804+
be omitted ("zero-argument :func:`super`"). In this case, *type* will be the
1805+
enclosing class, and *obj* will be the first argument of the immediately
1806+
enclosing function (typically ``self``). (This means that zero-argument
1807+
:func:`super` will not work as expected within a nested function or a generator
1808+
expression, which implicitly creates a nested function.)
1809+
18031810
There are two typical use cases for *super*. In a class hierarchy with
18041811
single inheritance, *super* can be used to refer to parent classes without
18051812
naming them explicitly, thus making the code more maintainable. This use
@@ -1845,7 +1852,6 @@ are always available. They are listed here in alphabetical order.
18451852
:func:`super`, see `guide to using super()
18461853
<https://rhettinger.wordpress.com/2011/05/26/super-considered-super/>`_.
18471854

1848-
18491855
.. _func-tuple:
18501856
.. class:: tuple()
18511857
tuple(iterable)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve :py:class:`super` error messages.

0 commit comments

Comments
 (0)
0