Raymond Hettinger <raymond.hettin...@gmail.com> added the comment:
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'>) ---------- resolution: -> not a bug _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue20751> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com