Message201279
I just want to make sure I understand the semantics concerning class methods, the following example demonstrates a usage similar to regular methods as much as possible:
class A(object):
def add(self, x, y):
print(self)
return x + y
add10 = partialmethod(add, 10)
add10class = classmethod(partialmethod(add, 10))
assert A().add10(5) == 15 # prints <__main__.A object at 0x1097e1390>
assert A.add10class(5) == 15 # prints <class '__main__.A'>
Another option would be to return a class-bound partial from the __get__ method. It's not as consistent as the first example but perhaps nicer:
class A(object):
def add(self, x, y):
print(self)
return x + y
add10 = partialmethod(add, 10)
assert A().add10(5) == 15 # prints <__main__.A object at 0x1097e1390>
assert A.add10(5) == 15 # prints <class '__main__.A'>
Is the first option what you had in mind? |
|
Date |
User |
Action |
Args |
2013-10-25 19:27:55 | alonho | set | recipients:
+ alonho, rhettinger, jcea, ncoghlan, belopolsky, ironfroggy, jackdied, Christophe Simonis, ssadler, eckhardt, r.david.murray, Alexander.Belopolsky, anacrolix |
2013-10-25 19:27:55 | alonho | set | messageid: <1382729275.27.0.204835137059.issue4331@psf.upfronthosting.co.za> |
2013-10-25 19:27:55 | alonho | link | issue4331 messages |
2013-10-25 19:27:55 | alonho | create | |
|