Skip to content

Commit cb17d27

Browse files
committed
Correctly report E501 when the first line of a docstring is too long
Resolves #622
1 parent f1908ba commit cb17d27

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

pycodestyle.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,7 @@ def comparison_type(logical_line, noqa):
11991199

12001200

12011201
def bare_except(logical_line, noqa):
1202-
r"""When catching exceptions, mention specific exceptions whenever possible.
1202+
r"""When catching exceptions, mention specific exceptions when possible.
12031203
12041204
Okay: except Exception:
12051205
Okay: except BaseException:
@@ -1727,7 +1727,9 @@ def maybe_check_physical(self, token):
17271727
return
17281728
self.multiline = True
17291729
self.line_number = token[2][0]
1730-
for line in token[1].split('\n')[:-1]:
1730+
_, src, (_, offset), _, _ = token
1731+
src = self.lines[self.line_number - 1][:offset] + src
1732+
for line in src.split('\n')[:-1]:
17311733
self.check_physical(line + '\n')
17321734
self.line_number += 1
17331735
self.multiline = False

testsuite/E50.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@
8282
#: E501
8383
"""
8484
longnospaceslongnospaceslongnospaceslongnospaceslongnospaceslongnospaceslongnospaceslongnospaces"""
85+
#: E501
86+
# Regression test for #622
87+
def foo():
88+
"""Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis pulvinar vitae
89+
"""
8590
#: Okay
8691
"""
8792
This

0 commit comments

Comments
 (0)