tokenizer: skip lines that are just slash and whitespace (#4343)
This commit is contained in:
parent
8447af4d8d
commit
b677a643c5
@ -181,6 +181,7 @@ Multiple contributions by:
|
|||||||
- [Tony Narlock](mailto:tony@git-pull.com)
|
- [Tony Narlock](mailto:tony@git-pull.com)
|
||||||
- [Tsuyoshi Hombashi](mailto:tsuyoshi.hombashi@gmail.com)
|
- [Tsuyoshi Hombashi](mailto:tsuyoshi.hombashi@gmail.com)
|
||||||
- [Tushar Chandra](mailto:tusharchandra2018@u.northwestern.edu)
|
- [Tushar Chandra](mailto:tusharchandra2018@u.northwestern.edu)
|
||||||
|
- [Tushar Sadhwani](mailto:tushar.sadhwani000@gmail.com)
|
||||||
- [Tzu-ping Chung](mailto:uranusjr@gmail.com)
|
- [Tzu-ping Chung](mailto:uranusjr@gmail.com)
|
||||||
- [Utsav Shah](mailto:ukshah2@illinois.edu)
|
- [Utsav Shah](mailto:ukshah2@illinois.edu)
|
||||||
- utsav-dbx
|
- utsav-dbx
|
||||||
|
@ -34,6 +34,8 @@
|
|||||||
- Fix regression where Black failed to parse a multiline f-string containing another
|
- Fix regression where Black failed to parse a multiline f-string containing another
|
||||||
multiline string (#4339)
|
multiline string (#4339)
|
||||||
|
|
||||||
|
- Fix bug with Black incorrectly parsing empty lines with a backslash (#4343)
|
||||||
|
|
||||||
### Performance
|
### Performance
|
||||||
|
|
||||||
<!-- Changes that improve Black's performance. -->
|
<!-- Changes that improve Black's performance. -->
|
||||||
|
@ -608,6 +608,12 @@ def generate_tokens(
|
|||||||
except StopIteration:
|
except StopIteration:
|
||||||
line = ""
|
line = ""
|
||||||
lnum += 1
|
lnum += 1
|
||||||
|
|
||||||
|
# skip lines that are just indent characters ending with a slash
|
||||||
|
# to avoid storing that line's indent information.
|
||||||
|
if not contstr and line.rstrip("\n").strip(" \t\f") == "\\":
|
||||||
|
continue
|
||||||
|
|
||||||
pos, max = 0, len(line)
|
pos, max = 0, len(line)
|
||||||
|
|
||||||
if contstr: # continued string
|
if contstr: # continued string
|
||||||
|
24
tests/data/cases/backslash_before_indent.py
Normal file
24
tests/data/cases/backslash_before_indent.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# flags: --minimum-version=3.10
|
||||||
|
class Plotter:
|
||||||
|
\
|
||||||
|
pass
|
||||||
|
|
||||||
|
class AnotherCase:
|
||||||
|
\
|
||||||
|
"""Some
|
||||||
|
\
|
||||||
|
Docstring
|
||||||
|
"""
|
||||||
|
|
||||||
|
# output
|
||||||
|
|
||||||
|
class Plotter:
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class AnotherCase:
|
||||||
|
"""Some
|
||||||
|
\
|
||||||
|
Docstring
|
||||||
|
"""
|
@ -14,5 +14,7 @@ def bob(): # pylint: disable=W9016
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def bobtwo(): # some comment here
|
def bobtwo():
|
||||||
|
|
||||||
|
# some comment here
|
||||||
pass
|
pass
|
||||||
|
@ -156,6 +156,7 @@ def something(self):
|
|||||||
|
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user