gh-127975: Avoid reusing quote types in ast.unparse if not needed (#127980)

This commit is contained in:
Shantanu 2025-01-31 00:49:06 -08:00 committed by GitHub
parent 95504f429e
commit 8df5193d37
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 7 deletions

View file

@ -513,11 +513,13 @@ class CosmeticTestCase(ASTTestCase):
self.check_src_roundtrip("class X(*args, **kwargs):\n pass")
def test_fstrings(self):
self.check_src_roundtrip("f'-{f'*{f'+{f'.{x}.'}+'}*'}-'")
self.check_src_roundtrip("f'\\u2028{'x'}'")
self.check_src_roundtrip('''f\'\'\'-{f"""*{f"+{f'.{x}.'}+"}*"""}-\'\'\'''')
self.check_src_roundtrip('''f\'-{f\'\'\'*{f"""+{f".{f'{x}'}."}+"""}*\'\'\'}-\'''')
self.check_src_roundtrip('''f\'-{f\'*{f\'\'\'+{f""".{f"{f'{x}'}"}."""}+\'\'\'}*\'}-\'''')
self.check_src_roundtrip('''f"\\u2028{'x'}"''')
self.check_src_roundtrip(r"f'{x}\n'")
self.check_src_roundtrip("f'{'\\n'}\\n'")
self.check_src_roundtrip("f'{f'{x}\\n'}\\n'")
self.check_src_roundtrip('''f"{'\\n'}\\n"''')
self.check_src_roundtrip('''f"{f'{x}\\n'}\\n"''')
def test_docstrings(self):
docstrings = (