[pypy-commit] pypy py3.5: improve error message

2017-03-09 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r90612:92ab105ad8e7
Date: 2017-03-09 18:11 +0100
http://bitbucket.org/pypy/pypy/changeset/92ab105ad8e7/

Log:improve error message

diff --git a/pypy/objspace/std/test/test_typeobject.py 
b/pypy/objspace/std/test/test_typeobject.py
--- a/pypy/objspace/std/test/test_typeobject.py
+++ b/pypy/objspace/std/test/test_typeobject.py
@@ -957,6 +957,9 @@
 assert C.__name__ == 'A'
 assert C.__qualname__ == 'C'
 
+e = raises(TypeError, type, 'D', (), {'__qualname__': 42})
+assert str(e.value) == "type __qualname__ must be a str, not int"
+
 def test_compare(self):
 class A(object):
 pass
diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -197,6 +197,10 @@
 if self.flag_heaptype:
 w_qualname = self.dict_w.pop('__qualname__', None)
 if w_qualname is not None:
+if not space.isinstance_w(w_qualname, space.w_unicode):
+raise oefmt(space.w_TypeError,
+"type __qualname__ must be a str, not %T",
+w_qualname)
 self.qualname = space.unicode_w(w_qualname)
 else:
 self.qualname = self.getname(space)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Improve error message in some cases, like CPython. Use '< >' around

2016-11-01 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r88022:ccec49a07062
Date: 2016-11-01 11:57 +0100
http://bitbucket.org/pypy/pypy/changeset/ccec49a07062/

Log:Improve error message in some cases, like CPython. Use '< >' around
auto-generated scope names even though these names are not really
public.

diff --git a/pypy/interpreter/astcompiler/symtable.py 
b/pypy/interpreter/astcompiler/symtable.py
--- a/pypy/interpreter/astcompiler/symtable.py
+++ b/pypy/interpreter/astcompiler/symtable.py
@@ -232,11 +232,7 @@
 class ModuleScope(Scope):
 
 def __init__(self):
-Scope.__init__(self, "top")
-
-def note_await(self, await_node):
-raise SyntaxError("'await' outside async function", await_node.lineno,
-  await_node.col_offset)
+Scope.__init__(self, "")
 
 
 class FunctionScope(Scope):
@@ -270,8 +266,11 @@
 self.has_yield_inside_try = True
 
 def note_await(self, await_node):
-raise SyntaxError("'await' outside async function", await_node.lineno,
-  await_node.col_offset)
+if self.name == '':
+msg = "'await' expressions in comprehensions are not supported"
+else:
+msg = "'await' outside async function"
+raise SyntaxError(msg, await_node.lineno, await_node.col_offset)
 
 def note_return(self, ret):
 if ret.value:
@@ -305,11 +304,9 @@
 if (self.has_free or self.child_has_free) and not self.optimized:
 raise AssertionError("unknown reason for unoptimization")
 
+
 class AsyncFunctionScope(FunctionScope):
 
-def __init__(self, name, lineno, col_offset):
-FunctionScope.__init__(self, name, lineno, col_offset)
-
 def note_yield(self, yield_node):
 raise SyntaxError("'yield' inside async function", yield_node.lineno,
   yield_node.col_offset)
@@ -521,7 +518,7 @@
 assert isinstance(args, ast.arguments)
 self.visit_sequence(args.defaults)
 self.visit_kwonlydefaults(args.kw_defaults)
-new_scope = FunctionScope("lambda", lamb.lineno, lamb.col_offset)
+new_scope = FunctionScope("", lamb.lineno, lamb.col_offset)
 self.push_scope(new_scope, lamb)
 lamb.args.walkabout(self)
 lamb.body.walkabout(self)
@@ -531,7 +528,7 @@
 outer = comps[0]
 assert isinstance(outer, ast.comprehension)
 outer.iter.walkabout(self)
-new_scope = FunctionScope("genexp", node.lineno, node.col_offset)
+new_scope = FunctionScope("", node.lineno, node.col_offset)
 self.push_scope(new_scope, node)
 self.implicit_arg(0)
 outer.target.walkabout(self)
diff --git a/pypy/interpreter/astcompiler/test/test_compiler.py 
b/pypy/interpreter/astcompiler/test/test_compiler.py
--- a/pypy/interpreter/astcompiler/test/test_compiler.py
+++ b/pypy/interpreter/astcompiler/test/test_compiler.py
@@ -1132,6 +1132,15 @@
 """
 py.test.raises(SyntaxError, self.simple_test, source, None, None)
 
+def test_error_message_1(self):
+source = """if 1:
+async def f():
+{await a for a in b}
+"""
+e = py.test.raises(SyntaxError, self.simple_test, source, None, None)
+assert e.value.msg == (
+"'await' expressions in comprehensions are not supported")
+
 
 class AppTestCompiler:
 
diff --git a/pypy/interpreter/astcompiler/test/test_symtable.py 
b/pypy/interpreter/astcompiler/test/test_symtable.py
--- a/pypy/interpreter/astcompiler/test/test_symtable.py
+++ b/pypy/interpreter/astcompiler/test/test_symtable.py
@@ -44,7 +44,7 @@
 gen_scope = mod_scope.children[0]
 assert isinstance(gen_scope, symtable.FunctionScope)
 assert not gen_scope.children
-assert gen_scope.name == "genexp"
+assert gen_scope.name == ""
 return mod_scope, gen_scope
 
 def check_unknown(self, scp, *names):
@@ -251,7 +251,7 @@
 assert len(scp.children) == 1
 lscp = scp.children[0]
 assert isinstance(lscp, symtable.FunctionScope)
-assert lscp.name == "lambda"
+assert lscp.name == ""
 assert lscp.lookup("x") == symtable.SCOPE_LOCAL
 assert lscp.lookup("y") == symtable.SCOPE_GLOBAL_IMPLICIT
 scp = self.mod_scope("lambda x=a: b")
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Improve error message

2016-10-14 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r87773:1bc8b7459f16
Date: 2016-10-14 11:27 +0200
http://bitbucket.org/pypy/pypy/changeset/1bc8b7459f16/

Log:Improve error message

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1375,7 +1375,8 @@
 except OperationError as err:
 if objdescr is None or not err.match(self, self.w_TypeError):
 raise
-raise oefmt(self.w_TypeError, "%s must be an integer, not %T",
+raise oefmt(self.w_TypeError,
+"%s indices must be integers or slices, not %T",
 objdescr, w_obj)
 try:
 # allow_conversion=False it's not really necessary because the
diff --git a/pypy/interpreter/test/test_objspace.py 
b/pypy/interpreter/test/test_objspace.py
--- a/pypy/interpreter/test/test_objspace.py
+++ b/pypy/interpreter/test/test_objspace.py
@@ -238,8 +238,8 @@
 try:
 self.space.getindex_w(self.space.w_tuple, None, "foobar")
 except OperationError as e:
-assert e.match(self.space, self.space.w_TypeError)
-assert "foobar" in e.errorstr(self.space)
+assert e.errorstr(self.space) == (
+   "TypeError: foobar indices must be integers or slices, not 
type")
 else:
 assert 0, "should have raised"
 
diff --git a/pypy/objspace/std/bytearrayobject.py 
b/pypy/objspace/std/bytearrayobject.py
--- a/pypy/objspace/std/bytearrayobject.py
+++ b/pypy/objspace/std/bytearrayobject.py
@@ -358,8 +358,7 @@
 _setitem_slice_helper(space, self.data, start, step,
   slicelength, sequence2, empty_elem='\x00')
 else:
-idx = space.getindex_w(w_index, space.w_IndexError,
-   "bytearray index")
+idx = space.getindex_w(w_index, space.w_IndexError, "bytearray")
 try:
 self.data[idx] = getbytevalue(space, w_other)
 except IndexError:
@@ -371,8 +370,7 @@
 len(self.data))
 _delitem_slice_helper(space, self.data, start, step, slicelength)
 else:
-idx = space.getindex_w(w_idx, space.w_IndexError,
-   "bytearray index")
+idx = space.getindex_w(w_idx, space.w_IndexError, "bytearray")
 try:
 del self.data[idx]
 except IndexError:
diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -561,7 +561,7 @@
 return self.getslice(start, stop, step, slicelength)
 
 try:
-index = space.getindex_w(w_index, space.w_IndexError, "list index")
+index = space.getindex_w(w_index, space.w_IndexError, "list")
 return self.getitem(index)
 except IndexError:
 raise oefmt(space.w_IndexError, "list index out of range")
@@ -578,7 +578,7 @@
 self.setslice(start, step, slicelength, w_other)
 return
 
-idx = space.getindex_w(w_index, space.w_IndexError, "list index")
+idx = space.getindex_w(w_index, space.w_IndexError, "list")
 try:
 self.setitem(idx, w_any)
 except IndexError:
@@ -591,7 +591,7 @@
 self.deleteslice(start, step, slicelength)
 return
 
-idx = space.getindex_w(w_idx, space.w_IndexError, "list index")
+idx = space.getindex_w(w_idx, space.w_IndexError, "list")
 if idx < 0:
 idx += self.length()
 try:
diff --git a/pypy/objspace/std/stringmethods.py 
b/pypy/objspace/std/stringmethods.py
--- a/pypy/objspace/std/stringmethods.py
+++ b/pypy/objspace/std/stringmethods.py
@@ -130,7 +130,7 @@
 ret = _descr_getslice_slowpath(selfvalue, start, step, sl)
 return self._new_from_list(ret)
 
-index = space.getindex_w(w_index, space.w_IndexError, "string index")
+index = space.getindex_w(w_index, space.w_IndexError, "string")
 return self._getitem_result(space, index)
 
 def _getitem_result(self, space, index):
diff --git a/pypy/objspace/std/tupleobject.py b/pypy/objspace/std/tupleobject.py
--- a/pypy/objspace/std/tupleobject.py
+++ b/pypy/objspace/std/tupleobject.py
@@ -189,7 +189,7 @@
 def descr_getitem(self, space, w_index):
 if isinstance(w_index, W_SliceObject):
 return self._getslice(space, w_index)
-index = space.getindex_w(w_index, space.w_IndexError, "tuple index")
+index = space.getindex_w(w_index, space.w_IndexError, "tuple")
 return self.getitem(space, index)
 
 def _getslice(self, space, w_index):
___
pypy-commit mailing list
pypy-comm