
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2013-08-02 03:12 byncoghlan, last changed2022-04-11 14:57 byadmin. This issue is nowclosed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| inspect.patch | Claudiu.Popa,2013-09-16 17:06 | review | ||
| Messages (7) | |||
|---|---|---|---|
| msg194148 -(view) | Author: Alyssa Coghlan (ncoghlan)*![]() | Date: 2013-08-02 03:12 | |
"python -m inspect <name>" doesn't currently do anything.It would be handy if this: python -m inspect siteWas 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 fromPEP 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 changeset2e1335245f8f by Nick Coghlan in branch 'default':Close#18626: add a basic CLI for the inspect modulehttp://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) | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:57:48 | admin | set | github: 62826 |
| 2013-09-22 12:49:39 | ncoghlan | set | messages: +msg198273 |
| 2013-09-22 12:47:02 | python-dev | set | status: open -> closed nosy: +python-dev messages: +msg198272 resolution: fixed stage: needs patch -> resolved |
| 2013-09-16 17:06:22 | Claudiu.Popa | set | files: +inspect.patch nosy: +Claudiu.Popa messages: +msg197919 keywords: +patch |
| 2013-08-17 14:53:53 | ncoghlan | set | messages: +msg195478 title: Make "python -m inspect <name>" dump the source of a module -> Make "python -m inspect <name>" meaningful |
| 2013-08-08 17:30:52 | serhiy.storchaka | set | nosy: +serhiy.storchaka messages: +msg194699 |
| 2013-08-08 16:44:14 | ezio.melotti | set | nosy: +ezio.melotti |
| 2013-08-02 04:53:11 | eric.snow | set | nosy: +eric.snow messages: +msg194153 |
| 2013-08-02 03:12:40 | ncoghlan | create | |