Skip to content

Commit 4743d8d

Browse files
hauntsaninjaisidentical
authored and
hauntsaninja
committed
Update Lib/ast.py
Co-authored-by: Batuhan Taskaya <isidentical@gmail.com>
1 parent cc318ee commit 4743d8d

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

Lib/ast.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,18 +1059,23 @@ def should_use_repr(c):
10591059
# on that in Tools/unicode/makeunicodedata.py
10601060
c not in (' ', '\n', '\t') and unicodedata.category(c)[0] in ("C", "Z")
10611061
)
1062+
use_repr = any(map(should_use_repr, value))
1063+
1064+
if not use_repr:
1065+
quote_types = ["'", '"', '"""', "'''"]
10621066

1063-
if not any(should_use_repr(c) for c in value):
10641067
if "\n" in value:
1065-
quote_types = ["'''", '"""']
1066-
else:
1067-
quote_types = ["'", '"', '"""', "'''"]
1068+
quote_types = quote_types[2:]
10681069

10691070
for quote_type in quote_types:
10701071
if quote_type not in value:
10711072
self.write(f"{quote_type}{value}{quote_type}")
1072-
return
1073-
self.write(repr(value))
1073+
break
1074+
else:
1075+
use_repr = True
1076+
1077+
if use_repr:
1078+
self.write(repr(value))
10741079

10751080
def visit_JoinedStr(self, node):
10761081
self.write("f")

0 commit comments

Comments
 (0)