Author alonho
Recipients Alexander.Belopolsky, Christophe Simonis, alonho, anacrolix, belopolsky, eckhardt, ironfroggy, jackdied, jcea, ncoghlan, r.david.murray, rhettinger, ssadler
Date 2013-10-25.19:27:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1382729275.27.0.204835137059.issue4331@psf.upfronthosting.co.za>
In-reply-to
Content
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?
History
Date User Action Args
2013-10-25 19:27:55alonhosetrecipients: + alonho, rhettinger, jcea, ncoghlan, belopolsky, ironfroggy, jackdied, Christophe Simonis, ssadler, eckhardt, r.david.murray, Alexander.Belopolsky, anacrolix
2013-10-25 19:27:55alonhosetmessageid: <1382729275.27.0.204835137059.issue4331@psf.upfronthosting.co.za>
2013-10-25 19:27:55alonholinkissue4331 messages
2013-10-25 19:27:55alonhocreate