10.2 Changes in the C API 10.3 CPython bytecode changes 18 (Contributed by Mark Shannon in bpo-39156.) – JUMP_IF_NOT_EXC_MATCH for checking exceptions in ‘try-except’ statements. – CONTAINS_OP for ‘in’ and ‘not in’ tests – IS_OP for ‘is’ and ‘is not’ tests – COMPARE_OP for rich comparisons • The$_{COMPARE_OP}$ opcode was split into four distinct instructions: • The LOAD_ASSERTION_ERROR opcode was added for handling the $_{assert}$statement. Previously, the assert statement would not work correctly if the$_{AssertionError}$ exception was being shadowed. (Con- tributed by Zackery Spytz in bpo-34880.) • The functions PyEval_CallObject , PyEval_CallFunction , PyEval_CallMethod and PyEval_CallObjectWithKeywords are deprecated. Use$_{PyObject_Call()}$ and its variants in- stead. (See more details in bpo-29548.) (See bpo-35810 and bpo-40217 for more information.) #if PY_VERSION_HEX >= 0x03090000 // This was not needed before Python 3.9 (Python issue 35810 ␣ ↪ → 40217) if (base->tp_flags&Py_TPFLAGS_HEAPTYPE) { // a heap type's tp_traverse already visited Py_TYPE(self) } else { Py_VISIT(Py_TYPE(self)); } #else then add: For example, if your$_{tp_traverse}$ function includes: base->tp_traverse(self, visit, arg) If your traverse function delegates to tp_traverse of its base class (or another type), ensure that Py_TYPE(self) is visited only once. Note that only heap types are expected to visit the type in tp_traverse . int foo_traverse (foo_struct *self, visitproc visit, void *arg) { // Rest of the traverse function #if PY_VERSION_HEX >= 0x03090000 // This was not needed before Python 3.9 (Python issue 35810 ␣ ↪ → 40217) Py_VISIT(Py_TYPE(self)); #endif } Example: • Instances of heap-allocated types (such as those created with$_{PyType_FromSpec()}$ and similar APIs) hold a reference to their type object since Python 3.8. As indicated in the “Changes in the C API” of Python 3.8, for the vast majority of cases, there should be no side effect but for types that have a custom tp_traverse function, ensure that all custom tp_traverse functions of heap-allocated types visit the object’s type.