File tree 2 files changed +23
-1
lines changed
2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -1949,7 +1949,10 @@ def build_tokens_line(self):
1949
1949
if token_type == tokenize .STRING :
1950
1950
text = mute_string (text )
1951
1951
elif token_type == FSTRING_MIDDLE : # pragma: >=3.12 cover
1952
- text = 'x' * len (text )
1952
+ # fstring tokens are "unescaped" braces -- re-escape!
1953
+ brace_count = text .count ('{' ) + text .count ('}' )
1954
+ text = 'x' * (len (text ) + brace_count )
1955
+ end = (end [0 ], end [1 ] + brace_count )
1953
1956
if prev_row :
1954
1957
(start_row , start_col ) = start
1955
1958
if prev_row != start_row : # different row
Original file line number Diff line number Diff line change
1
+ import io
2
+ import sys
3
+ import tokenize
4
+
1
5
import pytest
2
6
7
+ from pycodestyle import Checker
3
8
from pycodestyle import expand_indent
4
9
from pycodestyle import mute_string
5
10
@@ -27,3 +32,17 @@ def test_expand_indent(s, expected):
27
32
)
28
33
def test_mute_string (s , expected ):
29
34
assert mute_string (s ) == expected
35
+
36
+
37
+ def test_fstring_logical_line ():
38
+ src = '''\
39
+ f'hello {{ {thing} }} world'
40
+ '''
41
+ checker = Checker (lines = src .splitlines ())
42
+ checker .tokens = list (tokenize .generate_tokens (io .StringIO (src ).readline ))
43
+ checker .build_tokens_line ()
44
+
45
+ if sys .version_info >= (3 , 12 ): # pragma: >3.12 cover
46
+ assert checker .logical_line == "f'xxxxxxxxx{thing}xxxxxxxxx'"
47
+ else :
48
+ assert checker .logical_line == "f'xxxxxxxxxxxxxxxxxxxxxxxxx'"
You can’t perform that action at this time.
0 commit comments