cpython: 2e1335245f8f (original) (raw)

Mercurial > cpython

changeset 85780:2e1335245f8f

Close #18626: add a basic CLI for the inspect module [#18626]

Nick Coghlan ncoghlan@gmail.com
date Sun, 22 Sep 2013 22:46:49 +1000
parents 0c17a461f34c
children 8620aea9bbca
files Doc/library/inspect.rst Doc/whatsnew/3.4.rst Lib/inspect.py Lib/test/test_inspect.py Misc/NEWS
diffstat 5 files changed, 130 insertions(+), 3 deletions(-)[+] [-] Doc/library/inspect.rst 17 Doc/whatsnew/3.4.rst 6 Lib/inspect.py 61 Lib/test/test_inspect.py 46 Misc/NEWS 3

line wrap: on

line diff

--- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -1006,3 +1006,20 @@ updated as expected: return an empty dictionary. .. versionadded:: 3.3 + + +Command Line Interface +---------------------- + +The :mod:inspect module also provides a basic introspection capability +from the command line. + +.. program:: inspect + +By default, accepts the name of a module and prints the source of that +module. A class or function within the module can be printed instead by +appended a colon and the qualified name of the target object. + +.. cmdoption:: --details +

--- a/Doc/whatsnew/3.4.rst +++ b/Doc/whatsnew/3.4.rst @@ -264,11 +264,15 @@ New :func:functools.singledispatch dec inspect ------- + +The inspect module now offers a basic command line interface to quickly +display source code and other information for modules, classes and +functions. + :func:~inspect.unwrap makes it easy to unravel wrapper function chains created by :func:functools.wraps (and any other API that sets the __wrapped__ attribute on a wrapper function). - mmap ----

--- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -2109,3 +2109,64 @@ class Signature: rendered += ' -> {}'.format(anno) return rendered + +def _main():

+

+

+

+

+

+

+

+ + +if name == "main":

--- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -9,10 +9,11 @@ import collections import os import shutil import functools +import importlib from os.path import normcase from test.support import run_unittest, TESTFN, DirsOnSysPath - +from test.script_helper import assert_python_ok, assert_python_failure from test import inspect_fodder as mod from test import inspect_fodder2 as mod2 @@ -2372,6 +2373,47 @@ class TestUnwrap(unittest.TestCase): wrapped = func self.assertIsNone(inspect.unwrap(C())) +class TestMain(unittest.TestCase):

+

+

+

+ + + def test_main(): run_unittest( @@ -2380,7 +2422,7 @@ def test_main(): TestGetcallargsFunctions, TestGetcallargsMethods, TestGetcallargsUnboundMethods, TestGetattrStatic, TestGetGeneratorState, TestNoEOL, TestSignatureObject, TestSignatureBind, TestParameterObject,

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,9 @@ Core and Builtins Library ------- +- Issue #18626: the inspect module now offers a basic command line