[pypy-commit] pypy decimal-libmpdec: Fix context flags dictionary.

amauryfa noreply at buildbot.pypy.org
Wed May 21 00:23:54 CEST 2014


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: decimal-libmpdec
Changeset: r71623:c15880925b71
Date: 2014-05-19 22:18 +0200
http://bitbucket.org/pypy/pypy/changeset/c15880925b71/

Log:	Fix context flags dictionary.

diff --git a/lib-python/3/test/test_decimal.py b/lib-python/3/test/test_decimal.py
--- a/lib-python/3/test/test_decimal.py
+++ b/lib-python/3/test/test_decimal.py
@@ -47,6 +47,7 @@
 
 C = import_fresh_module('decimal', fresh=['_decimal'])
 P = import_fresh_module('decimal', blocked=['_decimal'])
+C.MAX_EMAX = P.MAX_EMAX
 orig_sys_decimal = sys.modules['decimal']
 
 # fractions module must import the correct decimal module.
diff --git a/pypy/module/_decimal/__init__.py b/pypy/module/_decimal/__init__.py
--- a/pypy/module/_decimal/__init__.py
+++ b/pypy/module/_decimal/__init__.py
@@ -15,6 +15,7 @@
         'getcontext': 'interp_context.getcontext',
         'setcontext': 'interp_context.setcontext',
         'DecimalException': 'interp_signals.get(space).w_DecimalException',
+        'SignalTuple': 'interp_signals.get(space).w_SignalTuple',
 
         'IEEE_CONTEXT_MAX_BITS': 'space.wrap(interp_decimal.IEEE_CONTEXT_MAX_BITS)',
         'MAX_PREC': 'space.wrap(interp_decimal.MAX_PREC)',
diff --git a/pypy/module/_decimal/interp_context.py b/pypy/module/_decimal/interp_context.py
--- a/pypy/module/_decimal/interp_context.py
+++ b/pypy/module/_decimal/interp_context.py
@@ -32,6 +32,13 @@
         else:
             self.flag_ptr[0] = rffi.cast(rffi.UINT, cur_flag & ~flag)
 
+    def descr_delitem(self, space, w_key):
+        raise oefmt(space.w_ValueError,
+                    "signal keys cannot be deleted")
+
+    def descr_iter(self, space):
+        return space.iter(interp_signals.get(space).w_SignalTuple)
+
 
 def new_signal_dict(space, flag_ptr):
     w_dict = space.allocate_instance(W_SignalDictMixin,
@@ -44,6 +51,8 @@
     'SignalDictMixin',
     __getitem__ = interp2app(W_SignalDictMixin.descr_getitem),
     __setitem__ = interp2app(W_SignalDictMixin.descr_setitem),
+    __delitem__ = interp2app(W_SignalDictMixin.descr_delitem),
+    __iter__ = interp2app(W_SignalDictMixin.descr_iter),
     )
 W_SignalDictMixin.typedef.acceptable_as_base_class = True
 
diff --git a/pypy/module/_decimal/interp_signals.py b/pypy/module/_decimal/interp_signals.py
--- a/pypy/module/_decimal/interp_signals.py
+++ b/pypy/module/_decimal/interp_signals.py
@@ -117,5 +117,9 @@
                             space.w_TypeError]),
             space.newdict())
 
+        self.w_SignalTuple = space.newtuple([
+                getattr(self, 'w_' + name)
+                for name, flag in SIGNAL_MAP])
+
 def get(space):
     return space.fromcache(SignalState)
diff --git a/pypy/module/_decimal/test/test_module.py b/pypy/module/_decimal/test/test_module.py
--- a/pypy/module/_decimal/test/test_module.py
+++ b/pypy/module/_decimal/test/test_module.py
@@ -25,6 +25,9 @@
         bases = type(flags).__bases__
         assert bases[1] is MutableMapping
 
+        assert _decimal.Inexact in flags
+        assert _decimal.Inexact in flags.keys()
+
     def test_context_changes(self):
         import _decimal
         context = _decimal.getcontext()


More information about the pypy-commit mailing list