File tree Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Original file line number Diff line number Diff line change @@ -820,15 +820,15 @@ def generate_finalize_for_class(
820820 )
821821 )
822822 emitter .emit_line ("if (PyErr_Occurred() != NULL) {" )
823- emitter .emit_line ('PyObject *class_obj = PyObject_GetAttrString(self, "__class__ ");' )
824- emitter .emit_line (' PyObject *del_method = PyObject_GetAttrString(class_obj, "__del__");' )
823+ emitter .emit_line ('PyObject *del_str = PyUnicode_FromString("__del__ ");' )
824+ emitter .emit_line (" PyObject *del_method = _PyType_Lookup(Py_TYPE(self), del_str);" )
825825 # CPython interpreter uses PyErr_WriteUnraisable: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_WriteUnraisable
826826 # However, the message is slightly different due to the way mypyc compiles classes.
827827 # CPython interpreter prints: Exception ignored in: <function F.__del__ at 0x100aed940>
828828 # mypyc prints: Exception ignored in: <slot wrapper '__del__' of 'F' objects>
829829 emitter .emit_line ("PyErr_WriteUnraisable(del_method);" )
830- emitter .emit_line ("Py_DECREF(class_obj);" )
831830 emitter .emit_line ("Py_XDECREF(del_method);" )
831+ emitter .emit_line ("Py_XDECREF(del_str);" )
832832 emitter .emit_line ("}" )
833833 # PyErr_Restore also clears exception raised in __del__.
834834 emitter .emit_line ("PyErr_Restore(type, value, traceback);" )
You can’t perform that action at this time.
0 commit comments