I landed bpo-31338 / PR #3374 which adds a Py_UNREACHABLE() macro to master, along with some additional documentation in the C API describing this and a few other common macros. If you’re writing or reviewing C changes that include unreachable code paths, please use this macro for consistency, instead of other approaches like assert() (which can be compiled out) and
return NULL, etc.
As part of the PR, I changed a bunch of existing instances in the code:
If you find any cases I’ve missed, feel free to submit a PR and I will happily review it. I think this makes our code more consistent and ultimately safer.
(Thanks Victor for the PR review!)