From 319a0cc56f8707630c282cf3a0b95a1d9cc2a9eb Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Mon, 24 Jul 2017 18:28:14 +0200 Subject: [PATCH] Add issue: 'bytes can only contain ASCII literal characters.' --- parso/python/normalizer.py | 7 +++++++ test/test_python_errors.py | 1 + 2 files changed, 8 insertions(+) diff --git a/parso/python/normalizer.py b/parso/python/normalizer.py index d4c9710..02b83a9 100644 --- a/parso/python/normalizer.py +++ b/parso/python/normalizer.py @@ -204,6 +204,13 @@ class ErrorFinder(Normalizer): self._add_indentation_error(message, spacing) else: self._add_syntax_error('invalid syntax', leaf) + elif leaf.type == 'string': + if 'b' in leaf.string_prefix.lower() \ + and any(c for c in leaf.value if ord(c) > 127): + # TODO add check for python 3 + # b'ä' + message = "bytes can only contain ASCII literal characters." + self._add_syntax_error(message, leaf) elif leaf.value == 'continue': in_loop = False for block in self._context.blocks: diff --git a/test/test_python_errors.py b/test/test_python_errors.py index 478deea..818a41e 100644 --- a/test/test_python_errors.py +++ b/test/test_python_errors.py @@ -120,6 +120,7 @@ def test_python_exception_matches(code): ('[*[] for a in [1]]', '3.5'), ('{**{} for a in [1]}', '3.5'), ('"s" b""', '3.5'), + ('b"ä"', '3.5'), ] ) def test_python_exception_matches_version(code, version):