Skip to content

Commit

Permalink
pythongh-106078: Convert _decimal types to heap types (python#106079)
Browse files Browse the repository at this point in the history
- 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]>
  • Loading branch information
3 people authored Jun 29, 2023
1 parent 0e24499 commit fb0d9b9
Show file tree
Hide file tree
Showing 3 changed files with 433 additions and 390 deletions.
21 changes: 20 additions & 1 deletion Lib/test/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
import locale
from test.support import (is_resource_enabled,
requires_IEEE_754, requires_docstrings,
requires_legacy_unicode_capi, check_sanitizer)
requires_legacy_unicode_capi, check_sanitizer,
check_disallow_instantiation)
from test.support import (TestFailed,
run_with_locale, cpython_only,
darwin_malloc_err_warning, is_emscripten)
Expand Down Expand Up @@ -5681,6 +5682,24 @@ def test_maxcontext_exact_arith(self):
self.assertEqual(Decimal(4) / 2, 2)
self.assertEqual(Decimal(400) ** -1, Decimal('0.0025'))

def test_c_immutable_types(self):
SignalDict = type(C.Context().flags)
SignalDictMixin = SignalDict.__bases__[0]
ContextManager = type(C.localcontext())
types = (
SignalDictMixin,
ContextManager,
C.Decimal,
C.Context,
)
for tp in types:
with self.subTest(tp=tp):
with self.assertRaisesRegex(TypeError, "immutable"):
tp.foo = 1

def test_c_disallow_instantiation(self):
ContextManager = type(C.localcontext())
check_disallow_instantiation(self, ContextManager)

@requires_docstrings
@requires_cdecimal
Expand Down
Loading

0 comments on commit fb0d9b9

Please sign in to comment.