-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make "python -m inspect <name>" meaningful #62826
Comments
"python -m inspect <name>" doesn't currently do anything. It would be handy if this:
Was roughly equivalent to:
Even better would be if it understood entry point notation so you could use "modname:qualname" to get the source code of a particular item within a module. |
At the risk of unnecessary complication, there is also other information that could be output, depending on the referenced object (module vs. class/func via qualname). For instance, a module's __file__ would be handy. So, the output could have a "header" with the relevant info, followed by a blank line, and then the source code. I suppose something like that could be added later with a commandline option, like "python -m inspect --info site", rather than being default behavior. Then this issue can stay focused on the simpler idea. :) Regardless, your proposal sounds good to me. I don't see any other meaningful use for "-m inspect". |
I agree that it will be better to output a formalized report about a module and it's contents using inspect.getmoduleinfo() and inspect.getmembers(). |
I realised that with the "module:qualname" syntax, it's straightforward to expand this beyond module introspection to arbitrary objects. What I suggest we could output:
|
Hello, here's a basic patch. Currently, the header info is printed by default, while the source can be retrieved by using --source (although I would prefer them to be switched, the source should be shown by default and the header info only when requested). It understands the entry point notation, like 'unittest:util.safe_repr'. |
New changeset 2e1335245f8f by Nick Coghlan in branch 'default': |
Thanks for the initial patch Claudiu - I tweaked it a bit before committing it.
|
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:
The text was updated successfully, but these errors were encountered: