]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-120321: Add gi_state, cr_state, and ag_state attributes (gh-144409)
authorSam Gross <colesbury@gmail.com>
Tue, 3 Feb 2026 18:06:32 +0000 (13:06 -0500)
committerGitHub <noreply@github.com>
Tue, 3 Feb 2026 18:06:32 +0000 (13:06 -0500)
commit7e2c9bdc989a2e10e093a18287a107aac7750091
tree8a76ca13b0ef7306dab8a7cbf3d52a52aa78ca45
parent79c43e7c249e61d959550c20f798a88c8829a8a8
gh-120321: Add gi_state, cr_state, and ag_state attributes (gh-144409)

Add `gi_state`, `cr_state`, and `ag_state` attributes to generators,
coroutines, and async generators respectively. These attributes return the
current state as a string (e.g., `GEN_RUNNING`, `CORO_SUSPENDED`).

The `inspect.getgeneratorstate()`, `inspect.getcoroutinestate()`, and
`inspect.getasyncgenstate()` functions now return these attributes directly.

This is in preparation for making `gi_frame` thread-safe, which may involve
stop-the-world synchronization. The new state attributes avoid potential
performance cliffs in `inspect.getgeneratorstate()` and similar functions by
not requiring frame access.

Also removes unused `FRAME_COMPLETED` state and renumbers the frame state enum
to start at 0 instead of -1.
12 files changed:
Doc/library/inspect.rst
Include/internal/pycore_frame.h
Include/internal/pycore_global_objects_fini_generated.h
Include/internal/pycore_global_strings.h
Include/internal/pycore_runtime_init_generated.h
Include/internal/pycore_unicodeobject_generated.h
Lib/inspect.py
Lib/test/test_generators.py
Lib/types.py
Misc/NEWS.d/next/Core_and_Builtins/2026-02-02-17-50-14.gh-issue-120321.Xfr7tL.rst [new file with mode: 0644]
Objects/genobject.c
Tools/c-analyzer/cpython/ignored.tsv