diff --git a/parso/python/errors.py b/parso/python/errors.py index 92fdef1..8300301 100644 --- a/parso/python/errors.py +++ b/parso/python/errors.py @@ -570,11 +570,14 @@ class _BytesAndStringMix(SyntaxRule): message = "cannot mix bytes and nonbytes literals" def _is_bytes_literal(self, string): + if string.type == 'fstring': + return False return 'b' in string.string_prefix.lower() def is_issue(self, node): first = node.children[0] - if first.type == 'string' and self._normalizer.version >= (3, 0): + # In Python 2 it's allowed to mix bytes and unicode. + if self._normalizer.version >= (3, 0): first_is_bytes = self._is_bytes_literal(first) for string in node.children[1:]: if first_is_bytes != self._is_bytes_literal(string): diff --git a/test/failing_examples.py b/test/failing_examples.py index 25e93ca..412c89a 100644 --- a/test/failing_examples.py +++ b/test/failing_examples.py @@ -285,6 +285,14 @@ if sys.version_info >= (3,): 'b"รค"', # combining strings and unicode is allowed in Python 2. '"s" b""', + '"s" b"" ""', + 'b"" "" b"" ""', + ] +if sys.version_info >= (3, 6): + FAILING_EXAMPLES += [ + # Same as above, but for f-strings. + 'f"s" b""', + 'b"s" f""', ] if sys.version_info >= (2, 7): # This is something that raises a different error in 2.6 than in the other