Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tokenizer: skip lines that are just slash and whitespace #4343

Merged
merged 8 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ Multiple contributions by:
- [Tony Narlock](mailto:tony@git-pull.com)
- [Tsuyoshi Hombashi](mailto:tsuyoshi.hombashi@gmail.com)
- [Tushar Chandra](mailto:tusharchandra2018@u.northwestern.edu)
- [Tushar Sadhwani](mailto:tushar.sadhwani000@gmail.com)
- [Tzu-ping Chung](mailto:uranusjr@gmail.com)
- [Utsav Shah](mailto:ukshah2@illinois.edu)
- utsav-dbx
Expand Down
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
- Fix regression where Black failed to parse a multiline f-string containing another
multiline string (#4339)

- Fix bug with Black incorrectly parsing empty lines with a backslash (#4343)

### Performance

<!-- Changes that improve Black's performance. -->
Expand Down
6 changes: 6 additions & 0 deletions src/blib2to3/pgen2/tokenize.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,12 @@ def generate_tokens(
except StopIteration:
line = ""
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)

if contstr: # continued string
Expand Down
24 changes: 24 additions & 0 deletions tests/data/cases/backslash_before_indent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# flags: --minimum-version=3.10
class Plotter:
\
pass

class AnotherCase:
\
"""Some
\
Docstring
"""

# output

class Plotter:

pass


class AnotherCase:
"""Some
\
Docstring
"""
4 changes: 3 additions & 1 deletion tests/data/cases/comment_after_escaped_newline.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ def bob(): # pylint: disable=W9016
pass


def bobtwo(): # some comment here
def bobtwo():
JelleZijlstra marked this conversation as resolved.
Show resolved Hide resolved

# some comment here
pass
1 change: 1 addition & 0 deletions tests/data/cases/form_feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def something(self):

#


Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just a \n

#
pass

Expand Down