Author: Brian Kearns <bdkea...@gmail.com> Branch: rpython-enverror Changeset: r73323:9984536b0e51 Date: 2014-09-05 14:47 -0400 http://bitbucket.org/pypy/pypy/changeset/9984536b0e51/
Log: attempt to support EnvironmentError properly in rpython diff --git a/rpython/annotator/builtin.py b/rpython/annotator/builtin.py --- a/rpython/annotator/builtin.py +++ b/rpython/annotator/builtin.py @@ -255,12 +255,8 @@ BUILTIN_ANALYZERS[original] = value -@analyzer_for(getattr(IOError.__init__, 'im_func', IOError.__init__)) -def IOError_init(s_self, *args): - pass - -@analyzer_for(getattr(OSError.__init__, 'im_func', OSError.__init__)) -def OSError_init(s_self, *args): +@analyzer_for(getattr(EnvironmentError.__init__, 'im_func', EnvironmentError.__init__)) +def EnvironmentError_init(s_self, *args): pass try: diff --git a/rpython/annotator/classdef.py b/rpython/annotator/classdef.py --- a/rpython/annotator/classdef.py +++ b/rpython/annotator/classdef.py @@ -438,8 +438,7 @@ # ____________________________________________________________ FORCE_ATTRIBUTES_INTO_CLASSES = { - IOError: {'errno': SomeInteger()}, - OSError: {'errno': SomeInteger()}, + EnvironmentError: {'errno': SomeInteger(), 'strerror': SomeString(can_be_None=True), 'filename': SomeString(can_be_None=True)}, } try: diff --git a/rpython/rtyper/rbuiltin.py b/rpython/rtyper/rbuiltin.py --- a/rpython/rtyper/rbuiltin.py +++ b/rpython/rtyper/rbuiltin.py @@ -264,27 +264,18 @@ def rtype_object__init__(hop): hop.exception_cannot_occur() -def rtype_IOError__init__(hop): +def rtype_EnvironmentError__init__(hop): hop.exception_cannot_occur() - if hop.nb_args == 2: - raise TyperError("IOError() should not be called with " - "a single argument") - if hop.nb_args >= 3: + if hop.nb_args >= 2: v_self = hop.args_v[0] r_self = hop.args_r[0] v_errno = hop.inputarg(lltype.Signed, arg=1) r_self.setfield(v_self, 'errno', v_errno, hop.llops) - -def rtype_OSError__init__(hop): - hop.exception_cannot_occur() - if hop.nb_args == 2: - raise TyperError("OSError() should not be called with " - "a single argument") - if hop.nb_args >= 3: - v_self = hop.args_v[0] - r_self = hop.args_r[0] - v_errno = hop.inputarg(lltype.Signed, arg=1) - r_self.setfield(v_self, 'errno', v_errno, hop.llops) + if hop.nb_args >= 3: + v_strerror = hop.inputarg(hop.args_r[2], arg=2) + else: + v_strerror = None + r_self.setfield(v_self, 'strerror', v_strerror, hop.llops) def rtype_WindowsError__init__(hop): hop.exception_cannot_occur() @@ -344,11 +335,8 @@ original = getattr(__builtin__, name[14:]) BUILTIN_TYPER[original] = value -BUILTIN_TYPER[getattr(IOError.__init__, 'im_func', IOError.__init__)] = ( - rtype_IOError__init__) - -BUILTIN_TYPER[getattr(OSError.__init__, 'im_func', OSError.__init__)] = ( - rtype_OSError__init__) +BUILTIN_TYPER[getattr(EnvironmentError.__init__, 'im_func', EnvironmentError.__init__)] = ( + rtype_EnvironmentError__init__) try: WindowsError 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 @@ -36,20 +36,34 @@ class TestException(BaseRtypingTest): def test_exception_with_arg(self): def g(n): - raise IOError(n, "?") + raise IOError(n) def h(n): raise OSError(n, "?") + def i(n): + raise EnvironmentError(n, "?", "test") def f(n): try: g(n) except IOError, e: assert e.errno == 42 + assert e.strerror is None + assert e.filename is None else: assert False try: h(n) except OSError, e: assert e.errno == 42 + assert e.strerror == "?" + assert e.filename is None + else: + assert False + try: + i(n) + except EnvironmentError as e: + assert e.errno == 42 + assert e.strerror == "?" + assert e.filename == "test" else: assert False self.interpret(f, [42]) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit