Skip to content

Commit b677a64

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

File tree

6 files changed

+37
-1
lines changed

6 files changed

+37
-1
lines changed

AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ Multiple contributions by:
181181
- [Tony Narlock](mailto:tony@git-pull.com)
182182
- [Tsuyoshi Hombashi](mailto:tsuyoshi.hombashi@gmail.com)
183183
- [Tushar Chandra](mailto:tusharchandra2018@u.northwestern.edu)
184+
- [Tushar Sadhwani](mailto:tushar.sadhwani000@gmail.com)
184185
- [Tzu-ping Chung](mailto:uranusjr@gmail.com)
185186
- [Utsav Shah](mailto:ukshah2@illinois.edu)
186187
- utsav-dbx

CHANGES.md

Lines changed: 2 additions & 0 deletions
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

Lines changed: 6 additions & 0 deletions
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
Lines changed: 24 additions & 0 deletions
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy