23 Aug
2010
23 Aug
'10
8:45 p.m.
2010/8/23 Raymond Hettinger
I don't have a specific proposal in mind. My main questions are * Is there anything that hasattr(obj, key) can or should do that can't already be done with getattr(obj, key, None)? If not, do we really need to change anything?
For one, it's annoying when "key" can be None.
* Why do people typically use hasattr() instead getattr()? Aren't they are really trying to just determine whether a key exists somewhere in the MRO? If so, then doing anything more than that is probably a surprise.
It's generally more convenient that getattr(obj, "blah", None) is not None.
P.S. The current behavior seems to be deeply embedded:
Well, that's what happens when a behavior is added in 1990. :) -- Regards, Benjamin