[Python-ideas] Callable properties

Guido van Rossum guido at python.org
Mon Jun 7 17:33:20 CEST 2010


Not sure I follow all of this, but in general overloading of __call__ should
be used rarely -- it's too easy for code to become unreadable otherwise.

--Guido

On Mon, Jun 7, 2010 at 6:40 AM, Michael Foord <fuzzyman at voidspace.org.uk>wrote:

>
>
> On 7 June 2010 12:34, Michael Foord <fuzzyman at voidspace.org.uk> wrote:
>
>>
>> [snip...]
>> I think you misunderstood, he was suggesting making the property
>> descriptor instances callable.
>>
>> 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):
>> ...  @property
>> ...  def foo(self):
>> ...   return 'foo'
>> ...
>> >>> f = Foo()
>> >>> Foo.foo.__get__(f)
>> 'foo'
>>
>> The reason for wanting to do this are the same reasons as you would call
>> an unbound method.
>>
>>
> Or this which is still slightly ugly but at least gets rid of the magic
> method call:
>
>
> >>> class Foo(object):
> ...  @property
> ...  def foo(self):
> ...   return 'foo'
> ...
> >>> f = Foo()
> >>> Foo.foo.fget(f)
> 'foo'
>
>
> Michael
>
>
>
>> Michael
>>
>>
>>>
>>> _______________________________________________
>>> Python-ideas mailing list
>>> Python-ideas at python.org
>>> http://mail.python.org/mailman/listinfo/python-ideas
>>>
>>
>>
>>
>> --
>> http://www.voidspace.org.uk
>>
>>
>>
>
>
> --
> http://www.voidspace.org.uk
>
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
>


-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20100607/dc12c44f/attachment.html>


More information about the Python-ideas mailing list