gh-108843: fix ast.unparse for f-string with many quotes (#108981)

This commit is contained in:
Shantanu 2023-09-18 06:56:19 -07:00 committed by GitHub
parent 4dd47c63a9
commit 23f9f6f464
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 1 deletions

View file

@ -635,6 +635,20 @@ class CosmeticTestCase(ASTTestCase):
self.check_src_roundtrip("[a, b] = [c, d] = [e, f] = g")
self.check_src_roundtrip("a, b = [c, d] = e, f = g")
def test_multiquote_joined_string(self):
self.check_ast_roundtrip("f\"'''{1}\\\"\\\"\\\"\" ")
self.check_ast_roundtrip("""f"'''{1}""\\"" """)
self.check_ast_roundtrip("""f'""\"{1}''' """)
self.check_ast_roundtrip("""f'""\"{1}""\\"' """)
self.check_ast_roundtrip("""f"'''{"\\n"}""\\"" """)
self.check_ast_roundtrip("""f'""\"{"\\n"}''' """)
self.check_ast_roundtrip("""f'""\"{"\\n"}""\\"' """)
self.check_ast_roundtrip("""f'''""\"''\\'{"\\n"}''' """)
self.check_ast_roundtrip("""f'''""\"''\\'{"\\n\\"'"}''' """)
self.check_ast_roundtrip("""f'''""\"''\\'{""\"\\n\\"'''""\" '''\\n'''}''' """)
class ManualASTCreationTestCase(unittest.TestCase):
"""Test that AST nodes created without a type_params field unparse correctly."""