From 380347c1c9ac4d7bb341df4c75388da31350b276 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Sat, 20 Jul 2024 13:25:33 +0000 Subject: [PATCH 01/11] Update docstrings --- Lib/inspect.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Lib/inspect.py b/Lib/inspect.py index 0e7b40eb39bce8..c9391e3511a65c 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -382,7 +382,12 @@ def isfunction(object): __defaults__ tuple of any default values for arguments __globals__ global namespace in which this function was defined __annotations__ dict of parameter annotations - __kwdefaults__ dict of keyword only parameters with defaults""" + __kwdefaults__ dict of keyword only parameters with defaults + __dict__ namespace which is supporting arbitrary function attributes + __closure__ None or tuple of cells + __qualname__ fully qualified name of this function + __module__ name of the module the function was defined in or None + __type_params__ tuple of type parameters""" return isinstance(object, types.FunctionType) def _has_code_flag(f, flag): @@ -454,7 +459,7 @@ def isgenerator(object): gi_frame frame object or possibly None once the generator has been exhausted gi_running set to 1 when generator is executing, 0 otherwise - next return the next item from the container + gi_yieldfrom is object being iterater by yield from? send resumes the generator and "sends" a value that becomes the result of the current yield-expression throw used to raise an exception inside the generator""" @@ -485,6 +490,7 @@ def isframe(object): """Return true if the object is a frame object. Frame objects provide these attributes: + clear used to clear all references to local variables f_back next outer frame object (this frame's caller) f_builtins built-in namespace seen by this frame f_code code object being executed in this frame @@ -492,7 +498,9 @@ def isframe(object): f_lasti index of last attempted instruction in bytecode f_lineno current line number in Python source code f_locals local namespace seen by this frame - f_trace tracing function for this frame, or None""" + f_trace tracing function for this frame, or None + f_trace_lines is a tracing event triggered for each source line? + f_trace_opcodes are per-opcode events being requested?""" return isinstance(object, types.FrameType) def iscode(object): @@ -511,13 +519,17 @@ def iscode(object): | 256=iterable_coroutine | 512=async_generator co_freevars tuple of names of free variables co_posonlyargcount number of positional only arguments + co_positions returns an iterator of source code positions for each bytecode instruction co_kwonlyargcount number of keyword only arguments (not including ** arg) co_lnotab encoded mapping of line numbers to bytecode indices + co_lines returns an iterator that yields successive bytecode ranges co_name name with which this code object was defined co_names tuple of names other than arguments and function locals co_nlocals number of local variables co_stacksize virtual machine stack space required - co_varnames tuple of names of arguments and local variables""" + co_varnames tuple of names of arguments and local variables + co_qualname fully qualified function name + replace return a copy of the code object with new new values""" return isinstance(object, types.CodeType) def isbuiltin(object): From 7c66f2182c20d103476c9c556c91613ed2a3d78c Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Sat, 20 Jul 2024 13:32:27 +0000 Subject: [PATCH 02/11] Fix trailing whitespace --- Lib/inspect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/inspect.py b/Lib/inspect.py index c9391e3511a65c..2c2a584972eb01 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -519,7 +519,7 @@ def iscode(object): | 256=iterable_coroutine | 512=async_generator co_freevars tuple of names of free variables co_posonlyargcount number of positional only arguments - co_positions returns an iterator of source code positions for each bytecode instruction + co_positions returns an iterator of source code positions for each bytecode instruction co_kwonlyargcount number of keyword only arguments (not including ** arg) co_lnotab encoded mapping of line numbers to bytecode indices co_lines returns an iterator that yields successive bytecode ranges From 6113f1727bf37da62f42e6e7a1eaa624395f7ecd Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Mon, 22 Jul 2024 08:28:23 +0300 Subject: [PATCH 03/11] Address review --- Doc/library/inspect.rst | 22 ++++++++++++++++++++++ Lib/inspect.py | 18 ++++++++++-------- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst index 7838eeed2843c4..bb7fbcce3c78ed 100644 --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -153,6 +153,17 @@ attributes (see :ref:`import-mod-attrs` for module attributes): | | f_trace | tracing function for this | | | | frame, or ``None`` | +-----------------+-------------------+---------------------------+ +| | f_trace_lines | is a tracing event | +| | | triggered for each source | +| | | line? | ++-----------------+-------------------+---------------------------+ +| | f_trace_opcodes | are per-opcode events | +| | | being requested? | ++-----------------+-------------------+---------------------------+ +| | clear | used to clear all | +| | | references to local | +| | | variables | ++-----------------+-------------------+---------------------------+ | code | co_argcount | number of arguments (not | | | | including keyword only | | | | arguments, \* or \*\* | @@ -214,6 +225,17 @@ attributes (see :ref:`import-mod-attrs` for module attributes): | | | arguments and local | | | | variables | +-----------------+-------------------+---------------------------+ +| | co_lines | returns an iterator that | +| | | yields successive | +| | | bytecode ranges | ++-----------------+-------------------+---------------------------+ +| | co_positions | returns an iterator of | +| | | source code positions for | +| | | each bytecode instruction | ++-----------------+-------------------+---------------------------+ +| | replace | return a copy of the code | +| | | object with a new values | ++-----------------+-------------------+---------------------------+ | generator | __name__ | name | +-----------------+-------------------+---------------------------+ | | __qualname__ | qualified name | diff --git a/Lib/inspect.py b/Lib/inspect.py index 2c2a584972eb01..4cd337718e196c 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -378,6 +378,8 @@ def isfunction(object): Function objects provide these attributes: __doc__ documentation string __name__ name with which this function was defined + __qualname__ fully qualified name of this function + __module__ name of the module the function was defined in or None __code__ code object containing compiled function bytecode __defaults__ tuple of any default values for arguments __globals__ global namespace in which this function was defined @@ -385,8 +387,6 @@ def isfunction(object): __kwdefaults__ dict of keyword only parameters with defaults __dict__ namespace which is supporting arbitrary function attributes __closure__ None or tuple of cells - __qualname__ fully qualified name of this function - __module__ name of the module the function was defined in or None __type_params__ tuple of type parameters""" return isinstance(object, types.FunctionType) @@ -459,7 +459,7 @@ def isgenerator(object): gi_frame frame object or possibly None once the generator has been exhausted gi_running set to 1 when generator is executing, 0 otherwise - gi_yieldfrom is object being iterater by yield from? + gi_yieldfrom object being iterated by yield from or None send resumes the generator and "sends" a value that becomes the result of the current yield-expression throw used to raise an exception inside the generator""" @@ -490,7 +490,6 @@ def isframe(object): """Return true if the object is a frame object. Frame objects provide these attributes: - clear used to clear all references to local variables f_back next outer frame object (this frame's caller) f_builtins built-in namespace seen by this frame f_code code object being executed in this frame @@ -500,7 +499,9 @@ def isframe(object): f_locals local namespace seen by this frame f_trace tracing function for this frame, or None f_trace_lines is a tracing event triggered for each source line? - f_trace_opcodes are per-opcode events being requested?""" + f_trace_opcodes are per-opcode events being requested? + + clear used to clear all references to local variables""" return isinstance(object, types.FrameType) def iscode(object): @@ -519,17 +520,18 @@ def iscode(object): | 256=iterable_coroutine | 512=async_generator co_freevars tuple of names of free variables co_posonlyargcount number of positional only arguments - co_positions returns an iterator of source code positions for each bytecode instruction co_kwonlyargcount number of keyword only arguments (not including ** arg) co_lnotab encoded mapping of line numbers to bytecode indices - co_lines returns an iterator that yields successive bytecode ranges co_name name with which this code object was defined co_names tuple of names other than arguments and function locals co_nlocals number of local variables co_stacksize virtual machine stack space required co_varnames tuple of names of arguments and local variables co_qualname fully qualified function name - replace return a copy of the code object with new new values""" + + co_lines returns an iterator that yields successive bytecode ranges + co_positions returns an iterator of source code positions for each bytecode instruction + replace return a copy of the code object with a new values""" return isinstance(object, types.CodeType) def isbuiltin(object): From 506da65c840f46aa41be70cab751418a359a2359 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Sat, 27 Jul 2024 11:40:26 +0300 Subject: [PATCH 04/11] Update Lib/inspect.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Lib/inspect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/inspect.py b/Lib/inspect.py index 4cd337718e196c..d933500bac7fb5 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -531,7 +531,7 @@ def iscode(object): co_lines returns an iterator that yields successive bytecode ranges co_positions returns an iterator of source code positions for each bytecode instruction - replace return a copy of the code object with a new values""" + replace returns a copy of the code object with a new values""" return isinstance(object, types.CodeType) def isbuiltin(object): From c5966f681bfe2f4a22eed18fc030ecae9d11b5a0 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Sat, 27 Jul 2024 11:40:40 +0300 Subject: [PATCH 05/11] Update Lib/inspect.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Lib/inspect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/inspect.py b/Lib/inspect.py index d933500bac7fb5..8a8550b0699634 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -386,7 +386,7 @@ def isfunction(object): __annotations__ dict of parameter annotations __kwdefaults__ dict of keyword only parameters with defaults __dict__ namespace which is supporting arbitrary function attributes - __closure__ None or tuple of cells + __closure__ a tuple of cells or None __type_params__ tuple of type parameters""" return isinstance(object, types.FunctionType) From d6b34397f826835f8165b960225e80beafe7389e Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Sat, 27 Jul 2024 11:47:18 +0300 Subject: [PATCH 06/11] Address review --- Doc/library/inspect.rst | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst index bb7fbcce3c78ed..76c7f8d235cca5 100644 --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -153,12 +153,14 @@ attributes (see :ref:`import-mod-attrs` for module attributes): | | f_trace | tracing function for this | | | | frame, or ``None`` | +-----------------+-------------------+---------------------------+ -| | f_trace_lines | is a tracing event | +| | f_trace_lines | indicate whether a | +| | | tracing event is | | | | triggered for each source | -| | | line? | +| | | source line | +-----------------+-------------------+---------------------------+ -| | f_trace_opcodes | are per-opcode events | -| | | being requested? | +| | f_trace_opcodes | indicate whether | +| | | per-opcode events are | +| | | requested | +-----------------+-------------------+---------------------------+ | | clear | used to clear all | | | | references to local | @@ -233,8 +235,9 @@ attributes (see :ref:`import-mod-attrs` for module attributes): | | | source code positions for | | | | each bytecode instruction | +-----------------+-------------------+---------------------------+ -| | replace | return a copy of the code | -| | | object with a new values | +| | replace | returns a copy of the | +| | | code object with a new | +| | | values | +-----------------+-------------------+---------------------------+ | generator | __name__ | name | +-----------------+-------------------+---------------------------+ From 08e4b6b566d9057b2335954e5f7f2c3a1c67f0c1 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Sat, 27 Jul 2024 11:50:06 +0300 Subject: [PATCH 07/11] Fix linting issue --- Doc/library/inspect.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst index 76c7f8d235cca5..0f39026f1d1187 100644 --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -237,7 +237,7 @@ attributes (see :ref:`import-mod-attrs` for module attributes): +-----------------+-------------------+---------------------------+ | | replace | returns a copy of the | | | | code object with a new | -| | | values | +| | | values | +-----------------+-------------------+---------------------------+ | generator | __name__ | name | +-----------------+-------------------+---------------------------+ From f5be7f48f41f891559129bbe7245e38f276d1294 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Sat, 27 Jul 2024 23:49:03 +0300 Subject: [PATCH 08/11] Update Lib/inspect.py Co-authored-by: Victor Stinner --- Lib/inspect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/inspect.py b/Lib/inspect.py index 8a8550b0699634..ee3dd212572309 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -378,7 +378,7 @@ def isfunction(object): Function objects provide these attributes: __doc__ documentation string __name__ name with which this function was defined - __qualname__ fully qualified name of this function + __qualname__ qualified name of this function __module__ name of the module the function was defined in or None __code__ code object containing compiled function bytecode __defaults__ tuple of any default values for arguments From 0d7fb34dd3ac54bbb10721e887b3c44a13878afa Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Sat, 27 Jul 2024 20:52:05 +0000 Subject: [PATCH 09/11] Fix frame.clear docstring --- Objects/frameobject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Objects/frameobject.c b/Objects/frameobject.c index 88093eb9071ae4..895bd371e8ef11 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -1701,7 +1701,7 @@ frame_clear(PyFrameObject *f, PyObject *Py_UNUSED(ignored)) } PyDoc_STRVAR(clear__doc__, -"F.clear(): clear most references held by the frame"); +"F.clear(): clear all references held by the frame"); static PyObject * frame_sizeof(PyFrameObject *f, PyObject *Py_UNUSED(ignored)) From c413656c7beabafff9f2d3ed83fc498ec5075117 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Sat, 27 Jul 2024 20:57:21 +0000 Subject: [PATCH 10/11] Address Victor's review --- Doc/library/inspect.rst | 10 +++++----- Lib/inspect.py | 19 ++++++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst index 0f39026f1d1187..9276ad16474a75 100644 --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -162,7 +162,7 @@ attributes (see :ref:`import-mod-attrs` for module attributes): | | | per-opcode events are | | | | requested | +-----------------+-------------------+---------------------------+ -| | clear | used to clear all | +| | clear() | used to clear all | | | | references to local | | | | variables | +-----------------+-------------------+---------------------------+ @@ -227,16 +227,16 @@ attributes (see :ref:`import-mod-attrs` for module attributes): | | | arguments and local | | | | variables | +-----------------+-------------------+---------------------------+ -| | co_lines | returns an iterator that | +| | co_lines() | returns an iterator that | | | | yields successive | | | | bytecode ranges | +-----------------+-------------------+---------------------------+ -| | co_positions | returns an iterator of | +| | co_positions() | returns an iterator of | | | | source code positions for | | | | each bytecode instruction | +-----------------+-------------------+---------------------------+ -| | replace | returns a copy of the | -| | | code object with a new | +| | replace() | returns a copy of the | +| | | code object with new | | | | values | +-----------------+-------------------+---------------------------+ | generator | __name__ | name | diff --git a/Lib/inspect.py b/Lib/inspect.py index ee3dd212572309..70c9cef9f1d917 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -452,17 +452,18 @@ def isgenerator(object): """Return true if the object is a generator. Generator objects provide these attributes: - __iter__ defined to support iteration over container - close raises a new GeneratorExit exception inside the - generator to terminate the iteration gi_code code object gi_frame frame object or possibly None once the generator has been exhausted gi_running set to 1 when generator is executing, 0 otherwise gi_yieldfrom object being iterated by yield from or None - send resumes the generator and "sends" a value that becomes + + __iter__() defined to support iteration over container + close() raises a new GeneratorExit exception inside the + generator to terminate the iteration + send() resumes the generator and "sends" a value that becomes the result of the current yield-expression - throw used to raise an exception inside the generator""" + throw() used to raise an exception inside the generator""" return isinstance(object, types.GeneratorType) def iscoroutine(object): @@ -501,7 +502,7 @@ def isframe(object): f_trace_lines is a tracing event triggered for each source line? f_trace_opcodes are per-opcode events being requested? - clear used to clear all references to local variables""" + clear() used to clear all references to local variables""" return isinstance(object, types.FrameType) def iscode(object): @@ -529,9 +530,9 @@ def iscode(object): co_varnames tuple of names of arguments and local variables co_qualname fully qualified function name - co_lines returns an iterator that yields successive bytecode ranges - co_positions returns an iterator of source code positions for each bytecode instruction - replace returns a copy of the code object with a new values""" + co_lines() returns an iterator that yields successive bytecode ranges + co_positions() returns an iterator of source code positions for each bytecode instruction + replace() returns a copy of the code object with a new values""" return isinstance(object, types.CodeType) def isbuiltin(object): From 54f35622445a989cd0d867d7f8eff12684fe7bb0 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Sat, 27 Jul 2024 21:01:10 +0000 Subject: [PATCH 11/11] Fix linting issues --- Lib/inspect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/inspect.py b/Lib/inspect.py index 70c9cef9f1d917..6848a8e45cf14e 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -457,7 +457,7 @@ def isgenerator(object): been exhausted gi_running set to 1 when generator is executing, 0 otherwise gi_yieldfrom object being iterated by yield from or None - + __iter__() defined to support iteration over container close() raises a new GeneratorExit exception inside the generator to terminate the iteration