[pypy-commit] pypy default: fix raising EnvironmentError without args

bdkearns noreply at buildbot.pypy.org
Fri Sep 5 22:44:05 CEST 2014


Author: Brian Kearns <bdkearns at gmail.com>
Branch: 
Changeset: r73331:08c4d8862d38
Date: 2014-09-05 16:43 -0400
http://bitbucket.org/pypy/pypy/changeset/08c4d8862d38/

Log:	fix raising EnvironmentError without args

diff --git a/rpython/rtyper/rbuiltin.py b/rpython/rtyper/rbuiltin.py
--- a/rpython/rtyper/rbuiltin.py
+++ b/rpython/rtyper/rbuiltin.py
@@ -267,12 +267,12 @@
 
 def rtype_EnvironmentError__init__(hop):
     hop.exception_cannot_occur()
-    if hop.nb_args <= 1:
-        raise TyperError("EnvironmentError() should be called with "
-                         "at least one argument")
     v_self = hop.args_v[0]
     r_self = hop.args_r[0]
-    v_errno = hop.inputarg(lltype.Signed, arg=1)
+    if hop.nb_args >= 2:
+        v_errno = hop.inputarg(lltype.Signed, arg=1)
+    else:
+        v_errno = hop.inputconst(lltype.Signed, 0)
     r_self.setfield(v_self, 'errno', v_errno, hop.llops)
     if hop.nb_args >= 3:
         v_strerror = hop.inputarg(rstr.string_repr, arg=2)
diff --git a/rpython/rtyper/test/test_exception.py b/rpython/rtyper/test/test_exception.py
--- a/rpython/rtyper/test/test_exception.py
+++ b/rpython/rtyper/test/test_exception.py
@@ -43,6 +43,8 @@
             raise EnvironmentError(n, "?", "test")
         def j(n):
             raise IOError(0, "test")
+        def k(n):
+            raise OSError
         def f(n):
             try:
                 g(n)
@@ -74,6 +76,12 @@
                 assert e.errno == 0
                 assert e.strerror == "test"
                 assert e.filename is None
+            try:
+                k(n)
+            except EnvironmentError as e:
+                assert e.errno == 0
+                assert e.strerror is None
+                assert e.filename is None
         self.interpret(f, [42])
 
     def test_catch_incompatible_class(self):


More information about the pypy-commit mailing list