Author: Amaury Forgeot d'Arc <[email protected]>
Branch: stdlib-3.2.5
Changeset: r70426:81af5323708c
Date: 2014-04-03 23:54 +0200
http://bitbucket.org/pypy/pypy/changeset/81af5323708c/
Log: CPython issue1692335: Exception.args is also set in __new__
(for naive exception subclasses which don't call super().__init__)
diff --git a/pypy/module/exceptions/interp_exceptions.py
b/pypy/module/exceptions/interp_exceptions.py
--- a/pypy/module/exceptions/interp_exceptions.py
+++ b/pypy/module/exceptions/interp_exceptions.py
@@ -208,8 +208,10 @@
if basecls is None:
basecls = cls
def descr_new_base_exception(space, w_subtype, __args__):
+ args_w, kwds_w = __args__.unpack() # ignore kwds
exc = space.allocate_instance(cls, w_subtype)
basecls.__init__(exc, space)
+ exc.args_w = args_w
return space.wrap(exc)
descr_new_base_exception.func_name = 'descr_new_' + cls.__name__
return interp2app(descr_new_base_exception)
diff --git a/pypy/module/exceptions/test/test_exc.py
b/pypy/module/exceptions/test/test_exc.py
--- a/pypy/module/exceptions/test/test_exc.py
+++ b/pypy/module/exceptions/test/test_exc.py
@@ -40,6 +40,14 @@
x = X(x=8)
assert x.x == 8
+ def test_args(self):
+ class X(Exception):
+ def __init__(self, x=3):
+ self.x = x
+
+ assert X(8).args == (8,)
+ assert X(x=8).args == ()
+
def test_exc(self):
assert issubclass(Exception, BaseException)
assert isinstance(Exception(), Exception)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit