[Python-Dev] PEP-able
M.-A. Lemburg
mal@lemburg.com
Thu, 20 Jul 2000 19:05:37 +0200
Paul Prescod wrote:
>
> PEP: ???
> Title: Computed Attributes
> Version: $Revision: 1.0 $
> Owner: paul@prescod.net
> Python-Version: 2.0
> Status: Incomplete
>
> Introduction
>
> This PEP describes a feature to make it easier to use Python
> attribute set/get/del syntax to fetch the results of a computation
> or to invoke computation. This feature has been emulated using
> __getattr__/__setattr__/__delattr__ but this approach suffers
> severe usability and performance concerns.
>
> Syntax
>
> Special methods should declare themselves with declarations of the
> following form:
>
> class x:
> def __get_foo__(self ): ... def __set_foo__(self, value ): ...
> def __del_foo__(self ): ...
>
> They are used like this:
>
> fooval=x.foo
> x.foo=fooval+5
> del x.foo
I don't get the point: how is this better than defining
explicit access methods ?
get_foo(self)
set_foo(self, value)
del_foo(self)
These not only define a distinct interface, but also provide
more flexibility, e.g. get_foo() could have a default argument.
--
Marc-Andre Lemburg
______________________________________________________________________
Business: http://www.lemburg.com/
Python Pages: http://www.lemburg.com/python/