Author: Carl Friedrich Bolz-Tereick <[email protected]>
Branch: py3.5
Changeset: r93711:5ad0629dd41b
Date: 2018-01-29 14:19 +0100
http://bitbucket.org/pypy/pypy/changeset/5ad0629dd41b/
Log: make sure that the error message for invalid characters in byte
string literals contains position information. improves issue #2712
(but something is still going wrong somewhere)
diff --git a/pypy/interpreter/astcompiler/fstring.py
b/pypy/interpreter/astcompiler/fstring.py
--- a/pypy/interpreter/astcompiler/fstring.py
+++ b/pypy/interpreter/astcompiler/fstring.py
@@ -355,15 +355,18 @@
except error.OperationError as e:
if e.match(space, space.w_UnicodeError):
- kind = 'unicode error'
+ kind = '(unicode error) '
elif e.match(space, space.w_ValueError):
- kind = 'value error'
+ kind = '(value error) '
+ elif e.match(space, space.w_SyntaxError):
+ kind = ''
else:
raise
- # Unicode/ValueError in literal: turn into SyntaxError
+ # Unicode/ValueError/SyntaxError (without position information) in
+ # literal: turn into SyntaxError with position information
e.normalize_exception(space)
errmsg = space.text_w(space.str(e.get_w_value(space)))
- raise astbuilder.error('(%s) %s' % (kind, errmsg), atom_node)
+ raise astbuilder.error('%s%s' % (kind, errmsg), atom_node)
if not fmode and len(joined_pieces) == 1: # <= the common path
return joined_pieces[0] # ast.Str, Bytes or FormattedValue
diff --git a/pypy/interpreter/test/test_compiler.py
b/pypy/interpreter/test/test_compiler.py
--- a/pypy/interpreter/test/test_compiler.py
+++ b/pypy/interpreter/test/test_compiler.py
@@ -1007,8 +1007,9 @@
compile(b"# coding: latin1\n#\xfd\n", "dummy", "exec")
raises(SyntaxError, compile, b"# coding: utf-8\n'\xfd'\n",
"dummy", "exec") #1
- raises(SyntaxError, compile, b'# coding: utf-8\nx=5\nb"\xfd"\n',
+ excinfo = raises(SyntaxError, compile, b'# coding:
utf-8\nx=5\nb"\xfd"\n',
"dummy", "exec") #2
+ assert excinfo.value.lineno == 3
# the following example still fails on CPython 3.5.2, skip if -A
if '__pypy__' in sys.builtin_module_names:
raises(SyntaxError, compile, b"# coding: utf-8\n#\xfd\n",
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit