Skip to content

Commit 135ecc3

Browse files
authored
bpo-20751: Replace method example with attribute example, matching the descriptor howto (GH-29909)
1 parent 0ae4e0c commit 135ecc3

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

Doc/reference/datamodel.rst

+32-4
Original file line numberDiff line numberDiff line change
@@ -1818,10 +1818,38 @@ Class Binding
18181818
``A.__dict__['x'].__get__(None, A)``.
18191819

18201820
Super Binding
1821-
If ``a`` is an instance of :class:`super`, then the binding ``super(B, obj).m()``
1822-
searches ``obj.__class__.__mro__`` for the base class ``A``
1823-
immediately following ``B`` and then invokes the descriptor with the call:
1824-
``A.__dict__['m'].__get__(obj, obj.__class__)``.
1821+
A dotted lookup such as ``super(A, a).x`` searches
1822+
``obj.__class__.__mro__`` for a base class ``B`` following ``A`` and then
1823+
returns ``B.__dict__['x'].__get__(a, A)``. If not a descriptor, ``x`` is
1824+
returned unchanged.
1825+
1826+
.. testcode::
1827+
:hide:
1828+
1829+
class Desc:
1830+
def __get__(*args):
1831+
return args
1832+
1833+
class B:
1834+
1835+
x = Desc()
1836+
1837+
class A(B):
1838+
1839+
x = 999
1840+
1841+
def m(self):
1842+
'Demonstrate these two calls are equivalent'
1843+
result1 = super(A, a).x
1844+
result2 = B.__dict__['x'].__get__(a, A)
1845+
return result1 == result2
1846+
1847+
.. doctest::
1848+
:hide:
1849+
1850+
>>> a = A()
1851+
>>> a.m()
1852+
True
18251853

18261854
For instance bindings, the precedence of descriptor invocation depends on
18271855
which descriptor methods are defined. A descriptor can define any combination

0 commit comments

Comments
 (0)