From 065081f227a2a9dcc1ce7eb4c9793960165cff83 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sat, 5 Aug 2017 23:12:13 +0200 Subject: [PATCH] Fix two more TODOs about bytes in Python 2. --- parso/python/normalizer.py | 5 ++--- test/normalizer_issue_files/allowed_syntax_python2.py | 2 ++ 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 test/normalizer_issue_files/allowed_syntax_python2.py diff --git a/parso/python/normalizer.py b/parso/python/normalizer.py index 847ff5c..86b8a9f 100644 --- a/parso/python/normalizer.py +++ b/parso/python/normalizer.py @@ -415,8 +415,7 @@ class ErrorFinder(Normalizer): first = node.children[0] # e.g. 's' b'' message = "cannot mix bytes and nonbytes literals" - # TODO this check is only relevant for Python 3+ - if first.type == 'string': + if first.type == 'string' and self._version >= (3, 0): first_is_bytes = _is_bytes_literal(first) for string in node.children[1:]: if first_is_bytes != _is_bytes_literal(string): @@ -550,8 +549,8 @@ class ErrorFinder(Normalizer): elif leaf.type == 'string': string_prefix = leaf.string_prefix.lower() if 'b' in string_prefix \ + and self._version >= (3, 0) \ 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) diff --git a/test/normalizer_issue_files/allowed_syntax_python2.py b/test/normalizer_issue_files/allowed_syntax_python2.py new file mode 100644 index 0000000..81736bc --- /dev/null +++ b/test/normalizer_issue_files/allowed_syntax_python2.py @@ -0,0 +1,2 @@ +'s' b'' +u's' b'ä'