You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
No. It would return all members accessible to getattr_static (which is completely unrelated to what __dir__ may or may not return). Also calling __dir__ would mean code execution, and the point of these functions is to avoid this where possible.
Trundle commented on Apr 9, 2011
Trundlemannequin
Mannequin
More actions
A first patch, misses any documentation changes. While working on it, I realised that modules technically shadow the dict attribute (because modules use tp_dictoffset, hence module have a dict member that points to the instance dict). I updated _shadowed_dict() so that it now disregards member descriptors as shadowing (as they will never trigger any code execution), but theoretically, the members can be any object (not just dicts), so I have to think a bit more about that case (as a custom object still can trigger code execution).
Also, dir_static() behaves slightly different from dir() (e.g. dir() raises a TypeError if the module's "dict" attribute isn't a dictionary, which is kind of impossible for dir_static as it doesn't even try to acccess __dict__ if it is shadowed), but IMHO such edge-cases are expected to behave differently for a static version and hence we don't care at all about that.
Activity
voidspace commentedon Apr 5, 2011
A version of dir that returns all the members that can be seen by getattr_static.
merwok commentedon Apr 8, 2011
Would it respect __dir__?
voidspace commentedon Apr 8, 2011
No. It would return all members accessible to getattr_static (which is completely unrelated to what __dir__ may or may not return). Also calling __dir__ would mean code execution, and the point of these functions is to avoid this where possible.
Trundle commentedon Apr 9, 2011
A first patch, misses any documentation changes. While working on it, I realised that modules technically shadow the dict attribute (because modules use tp_dictoffset, hence module have a dict member that points to the instance dict). I updated
_shadowed_dict()so that it now disregards member descriptors as shadowing (as they will never trigger any code execution), but theoretically, the members can be any object (not just dicts), so I have to think a bit more about that case (as a custom object still can trigger code execution).Also,
dir_static()behaves slightly different fromdir()(e.g.dir()raises aTypeErrorif the module's "dict" attribute isn't a dictionary, which is kind of impossible fordir_staticas it doesn't even try to acccess__dict__if it is shadowed), but IMHO such edge-cases are expected to behave differently for a static version and hence we don't care at all about that.voidspace commentedon Apr 9, 2011
Thanks for the patch Andreas. On a quick read through it looks good. I'll do a proper review shortly.
Trundle commentedon Apr 9, 2011
See issue bpo-11813 for the module problem.