[Python-ideas] Callable properties

Masklinn masklinn at masklinn.net
Mon Jun 7 13:06:43 CEST 2010


On 2010-06-07, at 12:51 , George Sakkis wrote:
> 
> I'm wondering if there is any downside in making properties callable:
It already exists, it's called a method.

Due to the way calling works in Python (you get a callable object and
 you apply the `()` operator to it) I don't think it's possible to
discriminate based on the context to perform the same operation
whether or not the value is called.

Your best bet would probably be to wrap the output of the property
in a subtype of itself (dynamically created subtype) able to return
self on call. Or you just create a lambda wrapping the property call.




More information about the Python-ideas mailing list