1. Pypy
  2. Untitled project
  3. pypy

Commits

Amaury Forgeot d'Arc  committed daf495c

(lambacck) Implement PyExceptionInstance_Class,
simplified because 2.7 strongly discourages old-style exceptions.

  • Participants
  • Parent commits 6a70d2e
  • Branches default

Comments (0)

Files changed (2)

File pypy/module/cpyext/pyerrors.py

View file
  • Ignore whitespace
     state = space.fromcache(State)
     state.clear_exception()
 
+@cpython_api([PyObject], PyObject)
+def PyExceptionInstance_Class(space, w_obj):
+    return space.type(w_obj)
+
 @cpython_api([PyObjectP, PyObjectP, PyObjectP], lltype.Void)
 def PyErr_Fetch(space, ptype, pvalue, ptraceback):
     """Retrieve the error indicator into three variables whose addresses are passed.

File pypy/module/cpyext/test/test_pyerrors.py

View file
  • Ignore whitespace
         out, err = capfd.readouterr()
         assert "Exception ValueError: 'message' in 'location' ignored" == err.strip()
 
+    def test_ExceptionInstance_Class(self, space, api):
+        instance = space.call_function(space.w_ValueError)
+        assert api.PyExceptionInstance_Class(instance) is space.w_ValueError
+
 class AppTestFetch(AppTestCpythonExtensionBase):
     def setup_class(cls):
         AppTestCpythonExtensionBase.setup_class.im_func(cls)