Write code that favors existing project idioms and clear control flow over ad hoc constructs, duplicated logic, or unnecessary complexity:
_Py_MAX_UNICODE instead of hardcoding 0x10FFFF), and use project-specific cast macros (e.g. _PyMemoryView_CAST(v)) instead of raw C-style casts.(unsigned char)(unsigned long)x) when a single cast suffices, and don’t introduce casts/macros that only wrap a single trivial operation (“over-encapsulation”)—inline the simple expression instead.// instead of duplicated if/else blocks setting a bool key:
if (PyDict_SetItemString(dict, "immortal",
PyBool_FromLong(PyUnstable_IsImmortal(op))) < 0) {
Py_DECREF(dict);
return NULL;
}
assert(...) instead of a comment claiming a value is always true).goto for anything other than the well-established “jump to cleanup/exit before returning” pattern; if logic requires a non-final jump, prefer extracting the logic into a separate function instead. When goto is used, give labels descriptive names (format_errno) rather than generic ones like skip.do { ... } while (0) wrapping to avoid dangling-else and similar pitfalls, and preprocessor conditionals should be simplified (e.g. collapse an #if/#else into a single #if !defined(...) when one branch becomes empty).Applying these conventions keeps code consistent with the rest of the codebase, reduces redundancy, and makes control flow and ownership easier to follow during review and maintenance.</description> </invoke>