[Python-Dev] 'hasattr' is broken by design (original) (raw)
Benjamin Peterson benjamin at python.org
Mon Aug 23 23:05:00 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 ]
2010/8/23 Michael Foord <fuzzyman at voidspace.org.uk>:
On 23/08/2010 23:55, Benjamin Peterson wrote:
2010/8/23 Raymond Hettinger<raymond.hettinger at gmail.com>:
On Aug 23, 2010, at 1:13 PM, Benjamin Peterson wrote:
2010/8/23 Michael Foord<fuzzyman at 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.
Actually, I'd say given Python's object model, you have to have the attribute in hand to determine that it is present.
For properties there is no reason why code should be executed merely in order to discover if the attribute exists or not.
Properties are allowed to raise AttributeError, so you technically have to execute it.
-- Regards, Benjamin
- 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 ]