zeekay / decorum

Python decorator helper library.
MIT License
14 stars 2 forks source link

Implement __get__ to allow instance methods to be decorated #30

Closed nathanielford closed 7 years ago

nathanielford commented 7 years ago

Previously, if you decorated a method like so:

class MyDecorator(Decorum):
    ...

class A:
    @MyDecorator
    def foo(self, x):
        ...

a = A()
a.foo("bar")

... it would fail, because x would be passed to self when foo was called by the decorator. By overriding the __get__ method, we can keep the original instance (a) in the partial function returned. This works with both decorated instance methods and naked methods.