On 2010-08-23, at 5:22 PM, Yury Selivanov wrote:
On 2010-08-23, at 5:02 PM, Michael Foord wrote:
On 23/08/2010 23:55, Benjamin Peterson wrote:
2010/8/23 Raymond Hettingerraymond.email@example.com:
On Aug 23, 2010, at 1:13 PM, Benjamin Peterson wrote:
2010/8/23 Michael Foordfuzzyman@voidspace.org.uk:
To me hasattr *looks* like a passive introspection function, and the fact that it can trigger arbitrary code execution is unfortunate - especially because a full workaround is pretty arcane.
hasattr(x, "y") doesn't look any more passive to me the x.y.
One says "does this object have attribute y" the other fetches attribute y. I'm amazed they don't look different to you. Given Python's object model there is no reason that the first *should* fetch the attribute to determine that it is present, *except* for the dynamic attribute creation of __getattr__ and __getattribute__.
As I understand the only possible way to make 'hasattr' work as it name indicates (i.e. just check if attribute exists, not run it), is to add another magic method(s?) to the existing __getattr__ and __getattribute__ which will tell whether attribute exists or not, and by default this method would mimic current 'hasattr' behaviour.
I'm not sure we should do this, but if such method exists, let's call it __hasattribute__, ORMs, for instance, probably would benefit.