@@ -42,6 +42,7 @@ BaseException_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
4242 /* the dict is created on the fly in PyObject_GenericSetAttr */
4343 self -> dict = NULL ;
4444 self -> traceback = self -> cause = self -> context = NULL ;
45+ self -> suppress_context = 0 ;
4546
4647 self -> args = PyTuple_New (0 );
4748 if (!self -> args ) {
@@ -266,35 +267,28 @@ BaseException_get_cause(PyObject *self) {
266267 PyObject * res = PyException_GetCause (self );
267268 if (res )
268269 return res ; /* new reference already returned above */
269- Py_INCREF (Py_Ellipsis );
270- return Py_Ellipsis ;
270+ Py_RETURN_NONE ;
271271}
272272
273- int
274- _PyException_SetCauseChecked (PyObject * self , PyObject * arg ) {
275- if (arg == Py_Ellipsis ) {
273+ static int
274+ BaseException_set_cause (PyObject * self , PyObject * arg ) {
275+ if (arg == NULL ) {
276+ PyErr_SetString (PyExc_TypeError , "__cause__ may not be deleted" );
277+ return -1 ;
278+ } else if (arg == Py_None ) {
276279 arg = NULL ;
277- } else if (arg != Py_None && !PyExceptionInstance_Check (arg )) {
278- PyErr_SetString (PyExc_TypeError , "exception cause must be None, "
279- "Ellipsis or derive from BaseException" );
280+ } else if (!PyExceptionInstance_Check (arg )) {
281+ PyErr_SetString (PyExc_TypeError , "exception cause must be None "
282+ "or derive from BaseException" );
280283 return -1 ;
281284 } else {
282- /* PyException_SetCause steals a reference */
285+ /* PyException_SetCause steals this reference */
283286 Py_INCREF (arg );
284287 }
285288 PyException_SetCause (self , arg );
286289 return 0 ;
287290}
288291
289- static int
290- BaseException_set_cause (PyObject * self , PyObject * arg ) {
291- if (arg == NULL ) {
292- PyErr_SetString (PyExc_TypeError , "__cause__ may not be deleted" );
293- return -1 ;
294- }
295- return _PyException_SetCauseChecked (self , arg );
296- }
297-
298292
299293static PyGetSetDef BaseException_getset [] = {
300294 {"__dict__" , PyObject_GenericGetDict , PyObject_GenericSetDict },
333327PyException_SetCause (PyObject * self , PyObject * cause ) {
334328 PyObject * old_cause = ((PyBaseExceptionObject * )self )-> cause ;
335329 ((PyBaseExceptionObject * )self )-> cause = cause ;
330+ ((PyBaseExceptionObject * )self )-> suppress_context = 1 ;
336331 Py_XDECREF (old_cause );
337332}
338333
@@ -352,6 +347,12 @@ PyException_SetContext(PyObject *self, PyObject *context) {
352347}
353348
354349
350+ static struct PyMemberDef BaseException_members [] = {
351+ {"__suppress_context__" , T_BOOL ,
352+ offsetof(PyBaseExceptionObject , suppress_context )}
353+ };
354+
355+
355356static PyTypeObject _PyExc_BaseException = {
356357 PyVarObject_HEAD_INIT (NULL , 0 )
357358 "BaseException" , /*tp_name*/
@@ -382,7 +383,7 @@ static PyTypeObject _PyExc_BaseException = {
382383 0 , /* tp_iter */
383384 0 , /* tp_iternext */
384385 BaseException_methods , /* tp_methods */
385- 0 , /* tp_members */
386+ BaseException_members , /* tp_members */
386387 BaseException_getset , /* tp_getset */
387388 0 , /* tp_base */
388389 0 , /* tp_dict */
0 commit comments