8000 gh-91291: Accept attributes as keyword arguments in decimal.localcontext by dignissimus · Pull Request #32242 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-91291: Accept attributes as keyword arguments in decimal.localcontext #32242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Apr 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Amend documentation, Add tests
  • Loading branch information
dignissimus committed Apr 4, 2022
commit 054361502165b9bc04cc3973e92f3f7b95eedf8f
2 changes: 1 addition & 1 deletion Doc/library/decimal.rst
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ function to temporarily change the active context.
support.

.. versionchanged:: 3.11
Raises :exc:`ValueError` if *kwargs* supplies an invalid value for an attribute.
Raises either :exc:`TypeError` or :exc:`ValueError` if *kwargs* supplies an invalid value for an attribute.

New contexts can also be created using the :class:`Context` constructor
described below. In addition, the module provides three pre-made contexts:
Expand Down
7 changes: 7 additions & 0 deletions Lib/test/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3616,11 +3616,18 @@ def test_localcontext_kwargs(self):
self.assertEqual(ctx.clamp, 1)

self.assertRaises(TypeError, self.decimal.localcontext, precision=10)

self.assertRaises(ValueError, self.decimal.localcontext, Emin=1)
self.assertRaises(ValueError, self.decimal.localcontext, Emax=-1)
self.assertRaises(ValueError, self.decimal.localcontext, capitals=2)
self.assertRaises(ValueError, self.decimal.localcontext, clamp=2)

self.assertRaises(TypeError, self.decimal.localcontext, rounding="")
self.assertRaises(TypeError, self.decimal.localcontext, flags="")
self.assertRaises(TypeError, self.decimal.localcontext, traps="")
self.assertRaises(TypeError, self.decimal.localcontext, Emin="")
self.assertRaises(TypeError, self.decimal.localcontext, Emax="")

def test_nested_with_statements(self):
# Use a copy of the supplied context in the block
Decimal = self.decimal.Decimal
Expand Down
0