Skip to content

Commit b677a64

Browse files
tokenizer: skip lines that are just slash and whitespace (psf#4343)
1 parent 8447af4 commit b677a64

File tree

6 files changed

+37
-1
lines changed

6 files changed

+37
-1
lines changed

AUTHORS.md

+1
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ Multiple contributions by:
181181
- [Tony Narlock](mailto:[email protected])
182182
- [Tsuyoshi Hombashi](mailto:[email protected])
183183
- [Tushar Chandra](mailto:[email protected])
184+
- [Tushar Sadhwani](mailto:[email protected])
184185
- [Tzu-ping Chung](mailto:[email protected])
185186
- [Utsav Shah](mailto:[email protected])
186187
- utsav-dbx

CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
- Fix regression where Black failed to parse a multiline f-string containing another
3535
multiline string (#4339)
3636

37+
- Fix bug with Black incorrectly parsing empty lines with a backslash (#4343)
38+
3739
### Performance
3840

3941
<!-- Changes that improve Black's performance. -->

src/blib2to3/pgen2/tokenize.py

+6
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,12 @@ def generate_tokens(
608608
except StopIteration:
609609
line = ""
610610
lnum += 1
611+
612+
# skip lines that are just indent characters ending with a slash
613+
# to avoid storing that line's indent information.
614+
if not contstr and line.rstrip("\n").strip(" \t\f") == "\\":
615+
continue
616+
611617
pos, max = 0, len(line)
612618

613619
if contstr: # continued string
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# flags: --minimum-version=3.10
2+
class Plotter:
3+
\
4+
pass
5+
6+
class AnotherCase:
7+
\
8+
"""Some
9+
\
10+
Docstring
11+
"""
12+
13+
# output
14+
15+
class Plotter:
16+
17+
pass
18+
19+
20+
class AnotherCase:
21+
"""Some
22+
\
23+
Docstring
24+
"""

tests/data/cases/comment_after_escaped_newline.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ def bob(): # pylint: disable=W9016
1414
pass
1515

1616

17-
def bobtwo(): # some comment here
17+
def bobtwo():
18+
19+
# some comment here
1820
pass

tests/data/cases/form_feeds.py

+1
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ def something(self):
156156

157157
#
158158

159+
159160
#
160161
pass
161162

0 commit comments

Comments
 (0)