On 23/08/2010 22:59, Benjamin Peterson wrote:
IMO, this is a much better solution, more in line with known use cases for hasattr(). If the proposed change when through, it would fail to address the common use case and cause people to start writing their own versions of hasattr() that just scan but do not run code.
Can you provide an example? I've never seen code which explicitly scans MRO and dicts to avoid triggering code. (Besides collections.Callable; that's a special case.)
The example I linked to in my previous email did exactly that - the use case was for finding and displaying docstrings on members in an interactive object viewer. We needed to be able to examine objects without triggering code execution in them.
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.