alon horev added the comment:
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?
----------
nosy: +alonho
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue4331>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com