Skip to content

Commit

Permalink
fix the one failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharsadhwani committed Mar 27, 2024
1 parent a81bae3 commit 0435144
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/blib2to3/Grammar.txt
Expand Up @@ -256,7 +256,6 @@ patterns: pattern (',' pattern)* [',']
pattern: (expr|star_expr) ['as' expr]

fstring: FSTRING_START fstring_middle* FSTRING_END
# TODO making these FSTRING_MIDDLE makes them unformattable so maybe put a new token here?
fstring_middle: fstring_replacement_field | FSTRING_MIDDLE
fstring_replacement_field: '{' (yield_expr | testlist_star_expr) ['='] [ "!" NAME ] [ ':' fstring_format_spec* ] '}'
fstring_format_spec: FSTRING_MIDDLE | fstring_replacement_field
7 changes: 4 additions & 3 deletions src/blib2to3/pgen2/tokenize.py
Expand Up @@ -665,7 +665,6 @@ def generate_tokens(
if endmatch: # all on one line
start, end = endmatch.span(0)
token = line[start:end]
# TODO: check if the token will ever have any whitespace around?
if token.endswith(('"""', "'''")):
middle_token, end_token = token[:-3], token[-3:]
middle_epos = end_spos = (lnum, end - 3)
Expand Down Expand Up @@ -707,8 +706,6 @@ def generate_tokens(
contline = line
break

# TODO: fstring_level > 0 is redundant in both cases here,
# remove it and ensure nothing breaks
if inside_fstring_colon:
match = fstring_middle_after_colon.match(line, pos)
if match is None:
Expand Down Expand Up @@ -982,6 +979,10 @@ def generate_tokens(
else:
if parenlev == 0 and bracelev > 0 and initial == "}":
bracelev -= 1
# if we're still inside fstrings, we're still part of the format spec
if inside_fstring_braces:
inside_fstring_colon = True
formatspec_start = (lnum, pos)
elif initial in "([{":
parenlev += 1
elif initial in ")]}":
Expand Down
6 changes: 6 additions & 0 deletions tests/data/cases/pep_701.py
Expand Up @@ -67,8 +67,11 @@
rf'foo'
rf'{foo}'

f"{x:{y}d}"

x = f"a{2+2:=^{x}}b"
x = f"a{2+2:=^{foo(x+y**2):something else}}b"
x = f"a{2+2:=^{foo(x+y**2):something else}one more}b"
f'{(abc:=10)}'

f"This is a really long string, but just make sure that you reflow fstrings {
Expand Down Expand Up @@ -164,8 +167,11 @@
rf"foo"
rf"{foo}"

f"{x:{y}d}"

x = f"a{2 + 2:=^{x}}b"
x = f"a{2 + 2:=^{foo(x + y**2):something else}}b"
x = f"a{2 + 2:=^{foo(x + y**2):something else}one more}b"
f"{(abc := 10)}"

f"This is a really long string, but just make sure that you reflow fstrings {2 + 2:d}"
Expand Down

0 comments on commit 0435144

Please sign in to comment.