File tree 1 file changed +32
-4
lines changed
1 file changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -1818,10 +1818,38 @@ Class Binding
1818
1818
``A.__dict__['x'].__get__(None, A) ``.
1819
1819
1820
1820
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
1825
1853
1826
1854
For instance bindings, the precedence of descriptor invocation depends on
1827
1855
which descriptor methods are defined. A descriptor can define any combination
You can’t perform that action at this time.
0 commit comments