Skip to content

Commit f7a9648

Browse files
committed
Allow backslash to end a line if within inline comment; issue #374
1 parent 5100035 commit f7a9648

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ Changes:
3636

3737
* Allow spaces around the equals sign in an annotated function. (Issue #357)
3838

39+
* Allow trailing backslash if in an inline comment. (Issue #374)
40+
3941
Bug fixes:
4042

4143
* Don't crash if Checker.build_tokens_line() returns None. (Issue #306)

pep8.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,10 +972,14 @@ def explicit_line_join(logical_line, tokens):
972972
Okay: aaa = [123,\n 123]
973973
Okay: aaa = ("bbb "\n "ccc")
974974
Okay: aaa = "bbb " \\n "ccc"
975+
Okay: aaa = 123 # \\
975976
"""
976977
prev_start = prev_end = parens = 0
978+
comment = False
977979
for token_type, text, start, end, line in tokens:
978-
if start[0] != prev_start and parens and backslash:
980+
if token_type == tokenize.COMMENT:
981+
comment = True
982+
if start[0] != prev_start and parens and backslash and not comment:
979983
yield backslash, "E502 the backslash is redundant between brackets"
980984
if end[0] != prev_end:
981985
if line.rstrip('\r\n').endswith('\\'):

0 commit comments

Comments
 (0)