Author: Philip Jenvey <[email protected]>
Branch: operrfmt-NT
Changeset: r64559:52c9fdaa5b22
Date: 2013-05-25 13:37 -0700
http://bitbucket.org/pypy/pypy/changeset/52c9fdaa5b22/
Log: ease the W_TypeObject assertion to accomodate Dummy/FakeObjSpaces
diff --git a/pypy/interpreter/error.py b/pypy/interpreter/error.py
--- a/pypy/interpreter/error.py
+++ b/pypy/interpreter/error.py
@@ -355,18 +355,21 @@
self.xstrings = strings
for i, _, attr in entries:
setattr(self, attr, args[i])
- assert _is_type(w_type)
+ assert w_type is not None
+ # space may be None during tests
+ self.space = w_type.space if _is_type(w_type) else None
def _compute_value(self):
+ space = self.space
lst = [None] * (len(formats) + len(formats) + 1)
for i, fmt, attr in entries:
string = self.xstrings[i]
value = getattr(self, attr)
lst[i+i] = string
- if fmt in 'NT':
- space = self.w_type.space
- if fmt == 'T':
- value = space.type(value)
+ if fmt == 'T':
+ type_ = type if space is None else space.type
+ value = type_(value)
+ if fmt in 'NT' and space is not None:
lst[i+i+1] = value.getname(space)
else:
lst[i+i+1] = str(value)
diff --git a/pypy/interpreter/test/test_error.py
b/pypy/interpreter/test/test_error.py
--- a/pypy/interpreter/test/test_error.py
+++ b/pypy/interpreter/test/test_error.py
@@ -12,26 +12,25 @@
assert (decompose_valuefmt("%s%d%%%s") ==
(("", "", "%", ""), ('s', 'd', 's')))
-def test_get_operrcls2(space):
+def test_get_operrcls2():
cls, strings = get_operrcls2('abc %s def %d')
assert strings == ("abc ", " def ", "")
assert issubclass(cls, OperationError)
- inst = cls(space.w_OSError, strings, "hello", 42)
+ inst = cls("w_type", strings, "hello", 42)
assert inst._compute_value() == "abc hello def 42"
cls2, strings2 = get_operrcls2('a %s b %d c')
assert cls2 is cls # caching
assert strings2 == ("a ", " b ", " c")
-def test_operationerrfmt(space):
- w_exc = space.w_IOError
- operr = operationerrfmt(w_exc, "abc %s def %d", "foo", 42)
+def test_operationerrfmt():
+ operr = operationerrfmt("w_type", "abc %s def %d", "foo", 42)
assert isinstance(operr, OperationError)
- assert operr.w_type == w_exc
+ assert operr.w_type == "w_type"
assert operr._w_value is None
assert operr._compute_value() == "abc foo def 42"
- operr2 = operationerrfmt(w_exc, "a %s b %d c", "bar", 43)
+ operr2 = operationerrfmt("w_type2", "a %s b %d c", "bar", 43)
assert operr2.__class__ is operr.__class__
- operr3 = operationerrfmt(w_exc, "a %s b %s c", "bar", "4b")
+ operr3 = operationerrfmt("w_type2", "a %s b %s c", "bar", "4b")
assert operr3.__class__ is not operr.__class__
def test_operationerrfmt_T(space):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit