SIGN IN SIGN UP
python / cpython UNCLAIMED

The Python programming language

72125 0 8 Python

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.
S
Sam Gross committed
7e2c9bdc989a2e10e093a18287a107aac7750091
Parent: 79c43e7
Committed by GitHub <noreply@github.com> on 2/3/2026, 6:06:32 PM