Skip to content

Commit a8242c2

Browse files
authored
Fix unasync script for Python 3.12 (#1005)
1 parent 23cce6a commit a8242c2

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

bin/make-unasync

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ def _tokenize(f):
8989
last_end = tok.end
9090
if tok.type in [std_tokenize.NEWLINE, std_tokenize.NL]:
9191
last_end = (tok.end[0] + 1, 0)
92+
elif (
93+
sys.version_info >= (3, 12)
94+
and tok.type == std_tokenize.FSTRING_MIDDLE
95+
):
96+
last_end = (
97+
last_end[0],
98+
last_end[1]
99+
+ tok.string.count("{")
100+
+ tok.string.count("}")
101+
)
92102

93103

94104
def _untokenize(tokens):
@@ -134,6 +144,12 @@ class CustomRule(unasync.Rule):
134144
tokval[:1], tokval[1:-1], tokval[-1:]
135145
tokval = \
136146
left_quote + self._unasync_string(name) + right_quote
147+
elif (
148+
sys.version_info >= (3, 12)
149+
and toknum == std_tokenize.FSTRING_MIDDLE
150+
):
151+
tokval = tokval.replace("{", "{{").replace("}", "}}")
152+
tokval = self._unasync_string(tokval)
137153
if used_space is None:
138154
used_space = space
139155
yield (used_space, tokval)

0 commit comments

Comments
 (0)