[Python-Dev] 'hasattr' is broken by design (original) (raw)
Guido van Rossum guido at python.org
Tue Aug 24 00:49:46 CEST 2010
- Previous message: [Python-Dev] 'hasattr' is broken by design
- Next message: [Python-Dev] 'hasattr' is broken by design
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Mon, Aug 23, 2010 at 3:45 PM, P.J. Eby <pje at telecommunity.com> wrote:
At 06:12 PM 8/23/2010 -0400, Yury Selivanov wrote:
BTW, is it possible to add new magic method hasattr? Maybe not in Python 3.2, but in general. In order to do this properly, you'd need to also add has or exists (or some such) to the descriptor protocol; otherwise you break descriptors' ability to operate independently of the class they're used in. You would probably also need a hasattribute, in order to be able to properly synchronize with getattr/getattribute. Seems like overkill to me, though, as I'm not sure how such a protocol actually helps ORM or persistence schemes (and I've written a few). Pretty much, if you're trying to check for the existence of an attribute, you're probably about to be getting that attribute anyway. (i.e. why query the existence of an attribute you don't intend to use?)
Right. This sounds like way too big a gun to kill this particular mosquito. If Yury wants to write a PEP I won't stop him, but I expect that it will be rejected for want of important use cases compared to the complexity of the solution. There just are too many places that would be affected, for too little value.
So just be warned.
OTOH I still think that fixing hasattr() to be mroe like getattr(obj, key, None) has a high value and a relative low risk.
-- --Guido van Rossum (python.org/~guido)
- Previous message: [Python-Dev] 'hasattr' is broken by design
- Next message: [Python-Dev] 'hasattr' is broken by design
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]