Skip to content

Commit fb0d9b9

Browse files
CharlieZhao95kumaraditya303erlend-aasland
authored
gh-106078: Convert _decimal types to heap types (#106079)
- Establish global state struct - Convert static types to heap types and add them to global state: * PyDecContextManager_Type * PyDecContext_Type * PyDecSignalDictMixin_Type * PyDec_Type - Add to global state: * PyDecSignalDict_Type * DecimalTuple Co-authored-by: Kumar Aditya <[email protected]> Co-authored-by: Erlend E. Aasland <[email protected]>
1 parent 0e24499 commit fb0d9b9

File tree

3 files changed

+433
-390
lines changed

3 files changed

+433
-390
lines changed

Lib/test/test_decimal.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
import locale
3535
from test.support import (is_resource_enabled,
3636
requires_IEEE_754, requires_docstrings,
37-
requires_legacy_unicode_capi, check_sanitizer)
37+
requires_legacy_unicode_capi, check_sanitizer,
38+
check_disallow_instantiation)
3839
from test.support import (TestFailed,
3940
run_with_locale, cpython_only,
4041
darwin_malloc_err_warning, is_emscripten)
@@ -5681,6 +5682,24 @@ def test_maxcontext_exact_arith(self):
56815682
self.assertEqual(Decimal(4) / 2, 2)
56825683
self.assertEqual(Decimal(400) ** -1, Decimal('0.0025'))
56835684

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)
56845703

56855704
@requires_docstrings
56865705
@requires_cdecimal

0 commit comments

Comments
 (0)