summaryrefslogtreecommitdiffstats
path: root/Doc/reference
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2021-12-04 02:37:08 (GMT)
committerGitHub <noreply@github.com>2021-12-04 02:37:08 (GMT)
commit135ecc3492cee259090fd4aaed9056c130cd2eba (patch)
tree319f8dbeed135dc415eb6b0f5c9924e974b1e060 /Doc/reference
parent0ae4e0c959bbc90ec18180ef3cc957759d346ced (diff)
downloadcpython-135ecc3492cee259090fd4aaed9056c130cd2eba.zip
cpython-135ecc3492cee259090fd4aaed9056c130cd2eba.tar.gz
cpython-135ecc3492cee259090fd4aaed9056c130cd2eba.tar.bz2
bpo-20751: Replace method example with attribute example, matching the descriptor howto (GH-29909)
Diffstat (limited to 'Doc/reference')
-rw-r--r--Doc/reference/datamodel.rst36
1 files changed, 32 insertions, 4 deletions
diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst
index b14b2cb..4109245 100644
--- a/Doc/reference/datamodel.rst
+++ b/Doc/reference/datamodel.rst
@@ -1818,10 +1818,38 @@ Class Binding
``A.__dict__['x'].__get__(None, A)``.
Super Binding
- If ``a`` is an instance of :class:`super`, then the binding ``super(B, obj).m()``
- searches ``obj.__class__.__mro__`` for the base class ``A``
- immediately following ``B`` and then invokes the descriptor with the call:
- ``A.__dict__['m'].__get__(obj, obj.__class__)``.
+ A dotted lookup such as ``super(A, a).x`` searches
+ ``obj.__class__.__mro__`` for a base class ``B`` following ``A`` and then
+ returns ``B.__dict__['x'].__get__(a, A)``. If not a descriptor, ``x`` is
+ returned unchanged.
+
+.. testcode::
+ :hide:
+
+ class Desc:
+ def __get__(*args):
+ return args
+
+ class B:
+
+ x = Desc()
+
+ class A(B):
+
+ x = 999
+
+ def m(self):
+ 'Demonstrate these two calls are equivalent'
+ result1 = super(A, a).x
+ result2 = B.__dict__['x'].__get__(a, A)
+ return result1 == result2
+
+.. doctest::
+ :hide:
+
+ >>> a = A()
+ >>> a.m()
+ True
For instance bindings, the precedence of descriptor invocation depends on
which descriptor methods are defined. A descriptor can define any combination