DanielSank / observed

Observer pattern in python
MIT License
33 stars 4 forks source link

class based access behaves unpythonic #5

Closed coldfix closed 10 years ago

coldfix commented 10 years ago

The standard expectation for methods is that you can equivalently call them via class access (i.e. Foo().method() is the same as Foo.method(Foo()):

from observed import event

class Foo(object):
    @event
    def bar(self, arg):
        pass

def baz(arg):
    print("baz", arg)

def inga(inst, arg):
    print("inga", arg)

foo = Foo()
foo.bar.addObserver(baz)
Foo.bar.addObserver(inga)

foo.bar(1)          # ("baz", 1)
Foo.bar(foo, 2)     # ("inga", 2)

This equivalence is a very important property that is relied upon in many circumstances. Again, I am noticing this so fast, only because I already noticed and fixed it in obsub ;)

DanielSank commented 10 years ago

I believe this is now fixed in the dedicated-classes branch.