[Python-ideas] Callable properties
fuzzyman at voidspace.org.uk
Mon Jun 7 13:34:06 CEST 2010
On 7 June 2010 12:06, Masklinn <masklinn at masklinn.net> wrote:
> 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.
I think you misunderstood, he was suggesting making the property descriptor
Not a bad idea, but as a change to a builtin it would be covered by the
language moratorium. Easy to do in a subclass of property though.
At the moment you do the following, which is a bit ugly:
>>> class Foo(object):
... def foo(self):
... return 'foo'
>>> f = Foo()
The reason for wanting to do this are the same reasons as you would call an
> Python-ideas mailing list
> Python-ideas at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas