Skip to content

gh-122058: Lib/inspect: Update docstrings for isfunction, isgenerator, isframe, iscode. #122059

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Doc/library/inspect.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 \*\* |
Expand Down Expand Up @@ -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 |
Expand Down
22 changes: 18 additions & 4 deletions Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,16 @@ 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
__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
__type_params__ tuple of type parameters"""
return isinstance(object, types.FunctionType)

def _has_code_flag(f, flag):
Expand Down Expand Up @@ -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 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"""
Expand Down Expand Up @@ -492,7 +497,11 @@ 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?

clear used to clear all references to local variables"""
return isinstance(object, types.FrameType)

def iscode(object):
Expand All @@ -517,7 +526,12 @@ def iscode(object):
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

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):
Expand Down
Loading