mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
bpo-20751: Match variable name to the example. (GH-29980)
This commit is contained in:
parent
b0b3086279
commit
4ccccb1cfc
1 changed files with 8 additions and 4 deletions
|
|
@ -1823,7 +1823,7 @@ Class Binding
|
||||||
|
|
||||||
Super Binding
|
Super Binding
|
||||||
A dotted lookup such as ``super(A, a).x`` searches
|
A dotted lookup such as ``super(A, a).x`` searches
|
||||||
``obj.__class__.__mro__`` for a base class ``B`` following ``A`` and then
|
``a.__class__.__mro__`` for a base class ``B`` following ``A`` and then
|
||||||
returns ``B.__dict__['x'].__get__(a, A)``. If not a descriptor, ``x`` is
|
returns ``B.__dict__['x'].__get__(a, A)``. If not a descriptor, ``x`` is
|
||||||
returned unchanged.
|
returned unchanged.
|
||||||
|
|
||||||
|
|
@ -1843,15 +1843,19 @@ Super Binding
|
||||||
x = 999
|
x = 999
|
||||||
|
|
||||||
def m(self):
|
def m(self):
|
||||||
'Demonstrate these two calls are equivalent'
|
'Demonstrate these two descriptor invocations are equivalent'
|
||||||
result1 = super(A, a).x
|
result1 = super(A, self).x
|
||||||
result2 = B.__dict__['x'].__get__(a, A)
|
result2 = B.__dict__['x'].__get__(self, A)
|
||||||
return result1 == result2
|
return result1 == result2
|
||||||
|
|
||||||
.. doctest::
|
.. doctest::
|
||||||
:hide:
|
:hide:
|
||||||
|
|
||||||
>>> a = A()
|
>>> a = A()
|
||||||
|
>>> a.__class__.__mro__.index(B) > a.__class__.__mro__.index(A)
|
||||||
|
True
|
||||||
|
>>> super(A, a).x == B.__dict__['x'].__get__(a, A)
|
||||||
|
True
|
||||||
>>> a.m()
|
>>> a.m()
|
||||||
True
|
True
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue