serhiy-storchaka · GitHub

Bug report

localcontext() accepts keyword arguments which set the corresponding attributes of the new context. The C and the pure Python implementations differ if the value is None:

>>> import decimal, _pydecimal
>>> with decimal.localcontext(prec=None) as ctx: ctx.prec
...
28
>>> with _pydecimal.localcontext(prec=None) as ctx: ctx.prec
...
TypeError: prec must be an integer

The C implementation shares the code with the Context constructor, where None means "not specified"; the pure Python implementation simply assigns all keyword arguments. None is not a valid value for any of these attributes, so it should probably be rejected in both.

Linked PRs

Read the original on github.com ↗