def PyErr_SetObject(space, w_type, w_value): """This function is similar to PyErr_SetString() but lets you specify an arbitrary Python object for the "value" of the exception.""" state = space.fromcache(State) operr = OperationError(w_type, w_value) operr.record_context(space, space.getexecutioncontext()) state.set_exception(operr)
def _leak_stopiteration(self, e): # Check for __future__ generator_stop and conditionally turn # a leaking StopIteration into RuntimeError (with its cause # set appropriately). space = self.space if self.pycode.co_flags & (consts.CO_FUTURE_GENERATOR_STOP | consts.CO_COROUTINE | consts.CO_ITERABLE_COROUTINE): e2 = OperationError( space.w_RuntimeError, space.newtext("%s raised StopIteration" % self.KIND)) e2.chain_exceptions(space, e) e2.set_cause(space, e.get_w_value(space)) e2.record_context(space, space.getexecutioncontext()) raise e2 else: space.warn( space.newunicode(u"generator '%s' raised StopIteration" % self.get_qualname()), space.w_PendingDeprecationWarning)