Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8ce70d6

Browse files
Eclips4picnixzvstinner
authored
gh-122058: Lib/inspect: Update docstrings for isfunction, isgenerator, isframe, iscode. (#122059)
Co-authored-by: Bénédikt Tran <[email protected]> Co-authored-by: Victor Stinner <[email protected]>
1 parent 0b433aa commit 8ce70d6

File tree

3 files changed

+50
-10
lines changed

3 files changed

+50
-10
lines changed

Doc/library/inspect.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,19 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
153153
| | f_trace | tracing function for this |
154154
| | | frame, or ``None`` |
155155
+-----------------+-------------------+---------------------------+
156+
| | f_trace_lines | indicate whether a |
157+
| | | tracing event is |
158+
| | | triggered for each source |
159+
| | | source line |
160+
+-----------------+-------------------+---------------------------+
161+
| | f_trace_opcodes | indicate whether |
162+
| | | per-opcode events are |
163+
| | | requested |
164+
+-----------------+-------------------+---------------------------+
165+
| | clear() | used to clear all |
166+
| | | references to local |
167+
| | | variables |
168+
+-----------------+-------------------+---------------------------+
156169
| code | co_argcount | number of arguments (not |
157170
| | | including keyword only |
158171
| | | arguments, \* or \*\* |
@@ -214,6 +227,18 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
214227
| | | arguments and local |
215228
| | | variables |
216229
+-----------------+-------------------+---------------------------+
230+
| | co_lines() | returns an iterator that |
231+
| | | yields successive |
232+
| | | bytecode ranges |
233+
+-----------------+-------------------+---------------------------+
234+
| | co_positions() | returns an iterator of |
235+
| | | source code positions for |
236+
| | | each bytecode instruction |
237+
+-----------------+-------------------+---------------------------+
238+
| | replace() | returns a copy of the |
239+
| | | code object with new |
240+
| | | values |
241+
+-----------------+-------------------+---------------------------+
217242
| generator | __name__ | name |
218243
+-----------------+-------------------+---------------------------+
219244
| | __qualname__ | qualified name |

Lib/inspect.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,16 @@ def isfunction(object):
264264
Function objects provide these attributes:
265265
__doc__ documentation string
266266
__name__ name with which this function was defined
267+
__qualname__ qualified name of this function
268+
__module__ name of the module the function was defined in or None
267269
__code__ code object containing compiled function bytecode
268270
__defaults__ tuple of any default values for arguments
269271
__globals__ global namespace in which this function was defined
270272
__annotations__ dict of parameter annotations
271-
__kwdefaults__ dict of keyword only parameters with defaults"""
273+
__kwdefaults__ dict of keyword only parameters with defaults
274+
__dict__ namespace which is supporting arbitrary function attributes
275+
__closure__ a tuple of cells or None
276+
__type_params__ tuple of type parameters"""
272277
return isinstance(object, types.FunctionType)
273278

274279
def _has_code_flag(f, flag):
@@ -333,17 +338,18 @@ def isgenerator(object):
333338
"""Return true if the object is a generator.
334339
335340
Generator objects provide these attributes:
336-
__iter__ defined to support iteration over container
337-
close raises a new GeneratorExit exception inside the
338-
generator to terminate the iteration
339341
gi_code code object
340342
gi_frame frame object or possibly None once the generator has
341343
been exhausted
342344
gi_running set to 1 when generator is executing, 0 otherwise
343-
next return the next item from the container
344-
send resumes the generator and "sends" a value that becomes
345+
gi_yieldfrom object being iterated by yield from or None
346+
347+
__iter__() defined to support iteration over container
348+
close() raises a new GeneratorExit exception inside the
349+
generator to terminate the iteration
350+
send() resumes the generator and "sends" a value that becomes
345351
the result of the current yield-expression
346-
throw used to raise an exception inside the generator"""
352+
throw() used to raise an exception inside the generator"""
347353
return isinstance(object, types.GeneratorType)
348354

349355
def iscoroutine(object):
@@ -378,7 +384,11 @@ def isframe(object):
378384
f_lasti index of last attempted instruction in bytecode
379385
f_lineno current line number in Python source code
380386
f_locals local namespace seen by this frame
381-
f_trace tracing function for this frame, or None"""
387+
f_trace tracing function for this frame, or None
388+
f_trace_lines is a tracing event triggered for each source line?
389+
f_trace_opcodes are per-opcode events being requested?
390+
391+
clear() used to clear all references to local variables"""
382392
return isinstance(object, types.FrameType)
383393

384394
def iscode(object):
@@ -403,7 +413,12 @@ def iscode(object):
403413
co_names tuple of names other than arguments and function locals
404414
co_nlocals number of local variables
405415
co_stacksize virtual machine stack space required
406-
co_varnames tuple of names of arguments and local variables"""
416+
co_varnames tuple of names of arguments and local variables
417+
co_qualname fully qualified function name
418+
419+
co_lines() returns an iterator that yields successive bytecode ranges
420+
co_positions() returns an iterator of source code positions for each bytecode instruction
421+
replace() returns a copy of the code object with a new values"""
407422
return isinstance(object, types.CodeType)
408423

409424
def isbuiltin(object):

Objects/frameobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1721,7 +1721,7 @@ frame_clear(PyFrameObject *f, PyObject *Py_UNUSED(ignored))
17211721
}
17221722

17231723
PyDoc_STRVAR(clear__doc__,
1724-
"F.clear(): clear most references held by the frame");
1724+
"F.clear(): clear all references held by the frame");
17251725

17261726
static PyObject *
17271727
frame_sizeof(PyFrameObject *f, PyObject *Py_UNUSED(ignored))

0 commit comments

Comments
 (0)