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

Skip to content

Commit e21b4f9

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

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

Doc/library/functions.rst

Lines changed: 7 additions & 0 deletions
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
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