self.assertRaises(TypeError, self.decimal.localcontext, Emin="")
self.assertRaises(TypeError, self.decimal.localcontext, Emax="")
+ # None is not a valid value for any of these attributes.
+ for name in ('prec', 'rounding', 'Emin', 'Emax', 'capitals', 'clamp',
+ 'flags', 'traps'):
+ with self.subTest(name=name):
+ self.assertRaises(TypeError, self.decimal.localcontext,
+ **{name: None})
+
def test_local_context_kwargs_does_not_overwrite_existing_argument(self):
ctx = self.decimal.getcontext()
orig_prec = ctx.prec
--- /dev/null
+:func:`decimal.localcontext` now raises :exc:`TypeError` if a keyword argument
+is ``None``, as the pure Python implementation already did. Previously the C
+implementation silently ignored it.
return PyObject_GenericSetAttr(self, name, value);
}
-/* In the constructor and in localcontext() None means "not specified". */
+/* In the constructor None means "not specified". */
#define NONE_TO_NULL(x) ((x) == Py_None ? NULL : (x))
/* Set the given attributes. An attribute is left unchanged if the
ctx as local: object = None
*
- prec: object = None
- rounding: object = None
- Emin: object = None
- Emax: object = None
- capitals: object = None
- clamp: object = None
- flags: object = None
- traps: object = None
+ prec: object = NULL
+ rounding: object = NULL
+ Emin: object = NULL
+ Emax: object = NULL
+ capitals: object = NULL
+ clamp: object = NULL
+ flags: object = NULL
+ traps: object = NULL
Return a context manager for a copy of the supplied context.
PyObject *rounding, PyObject *Emin,
PyObject *Emax, PyObject *capitals,
PyObject *clamp, PyObject *flags, PyObject *traps)
-/*[clinic end generated code: output=9bf4e47742a809b0 input=490307b9689c3856]*/
+/*[clinic end generated code: output=9bf4e47742a809b0 input=616abb6ee1654373]*/
{
PyObject *global;
}
int ret = context_setattrs(
- local_copy, NONE_TO_NULL(prec), NONE_TO_NULL(rounding),
- NONE_TO_NULL(Emin), NONE_TO_NULL(Emax), NONE_TO_NULL(capitals),
- NONE_TO_NULL(clamp), NONE_TO_NULL(flags), NONE_TO_NULL(traps)
+ local_copy, prec, rounding,
+ Emin, Emax, capitals,
+ clamp, flags, traps
);
if (ret < 0) {
Py_DECREF(local_copy);
PyObject *argsbuf[9];
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
PyObject *local = Py_None;
- PyObject *prec = Py_None;
- PyObject *rounding = Py_None;
- PyObject *Emin = Py_None;
- PyObject *Emax = Py_None;
- PyObject *capitals = Py_None;
- PyObject *clamp = Py_None;
- PyObject *flags = Py_None;
- PyObject *traps = Py_None;
+ PyObject *prec = NULL;
+ PyObject *rounding = NULL;
+ PyObject *Emin = NULL;
+ PyObject *Emax = NULL;
+ PyObject *capitals = NULL;
+ PyObject *clamp = NULL;
+ PyObject *flags = NULL;
+ PyObject *traps = NULL;
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
/*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
#ifndef _DECIMAL_CONTEXT_APPLY_METHODDEF
#define _DECIMAL_CONTEXT_APPLY_METHODDEF
#endif /* !defined(_DECIMAL_CONTEXT_APPLY_METHODDEF) */
-/*[clinic end generated code: output=75ab23467fa0eee3 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=07ec694c7fd6b048 input=a9049054013a1b77]*/