[issue47135] Allow decimal.localcontext to accept keyword arguments to set context attributes

Sam Ezeh report at bugs.python.org
Fri Apr 1 15:51:26 EDT 2022


Sam Ezeh <sam.z.ezeh at gmail.com> added the comment:

This is what functionality looks like when supplying incorrect attribute names with the patch.

Python 3.11.0a6+ (heads/bpo-47135-dirty:d4bb38f82b, Apr  1 2022, 20:01:56) [GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import _pydecimal
>>> ctx = _pydecimal.getcontext()
>>> ctx.precision = 10
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/run/media/sam/OS/Git/cpython/Lib/_pydecimal.py", line 3974, in __setattr__
    raise AttributeError(
    ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'decimal.Context' object has no attribute 'precision'
>>> with _pydecimal.localcontext(precision=10) as ctx:
...     pass
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/run/media/sam/OS/Git/cpython/Lib/_pydecimal.py", line 506, in localcontext
    setattr(ctx, key, value)
    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/run/media/sam/OS/Git/cpython/Lib/_pydecimal.py", line 3974, in __setattr__
    raise AttributeError(
    ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'decimal.Context' object has no attribute 'precision'
>>> import decimal
>>> ctx = decimal.getcontext()
>>> ctx.precision = 10
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'decimal.Context' object has no attribute 'precision'
>>> with decimal.localcontext(precision=10) as ctx:
...     pass
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'precision' is an invalid keyword argument for this function
>>>

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue47135>
_______________________________________


More information about the Python-bugs-list mailing list