A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2005-December/058527.html below:

[Python-Dev] hasattr and properties

[Python-Dev] hasattr and properties [Python-Dev] hasattr and propertiesGreg Ewing greg.ewing at canterbury.ac.nz
Fri Dec 9 04:31:19 CET 2005
Guido van Rossum wrote:

> Um, that does't work for types which customize __getattribute__ or
> __getattr__ in various ways.

There could be a __hasattr__ slot in the class itself for
that purpose.

> IMO a property that has a side effect (other than updating a cache or
> statistics or perhaps logging) is a misfeature anyway,

Even if it doesn't have side effects, getting the attribute's
value could be expensive. One shouldn't have to pay the full
cost of getting the value just to find out whether the attribute
itself exists.

To put it another way, hasattr is enquiring about the object's
interface, not asking it to perform a computation. Doing the
latter when only being asked to do the former is wrong, IMO.

Greg
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4