Message407623
> it should have
>
> d.__get__(obj, type(obj)) instead of d.__get__(obj)
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'>) |
|
Date |
User |
Action |
Args |
2021-12-04 01:44:12 | rhettinger | set | recipients:
+ rhettinger, docs@python, Paul Pinterits, cryvate, iritkatriel |
2021-12-04 01:44:12 | rhettinger | set | messageid: <1638582252.44.0.0747756989777.issue31735@roundup.psfhosted.org> |
2021-12-04 01:44:12 | rhettinger | link | issue31735 messages |
2021-12-04 01:44:12 | rhettinger | create | |
|