[Python-Dev] string-valued fget/fset/fdel for properties
Edward Loper
edloper at gradient.cis.upenn.edu
Mon Nov 24 04:35:33 EST 2003
Guido van Rossum wrote:
>> 1. It's easier to read. (In my opinion, anyway; what do other
>> people think?)
>
> Only if you're used to the new syntax. Otherwise it could mean a
> costly excursion into the docs.
> [...]
>> - It's one more special case to document/know.
>
> Right. It feels like a hack.
To me it seems like the "obvious" behavior for a string fget/fset/fdel,
but if it's not universally obvious than you're proably right that it's
a bad idea to add it.
> but I've got a suspicion you want to combine some string argument
> (most likely for fget) with some function argument.
Yes, the idea was that some properties only redirect on read, or only on
write; and that the syntax could be made "cleaner" for those cases.
> I'm curious about the use case that makes you feel the need for speed.
> I would expect most properties not to simply redirect to another
> attribute, but to add at least *some* checking or other calculation.
The primary motivation was actually to make the code "easier to read";
the speed boost was an added bonus. (Though not a trivial one -- I do
have a good number of fairly tight loops that access properties.) The
use case that inspired the idea is defining read-only properties for
immutable objects. But I guess I would be better off going with wrapper
functions that create the read-only properties for me (like
<http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/157768>).
Thanks for the feedback!
-Edward
More information about the Python-Dev
mailing list