Author: Carl Friedrich Bolz-Tereick <cfb...@gmx.de> Branch: pyparser-improvements-2 Changeset: r94276:692d3ce9de27 Date: 2018-04-07 14:38 +0200 http://bitbucket.org/pypy/pypy/changeset/692d3ce9de27/
Log: tweak error message and position diff --git a/pypy/interpreter/pyparser/pytokenizer.py b/pypy/interpreter/pyparser/pytokenizer.py --- a/pypy/interpreter/pyparser/pytokenizer.py +++ b/pypy/interpreter/pyparser/pytokenizer.py @@ -231,11 +231,13 @@ if not ((opening == "(" and initial == ")") or (opening == "[" and initial == "]") or (opening == "{" and initial == "}")): + msg = "closing parenthesis '%s' does not match opening parenthesis '%s'" % ( + initial, opening) + + if lnum1 != lnum: + msg += " on line " + str(lnum1) raise TokenError( - "parenthesis '%s' and '%s' don't match" % ( - opening, initial), - line1, lnum1, start1, token_list, - lastlineno=lnum) + msg, line, lnum, start, token_list) if token in python_opmap: punct = python_opmap[token] else: diff --git a/pypy/interpreter/pyparser/test/test_pytokenizer.py b/pypy/interpreter/pyparser/test/test_pytokenizer.py --- a/pypy/interpreter/pyparser/test/test_pytokenizer.py +++ b/pypy/interpreter/pyparser/test/test_pytokenizer.py @@ -45,12 +45,12 @@ for j, closing in enumerate(")]}"): if i == j: continue - error = pytest.raises(TokenError, tokenize, opening + "1\n" + closing) - assert error.value.msg == \ - "parenthesis '%s' and '%s' don't match" % (opening, closing) - assert error.value.offset == 0 - assert error.value.lineno == 1 - assert error.value.lastlineno == 2 + check_token_error(opening + "1\n" + closing, + "closing parenthesis '%s' does not match opening parenthesis '%s' on line 1" % (closing, opening), + pos=0, line=2) + check_token_error(opening + "1" + closing, + "closing parenthesis '%s' does not match opening parenthesis '%s'" % (closing, opening), + pos=2, line=1) def test_unknown_char(self): _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit