Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue18626

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title:Make "python -m inspect" meaningful
Type:enhancementStage:resolved
Components:Library (Lib)Versions:Python 3.4
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To:Nosy List: Claudiu.Popa, eric.snow, ezio.melotti, ncoghlan, python-dev, serhiy.storchaka
Priority:normalKeywords:patch

Created on2013-08-02 03:12 byncoghlan, last changed2022-04-11 14:57 byadmin. This issue is nowclosed.

Files
File nameUploadedDescriptionEdit
inspect.patchClaudiu.Popa,2013-09-16 17:06review
Messages (7)
msg194148 -(view)Author: Alyssa Coghlan (ncoghlan)*(Python committer)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)*(Python committer)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)*(Python committer)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)*(Python committer)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)*(Python triager)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)(Python triager)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)*(Python committer)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
DateUserActionArgs
2022-04-11 14:57:48adminsetgithub: 62826
2013-09-22 12:49:39ncoghlansetmessages: +msg198273
2013-09-22 12:47:02python-devsetstatus: open -> closed

nosy: +python-dev
messages: +msg198272

resolution: fixed
stage: needs patch -> resolved
2013-09-16 17:06:22Claudiu.Popasetfiles: +inspect.patch

nosy: +Claudiu.Popa
messages: +msg197919

keywords: +patch
2013-08-17 14:53:53ncoghlansetmessages: +msg195478
title: Make "python -m inspect <name>" dump the source of a module -> Make "python -m inspect <name>" meaningful
2013-08-08 17:30:52serhiy.storchakasetnosy: +serhiy.storchaka
messages: +msg194699
2013-08-08 16:44:14ezio.melottisetnosy: +ezio.melotti
2013-08-02 04:53:11eric.snowsetnosy: +eric.snow
messages: +msg194153
2013-08-02 03:12:40ncoghlancreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp