Repository navigation
inspect.dir_static #55979
Description
Activity
A version of dir that returns all the members that can be seen by getattr_static.
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Apr 5, 2011 - addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
on Apr 5, 2011 Would it respect __dir__?
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.
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.Thanks for the patch Andreas. On a quick read through it looks good. I'll do a proper review shortly.
See issue bpo-11813 for the module problem.
- addedtype-featureA feature request or enhancementA feature request or enhancementand removedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Jul 15, 2011
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsNo status
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields: