|
34 | 34 | import locale
|
35 | 35 | from test.support import (is_resource_enabled,
|
36 | 36 | requires_IEEE_754, requires_docstrings,
|
37 |
| - requires_legacy_unicode_capi, check_sanitizer) |
| 37 | + requires_legacy_unicode_capi, check_sanitizer, |
| 38 | + check_disallow_instantiation) |
38 | 39 | from test.support import (TestFailed,
|
39 | 40 | run_with_locale, cpython_only,
|
40 | 41 | darwin_malloc_err_warning, is_emscripten)
|
@@ -5681,6 +5682,24 @@ def test_maxcontext_exact_arith(self):
|
5681 | 5682 | self.assertEqual(Decimal(4) / 2, 2)
|
5682 | 5683 | self.assertEqual(Decimal(400) ** -1, Decimal('0.0025'))
|
5683 | 5684 |
|
| 5685 | + def test_c_immutable_types(self): |
| 5686 | + SignalDict = type(C.Context().flags) |
| 5687 | + SignalDictMixin = SignalDict.__bases__[0] |
| 5688 | + ContextManager = type(C.localcontext()) |
| 5689 | + types = ( |
| 5690 | + SignalDictMixin, |
| 5691 | + ContextManager, |
| 5692 | + C.Decimal, |
| 5693 | + C.Context, |
| 5694 | + ) |
| 5695 | + for tp in types: |
| 5696 | + with self.subTest(tp=tp): |
| 5697 | + with self.assertRaisesRegex(TypeError, "immutable"): |
| 5698 | + tp.foo = 1 |
| 5699 | + |
| 5700 | + def test_c_disallow_instantiation(self): |
| 5701 | + ContextManager = type(C.localcontext()) |
| 5702 | + check_disallow_instantiation(self, ContextManager) |
5684 | 5703 |
|
5685 | 5704 | @requires_docstrings
|
5686 | 5705 | @requires_cdecimal
|
|
0 commit comments