diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py --- a/Lib/test/test_decimal.py +++ b/Lib/test/test_decimal.py @@ -3278,6 +3278,11 @@ self.assertEqual(c4.prec, 4) del c4 + def test_localcontext_none(self): + # see #15783 + with self.decimal.localcontext(None): + pass + class CContextWithStatement(ContextWithStatement): decimal = C class PyContextWithStatement(ContextWithStatement): diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -1486,10 +1486,10 @@ } #define CONTEXT_CHECK_VA(obj) \ - if (!PyDecContext_Check(obj)) { \ - PyErr_SetString(PyExc_TypeError, \ - "optional argument must be a context"); \ - return NULL; \ + if ((obj != Py_None) && !PyDecContext_Check(obj)) { \ + PyErr_SetString(PyExc_TypeError, \ + "optional argument must be a context"); \ + return NULL; \ }