Why property works only for objects?

Michal Kwiatkowski ruby at no.spam
Sun Mar 12 12:21:43 EST 2006


Alex Martelli napisał(a):
>> IMHO that's not very consistent. 
> 
> How so? Given the lower-level semantics of descriptors (and the
> distinction between overriding and non), are you suggesting that
> property should not be a type but a factory function able to return
> instances of either overriding or non-overriding types? I'm not sure how
> that complication would make things "consistent" in your view.

Nothing in property documentation suggest that if you don't define
__set__ method, you won't be able to set an attribute. It just states
"Return a property attribute for new-style classes". After reading a bit
about descriptors I've just assumed that property is a handy way to
create (any) descriptors. Learning that it only creates overriding
descriptors was a bit shocking. I'm not suggesting it's bad behavior,
only that it seemed unexpected for an unaware programmer. What at first
glance looked like a shortcut, turned out to be designed for a specific
use case.

mk
-- 
 . o .       >>  http://joker.linuxstuff.pl  <<
 . . o   It's easier to get forgiveness for being wrong
 o o o   than forgiveness for being right.



More information about the Python-list mailing list