[3.12] gh-112364: Correct unparsing of backslashes and quotes in ast.… (#115782)

[3.12] gh-112364: Correct unparsing of backslashes and quotes in ast.unparse (GH-115696)
(cherry picked from commit 69ab93082d)
This commit is contained in:
Frank Hoffmann 2024-02-22 00:28:07 +01:00 committed by GitHub
parent 3651c2729a
commit d2fced7128
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 24 additions and 7 deletions

View file

@ -649,6 +649,21 @@ class CosmeticTestCase(ASTTestCase):
self.check_ast_roundtrip("""f'''""\"''\\'{"\\n\\"'"}''' """)
self.check_ast_roundtrip("""f'''""\"''\\'{""\"\\n\\"'''""\" '''\\n'''}''' """)
def test_backslash_in_format_spec(self):
self.check_ast_roundtrip("""f"{x:\\ }" """)
self.check_ast_roundtrip("""f"{x:\\\\ }" """)
self.check_ast_roundtrip("""f"{x:\\\\\\ }" """)
self.check_ast_roundtrip("""f"{x:\\\\\\\\ }" """)
def test_quote_in_format_spec(self):
self.check_ast_roundtrip("""f"{x:'}" """)
self.check_ast_roundtrip("""f"{x:\\'}" """)
self.check_ast_roundtrip("""f"{x:\\\\'}" """)
self.check_ast_roundtrip("""f'\\'{x:"}' """)
self.check_ast_roundtrip("""f'\\'{x:\\"}' """)
self.check_ast_roundtrip("""f'\\'{x:\\\\"}' """)
class ManualASTCreationTestCase(unittest.TestCase):
"""Test that AST nodes created without a type_params field unparse correctly."""