homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author tim.peters
Recipients
Date 2002年03月21日.02:25:11
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Logged In: YES 
user_id=31435
hasattr() is defined in terms of whether PyObject_GetAttr() 
raises an exception, and thanks to __getattr__ hooks can't 
be computed any faster than calling PyObject_GetAttr(). 
Which is what the code does:
	v = PyObject_GetAttr(v, name);
	if (v == NULL) {
		PyErr_Clear();
		Py_INCREF(Py_False);
		return Py_False;
	}
	Py_DECREF(v);
	Py_INCREF(Py_True);
	return Py_True;
It's simply not going to get faster than that.
I'm not saying you can't have a "better" message here 
(although since an object's __name__ field doesn't bear any 
necessary relationship to the variable name(s) through 
which the object is referenced, it's unclear that the 
message won't actually be worse in real non-trivial cases: 
the type name is an object invariant, but the name can be 
misleading). I am saying the tradeoff is real and needs to 
be addressed. That's part of "good design", Dale; doing 
what feels good in the last case you remember is arguably 
not.
History
Date User Action Args
2007年08月23日 15:11:42adminlinkissue532638 messages
2007年08月23日 15:11:42admincreate

AltStyle によって変換されたページ (->オリジナル) /