Skip to content

Commit f3a381e

Browse files
authored
gh-141510: support frozendict's in the C decimal module (gh-145165)
1 parent c2d3d6b commit f3a381e

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Lib/test/test_decimal.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3963,15 +3963,21 @@ def test_flag_comparisons(self):
39633963
d.update(c.flags)
39643964
self.assertEqual(d, c.flags)
39653965
self.assertEqual(c.flags, d)
3966+
self.assertEqual(frozendict(d), c.flags)
3967+
self.assertEqual(c.flags, frozendict(d))
39663968

39673969
d[Inexact] = True
39683970
self.assertNotEqual(d, c.flags)
39693971
self.assertNotEqual(c.flags, d)
3972+
self.assertNotEqual(frozendict(d), c.flags)
3973+
self.assertNotEqual(c.flags, frozendict(d))
39703974

39713975
# Invalid SignalDict
39723976
d = {Inexact:False}
39733977
self.assertNotEqual(d, c.flags)
39743978
self.assertNotEqual(c.flags, d)
3979+
self.assertNotEqual(frozendict(d), c.flags)
3980+
self.assertNotEqual(c.flags, frozendict(d))
39753981

39763982
d = ["xyz"]
39773983
self.assertNotEqual(d, c.flags)

Modules/_decimal/_decimal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ dict_as_flags(decimal_state *state, PyObject *val)
552552
uint32_t flags = 0;
553553
int x;
554554

555-
if (!PyDict_Check(val)) {
555+
if (!PyAnyDict_Check(val)) {
556556
PyErr_SetString(PyExc_TypeError,
557557
"argument must be a signal dict");
558558
return DEC_INVALID_SIGNALS;
@@ -802,7 +802,7 @@ signaldict_richcompare(PyObject *v, PyObject *w, int op)
802802
if (PyDecSignalDict_Check(state, w)) {
803803
res = (SdFlags(v)==SdFlags(w)) ^ (op==Py_NE) ? Py_True : Py_False;
804804
}
805-
else if (PyDict_Check(w)) {
805+
else if (PyAnyDict_Check(w)) {
806806
uint32_t flags = dict_as_flags(state, w);
807807
if (flags & DEC_ERRORS) {
808808
if (flags & DEC_INVALID_SIGNALS) {

0 commit comments

Comments
 (0)