[Python-ideas] Callable properties
George Sakkis
george.sakkis at gmail.com
Mon Jun 7 12:51:51 CEST 2010
I'm wondering if there is any downside in making properties callable:
class callableproperty(property):
def __call__(self, obj):
return self.fget(obj)
class Foo(object):
@property
def bar(self):
return self
@callableproperty
def baz(self):
return self
>>> foo = Foo()
>>> foo.baz is Foo.baz(foo)
True
>>> foo.bar is Foo.bar(foo)
...
TypeError: 'property' object is not callable
As for the motivation, having callable properties would make it easier
to stack them with other decorators that typically expect callables.
Am I missing something ?
George
More information about the Python-ideas
mailing list