Definition of "property"

Jon Ribbens jon+usenet at unequivocal.eu
Mon May 31 10:34:05 EDT 2021


On 2021-05-31, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> On 31/05/21 9:13 am, Jon Ribbens wrote:
>> No, I said it pretends to be a *data* attribute.
>
> I don't think it's pretending to be anything. From the outside,
> it's just an attribute.

>From the outside, it's just a *data* attribute. Which, from the inside,
it isn't. Hence "pretending".

> Data attributes are more common than non-data attributes, so
> we tend to assume that an attribute is a data attribute until
> told otherwise. But that's just our psychological bias, not
> because of any pretence on the part of properties.

None of that is true. You can tell something's definitely not
a data attribute if you have to put brackets after its name
to call it as a method to invoke its function or retrieve the
value it returns. Accessing a data attribtue is efficient and
has no side effects, unless someone's doing some unusual and
probably inadvisable hackery behind the scenes. Calling a method
can do literally anything.

> Also, there's a sense in which *all* attributes are properties.
> At the lowest level, all attribute accesses end up calling
> a method. It's just that in most cases the method is implemented
> in C and it looks up a value in the object's dict.

Sure, if we take the "lowest level" and pretend there are no
higher-level structures it's all just electrons doing apparently
random things and there's nothing more to be said about it.


More information about the Python-list mailing list