Skip to content
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

gh-106078: Convert _decimal types to heap types #106079

Merged
merged 18 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
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
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 (run_unittest, run_doctest, 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 @@ -5661,6 +5662,24 @@ def test_maxcontext_exact_arith(self):
self.assertEqual(Decimal(4) / 2, 2)
self.assertEqual(Decimal(400) ** -1, Decimal('0.0025'))

def test_immutable_types(self):
decimal = C
siganldict_type = type(decimal.Context().flags)
self.dataset = (
siganldict_type.__bases__[0], # SignalDictMixin type
type(decimal.localcontext()), # ContextManager type
decimal.Decimal,
decimal.Context,
)
for tp in self.dataset:
with self.subTest(tp=tp):
with self.assertRaisesRegex(TypeError, "immutable"):
tp.foo = 1

def test_disallow_instantiation(self):
decimal = C
ctxmanager_type = type(decimal.localcontext())
check_disallow_instantiation(self, ctxmanager_type)

@requires_docstrings
@unittest.skipUnless(C, "test requires C version")
Expand Down
Loading