CPython's coroutine Implementation in C: The Generator That Awaits
A coroutine is a generator with a different flag: CO_COROUTINE picks the type, RETURN_GENERATOR hands back the frame, and am_await wraps it so you can drive it like an iterator.
All posts published on this site.
Everything published here, newest first.
A coroutine is a generator with a different flag: CO_COROUTINE picks the type, RETURN_GENERATOR hands back the frame, and am_await wraps it so you can drive it like an iterator.
A descriptor is a type with tp_descr_get (and maybe tp_descr_set). Having a setter is what makes it a data descriptor — and that single bit decides who wins an attribute lookup.
CPython’s dict is a hash table with a twist: compact and insertion-ordered since 3.6, and able to share a single keys object across thousands of instances.
There’s exactly one Ellipsis, and it’s immortal: a static struct initialized with a refcount of 3«30 so that no increment or decrement can ever bring it to zero.
enumerate, zip and reversed don’t build lists: they’re lazy C iterators that reuse one result tuple and mutate it in place, so a for loop over them allocates almost nothing.