gh-122058: `Lib/inspect`: Update docstrings for `isfunction`, `isgene… · python/cpython@8ce70d6 · GitHub
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 <10796600+picnixz@users.noreply.github.com> Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent 0b433aa commit 8ce70d6

3 files changed

Lines changed: 50 additions & 10 deletions

File tree

‎Doc/library/inspect.rst‎

Lines changed: 25 additions & 0 deletions

‎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

0 commit comments

Comments
 (0)