On Mon, Jun 7, 2010 at 5:51 AM, George Sakkis <span dir="ltr"><<a href="mailto:george.sakkis@gmail.com">george.sakkis@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

I'm wondering if there is any downside in making properties callable:<br>
<br>
class callableproperty(property):<br>
    def __call__(self, obj):<br>
        return self.fget(obj)<br>
<br>
class Foo(object):<br>
    @property<br>
    def bar(self):<br>
        return self<br>
<br>
    @callableproperty<br>
    def baz(self):<br>
        return self<br>
<br>
<br>
>>> foo = Foo()<br>
>>> foo.baz is Foo.baz(foo)<br>
True<br>
>>> foo.bar is Foo.bar(foo)<br>
...<br>
TypeError: 'property' object is not callable<br>
<br>
<br>
As for the motivation, having callable properties would make it easier<br>
to stack them with other decorators that typically expect callables.<br>
Am I missing something ?<br></blockquote><div><br clear="all">I find stacking descriptors to be easier than it might at first appear (and making decorators descriptors is also advantageous).  Treating properties like Yet Another Descriptor helps here.  As it is you could use Foo.bar.__get__(foo), or generally Foo.bar.__get__ as a callable.<br>

<br></div></div>-- <br>Ian Bicking  |  <a href="http://blog.ianbicking.org">http://blog.ianbicking.org</a><br>