[pypy-commit] pypy decimal-libmpdec: Ensure that _decimal exception types have a __module__, otherwise this confuses traceback.py.

amauryfa noreply at buildbot.pypy.org
Sun Oct 5 20:22:55 CEST 2014


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: decimal-libmpdec
Changeset: r73793:bef69d4879cd
Date: 2014-09-18 00:52 +0200
http://bitbucket.org/pypy/pypy/changeset/bef69d4879cd/

Log:	Ensure that _decimal exception types have a __module__, otherwise
	this confuses traceback.py.

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
@@ -77,51 +77,55 @@
 
 class SignalState:
     def __init__(self, space):
+        w_typedict = space.newdict()
+        space.setitem(w_typedict,
+                      space.wrap("__module__"), space.wrap("decimal"))
+                                             
         self.w_DecimalException = space.call_function(
             space.w_type, space.wrap("DecimalException"),
             space.newtuple([space.w_ArithmeticError]),
-            space.newdict())
+            w_typedict)
         self.w_Clamped = space.call_function(
             space.w_type, space.wrap("Clamped"),
             space.newtuple([self.w_DecimalException]),
-            space.newdict())
+            w_typedict)
         self.w_Rounded = space.call_function(
             space.w_type, space.wrap("Rounded"),
             space.newtuple([self.w_DecimalException]),
-            space.newdict())
+            w_typedict)
         self.w_Inexact = space.call_function(
             space.w_type, space.wrap("Inexact"),
             space.newtuple([self.w_DecimalException]),
-            space.newdict())
+            w_typedict)
         self.w_Subnormal = space.call_function(
             space.w_type, space.wrap("Subnormal"),
             space.newtuple([self.w_DecimalException]),
-            space.newdict())
+            w_typedict)
         self.w_Underflow = space.call_function(
             space.w_type, space.wrap("Underflow"),
             space.newtuple([self.w_Inexact,
                             self.w_Rounded,
                             self.w_Subnormal]),
-            space.newdict())
+            w_typedict)
         self.w_Overflow = space.call_function(
             space.w_type, space.wrap("Overflow"),
             space.newtuple([self.w_Inexact,
                             self.w_Rounded]),
-            space.newdict())
+            w_typedict)
         self.w_DivisionByZero = space.call_function(
             space.w_type, space.wrap("DivisionByZero"),
             space.newtuple([self.w_DecimalException,
                             space.w_ZeroDivisionError]),
-            space.newdict())
+            w_typedict)
         self.w_InvalidOperation = space.call_function(
             space.w_type, space.wrap("InvalidOperation"),
             space.newtuple([self.w_DecimalException]),
-            space.newdict())
+            w_typedict)
         self.w_FloatOperation = space.call_function(
             space.w_type, space.wrap("FloatOperation"),
             space.newtuple([self.w_DecimalException,
                             space.w_TypeError]),
-            space.newdict())
+            w_typedict)
 
         self.w_SignalTuple = space.newtuple([
                 getattr(self, 'w_' + name)
@@ -142,7 +146,7 @@
                 w_bases = space.newtuple([self.w_InvalidOperation])
             setattr(self, 'w_' + name,
                     space.call_function(
-                    space.w_type, space.wrap(name), w_bases, space.newdict()))
+                    space.w_type, space.wrap(name), w_bases, w_typedict))
 
 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
@@ -50,6 +50,7 @@
             ex = getattr(_decimal, name)
             assert issubclass(ex, _decimal.DecimalException)
             assert issubclass(ex, ArithmeticError)
+            assert ex.__module__ == 'decimal'
 
     def test_exception_hierarchy(self):
         import _decimal as decimal


More information about the pypy-commit mailing list