msg194148 - (view) |
Author: Alyssa Coghlan (ncoghlan) *  |
Date: 2013-08-02 03:12 |
"python -m inspect " doesn't currently do anything. It would be handy if this: python -m inspect site Was roughly equivalent to: python -c "import inspect, site; print(inspect.getsource(site))" 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. |
|
|
msg194153 - (view) |
Author: Eric Snow (eric.snow) *  |
Date: 2013-08-02 04:53 |
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". |
|
|
msg194699 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2013-08-08 17:30 |
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(). |
|
|
msg195478 - (view) |
Author: Alyssa Coghlan (ncoghlan) *  |
Date: 2013-08-17 14:53 |
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: - a header with key module info (names taken from PEP 451): Origin Cached Submodule search path Loader (repr output) - for non-module objects, also include the line within the file (if it can be determined) - the output of getsource() if a "--source" option is given |
|
|
msg197919 - (view) |
Author: PCManticore (Claudiu.Popa) *  |
Date: 2013-09-16 17:06 |
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'. |
|
|
msg198272 - (view) |
Author: Roundup Robot (python-dev)  |
Date: 2013-09-22 12:47 |
New changeset 2e1335245f8f by Nick Coghlan in branch 'default': Close #18626: add a basic CLI for the inspect module http://hg.python.org/cpython/rev/2e1335245f8f |
|
|
msg198273 - (view) |
Author: Alyssa Coghlan (ncoghlan) *  |
Date: 2013-09-22 12:49 |
Thanks for the initial patch Claudiu - I tweaked it a bit before committing it. * as you suggested, displaying the source is the default, with a --details option to display the formatted info instead * changed the displayed details (e.g. only displaying the search path for packages, displaying the line number for classes and functions * a few tweaks to the actual implementation (e.g. using partition over find, avoiding tracebacks for a couple of likely user errors) |
|
|