From 8b732815efdbdb2b74acb573a351954579ab5aa1 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Thu, 9 Dec 2021 17:17:16 +0530 Subject: [PATCH 1/3] bpo-27062: add `__all__` to inspect module --- Lib/inspect.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Lib/inspect.py b/Lib/inspect.py index 1eb2f2b575ef454..ed596b4d4c8ed68 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -32,7 +32,18 @@ __author__ = ('Ka-Ping Yee ', 'Yury Selivanov ') - +__all__ = ['get_annotations', 'ismodule', 'isclass', 'ismethod', 'ismethoddescriptor', + 'isdatadescriptor', 'ismemberdescriptor', 'isgetsetdescriptor', 'isfunction', + 'isgeneratorfunction', 'iscoroutinefunction', 'isasyncgenfunction', 'isasyncgen', + 'isgenerator', 'iscoroutine', 'isawaitable', 'istraceback', 'isframe', 'iscode', + 'isbuiltin', 'isroutine', 'isabstract', 'getmembers', 'getmembers_static', + 'classify_class_attrs', 'getmro', 'unwrap', 'indentsize', 'getdoc', 'cleandoc', + 'getfile', 'getmodulename', 'getsourcefile', 'getabsfile', 'getmodule', 'findsource', + 'getcomments', 'getblock', 'getsourcelines', 'getsource', 'walktree', 'getclasstree', + 'getargs', 'getfullargspec', 'getargvalues', 'formatannotation', 'formatannotationrelativeto', + 'formatargvalues', 'getcallargs', 'getclosurevars', 'getframeinfo', 'getlineno', 'getouterframes', + 'getinnerframes', 'currentframe', 'stack', 'trace', 'getattr_static', 'getgeneratorstate', + 'getgeneratorlocals', 'getcoroutinestate', 'getcoroutinelocals', 'signature'] import abc import ast import dis From d76c04b418279b37d438d8cce5cc14171b4473b1 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Thu, 9 Dec 2021 11:50:33 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lib/inspect.py | 26 ++++++++++--------- .../2021-12-09-11-50-32.bpo-27062.R5vii6.rst | 1 + 2 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2021-12-09-11-50-32.bpo-27062.R5vii6.rst diff --git a/Lib/inspect.py b/Lib/inspect.py index ed596b4d4c8ed68..e3175872eb230be 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -32,18 +32,20 @@ __author__ = ('Ka-Ping Yee ', 'Yury Selivanov ') -__all__ = ['get_annotations', 'ismodule', 'isclass', 'ismethod', 'ismethoddescriptor', - 'isdatadescriptor', 'ismemberdescriptor', 'isgetsetdescriptor', 'isfunction', - 'isgeneratorfunction', 'iscoroutinefunction', 'isasyncgenfunction', 'isasyncgen', - 'isgenerator', 'iscoroutine', 'isawaitable', 'istraceback', 'isframe', 'iscode', - 'isbuiltin', 'isroutine', 'isabstract', 'getmembers', 'getmembers_static', - 'classify_class_attrs', 'getmro', 'unwrap', 'indentsize', 'getdoc', 'cleandoc', - 'getfile', 'getmodulename', 'getsourcefile', 'getabsfile', 'getmodule', 'findsource', - 'getcomments', 'getblock', 'getsourcelines', 'getsource', 'walktree', 'getclasstree', - 'getargs', 'getfullargspec', 'getargvalues', 'formatannotation', 'formatannotationrelativeto', - 'formatargvalues', 'getcallargs', 'getclosurevars', 'getframeinfo', 'getlineno', 'getouterframes', - 'getinnerframes', 'currentframe', 'stack', 'trace', 'getattr_static', 'getgeneratorstate', - 'getgeneratorlocals', 'getcoroutinestate', 'getcoroutinelocals', 'signature'] +__all__ = ['classify_class_attrs', 'cleandoc', 'currentframe', 'findsource', + 'formatannotation', 'formatannotationrelativeto', 'formatargvalues', + 'get_annotations', 'getabsfile', 'getargs', 'getargvalues', 'getattr_static', + 'getblock', 'getcallargs', 'getclasstree', 'getclosurevars', 'getcomments', + 'getcoroutinelocals', 'getcoroutinestate', 'getdoc', 'getfile', 'getframeinfo', + 'getfullargspec', 'getgeneratorlocals', 'getgeneratorstate', 'getinnerframes', + 'getlineno', 'getmembers', 'getmembers_static', 'getmodule', 'getmodulename', + 'getmro', 'getouterframes', 'getsource', 'getsourcefile', 'getsourcelines', + 'indentsize', 'isabstract', 'isasyncgen', 'isasyncgenfunction', 'isawaitable', + 'isbuiltin', 'isclass', 'iscode', 'iscoroutine', 'iscoroutinefunction', 'isdatadescriptor', + 'isframe', 'isfunction', 'isgenerator', 'isgeneratorfunction', 'isgetsetdescriptor', + 'ismemberdescriptor', 'ismethod', 'ismethoddescriptor', 'ismodule', 'isroutine', + 'istraceback', 'signature', 'stack', 'trace', 'unwrap', 'walktree'] + import abc import ast import dis diff --git a/Misc/NEWS.d/next/Library/2021-12-09-11-50-32.bpo-27062.R5vii6.rst b/Misc/NEWS.d/next/Library/2021-12-09-11-50-32.bpo-27062.R5vii6.rst new file mode 100644 index 000000000000000..3ca22b69d456fb3 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-12-09-11-50-32.bpo-27062.R5vii6.rst @@ -0,0 +1 @@ +Add :attr:`__all__` to :mod:`inspect`, patch by Kumar Aditya. \ No newline at end of file From a0d5961c16a51c91f919fef62f0b0249b16fd487 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Thu, 9 Dec 2021 18:23:17 +0530 Subject: [PATCH 3/3] code review --- Lib/inspect.py | 112 ++++++++++++++++++++++++++++++++++----- Lib/test/test_inspect.py | 3 ++ 2 files changed, 102 insertions(+), 13 deletions(-) diff --git a/Lib/inspect.py b/Lib/inspect.py index e3175872eb230be..746f6e4f9f9f06e 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -32,19 +32,105 @@ __author__ = ('Ka-Ping Yee ', 'Yury Selivanov ') -__all__ = ['classify_class_attrs', 'cleandoc', 'currentframe', 'findsource', - 'formatannotation', 'formatannotationrelativeto', 'formatargvalues', - 'get_annotations', 'getabsfile', 'getargs', 'getargvalues', 'getattr_static', - 'getblock', 'getcallargs', 'getclasstree', 'getclosurevars', 'getcomments', - 'getcoroutinelocals', 'getcoroutinestate', 'getdoc', 'getfile', 'getframeinfo', - 'getfullargspec', 'getgeneratorlocals', 'getgeneratorstate', 'getinnerframes', - 'getlineno', 'getmembers', 'getmembers_static', 'getmodule', 'getmodulename', - 'getmro', 'getouterframes', 'getsource', 'getsourcefile', 'getsourcelines', - 'indentsize', 'isabstract', 'isasyncgen', 'isasyncgenfunction', 'isawaitable', - 'isbuiltin', 'isclass', 'iscode', 'iscoroutine', 'iscoroutinefunction', 'isdatadescriptor', - 'isframe', 'isfunction', 'isgenerator', 'isgeneratorfunction', 'isgetsetdescriptor', - 'ismemberdescriptor', 'ismethod', 'ismethoddescriptor', 'ismodule', 'isroutine', - 'istraceback', 'signature', 'stack', 'trace', 'unwrap', 'walktree'] + +__all__ = [ + "ArgInfo", + "Arguments", + "Attribute", + "BlockFinder", + "BoundArguments", + "CORO_CLOSED", + "CORO_CREATED", + "CORO_RUNNING", + "CORO_SUSPENDED", + "CO_ASYNC_GENERATOR", + "CO_COROUTINE", + "CO_GENERATOR", + "CO_ITERABLE_COROUTINE", + "CO_NESTED", + "CO_NEWLOCALS", + "CO_NOFREE", + "CO_OPTIMIZED", + "CO_VARARGS", + "CO_VARKEYWORDS", + "ClassFoundException", + "ClosureVars", + "EndOfBlock", + "FrameInfo", + "FullArgSpec", + "GEN_CLOSED", + "GEN_CREATED", + "GEN_RUNNING", + "GEN_SUSPENDED", + "Parameter", + "Signature", + "TPFLAGS_IS_ABSTRACT", + "Traceback", + "classify_class_attrs", + "cleandoc", + "currentframe", + "findsource", + "formatannotation", + "formatannotationrelativeto", + "formatargvalues", + "get_annotations", + "getabsfile", + "getargs", + "getargvalues", + "getattr_static", + "getblock", + "getcallargs", + "getclasstree", + "getclosurevars", + "getcomments", + "getcoroutinelocals", + "getcoroutinestate", + "getdoc", + "getfile", + "getframeinfo", + "getfullargspec", + "getgeneratorlocals", + "getgeneratorstate", + "getinnerframes", + "getlineno", + "getmembers", + "getmembers_static", + "getmodule", + "getmodulename", + "getmro", + "getouterframes", + "getsource", + "getsourcefile", + "getsourcelines", + "indentsize", + "isabstract", + "isasyncgen", + "isasyncgenfunction", + "isawaitable", + "isbuiltin", + "isclass", + "iscode", + "iscoroutine", + "iscoroutinefunction", + "isdatadescriptor", + "isframe", + "isfunction", + "isgenerator", + "isgeneratorfunction", + "isgetsetdescriptor", + "ismemberdescriptor", + "ismethod", + "ismethoddescriptor", + "ismodule", + "isroutine", + "istraceback", + "signature", + "stack", + "trace", + "unwrap", + "walktree", +] + import abc import ast diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 33665cf3c79ebf5..c25256dfa26fdd1 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -107,6 +107,9 @@ def istest(self, predicate, exp): continue self.assertFalse(other(obj), 'not %s(%s)' % (other.__name__, exp)) + def test__all__(self): + support.check__all__(self, inspect, not_exported=("k", "v", "mod_dict", "modulesbyfile")) + def generator_function_example(self): for i in range(2): yield i