A multiline string with quotes next to the ending quote is not parsed correctly: In [1]: """A "test"""" ------------------------------------------------------------ File "", line 1 """A "test"""" ^ <type 'exceptions.SyntaxError'>: EOL while scanning single-quoted string Is this normal behaviour? It seems to me like the parser should parse everything inside the triple double quotes (there is no ambiguity).
There is an ambiguity: did you mean """ " or " """ (spaces added for clarity). Python does not count quotes, parentheses or similar in strings, so the first occurrence of """ will close the literal. You can either use triple single quotes, or escape the first quote, like that: """A "test\"""".
The last quote starts another string literal, so this is valid Python: """A "test"""" B" and results in a string 'A "test B'. The lexer cannot know whether the second string literal is terminated or not, yielding valid or invalid code.