homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients docs@python, martin.panter, rhettinger, zuo
Date 2021年12月03日.23:39:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1638574781.2.0.22898103265.issue20751@roundup.psfhosted.org>
In-reply-to
Content
Regarding comment #1, The wording is correct and there was a reason for using a method. While super() can be used for attribute lookup, use cases are almost entirely dominated by method lookups. For many users, an attribute lookup with super() is unconventional, weird, hard to grok, awkward to demonstrate, and not well motivated by the way super() is actually used.
 ##############################################################
 # Demonstration code for the example in text
 class A:
 def m(self):
 return 42
 class B(A):
 def m(obj):
 return super(B, obj).m()
 >>> b = B()
 >>> b.m() # Normal invocation 
 42
 >>> A.__dict__['m'].__get__(b, B)() # Equivalent call
 42
That said, I will switch it to an attribute lookup for consistency with the other examples in the section and with the current version of the DescriptorHowto.
Regarding comment #2, the objtype argument is optional as shown in all of the examples. The call from object.__getattribute__() always passes in both parameters, even though only the first is required.
 
 ################################################################
 # Demonstration of __get__() being called with one or two params
 class A:
 def __init__(self, x):
 self.x = x
 def m(self, y):
 return self.x * y
 >>> a = A(10)
 >>> a.m(5)
 50
 >>> vars(A)['m'].__get__(a)(5) # objtype is not required
 50
 >>> vars(A)['m'].__get__(a, A)(5) # objtype may be used
 50
 ################################################################
 # Demonstration of object.__getattribute__ supplying both args
 class Desc:
 def __get__(self, *args):
 return args
 
 class B:
 z = Desc()
 
 >>> b = B()
 >>> b.z
 (<__main__.B object at 0x109156110>, <class '__main__.B'>)
History
Date User Action Args
2021年12月03日 23:39:41rhettingersetrecipients: + rhettinger, zuo, docs@python, martin.panter
2021年12月03日 23:39:41rhettingersetmessageid: <1638574781.2.0.22898103265.issue20751@roundup.psfhosted.org>
2021年12月03日 23:39:41rhettingerlinkissue20751 messages
2021年12月03日 23:39:40rhettingercreate

AltStyle によって変換されたページ (->オリジナル) /