summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Ward <greg@gerg.ca>2013-11-08 15:04:39 -0500
committerGreg Ward <greg@gerg.ca>2013-11-08 16:21:23 -0500
commit5d24e16b633904135f42fbba2a4bc390e5d15a85 (patch)
tree3539740daf3b2c8c639f6f29a5d05428ab8676d4
parent66d353dd2e68197d6c168f188bfad68b6f738908 (diff)
downloadpep8-5d24e16b633904135f42fbba2a4bc390e5d15a85.tar.gz
Allow long lines in multiline strings if they cannot be wrapped (issue #224).
-rwxr-xr-xpep8.py9
-rw-r--r--testsuite/E50.py12
2 files changed, 20 insertions, 1 deletions
diff --git a/pep8.py b/pep8.py
index ce3feb0..032afc1 100755
--- a/pep8.py
+++ b/pep8.py
@@ -200,7 +200,7 @@ def missing_newline(physical_line):
return len(physical_line), "W292 no newline at end of file"
-def maximum_line_length(physical_line, max_line_length):
+def maximum_line_length(physical_line, max_line_length, multiline):
"""
Limit all lines to a maximum of 79 characters.
@@ -216,6 +216,10 @@ def maximum_line_length(physical_line, max_line_length):
line = physical_line.rstrip()
length = len(line)
if length > max_line_length and not noqa(line):
+ # Sometimes, long lines in docstrings are hard to avoid -- like,
+ # a long URL that can't be wrapped because it has no whitespace.
+ if multiline and re.match(r'^\s*\S+$', line):
+ return
if hasattr(line, 'decode'): # Python 2
# The line could contain multi-byte characters
try:
@@ -1187,6 +1191,7 @@ class Checker(object):
self._logical_checks = options.logical_checks
self._ast_checks = options.ast_checks
self.max_line_length = options.max_line_length
+ self.multiline = False # in a multiline string?
self.hang_closing = options.hang_closing
self.verbose = options.verbose
self.filename = filename
@@ -1358,10 +1363,12 @@ class Checker(object):
# *not* check the last line: its newline is outside of the
# multiline string, so we consider it a regular physical line
# (it will be checked when we see the newline token).
+ self.multiline = True
self.line_number = token[2][0]
for line in token[1].split('\n')[:-1]:
self.check_physical(line + '\n')
self.line_number += 1
+ self.multiline = False
elif token[0] in (tokenize.NEWLINE, tokenize.NL):
self.check_physical(token[4])
diff --git a/testsuite/E50.py b/testsuite/E50.py
index 1fc95ff..5737e95 100644
--- a/testsuite/E50.py
+++ b/testsuite/E50.py
@@ -45,6 +45,8 @@ ddd = \
('''
''' + ' \
')
+#: E501 E225 E226
+very_long_identifiers=and_terrible_whitespace_habits(are_no_excuse+for_long_lines)
#
#: E501
'''multiline string
@@ -53,3 +55,13 @@ with a long long long long long long long long long long long long long long lon
#: E501
'''same thing, but this time without a terminal newline in the string
long long long long long long long long long long long long long long long long line'''
+#
+# issue 224 (unavoidable long lines in docstrings)
+#: Okay
+"""
+I'm some great documentation. Because I'm some great documentation, I'm
+going to give you a reference to some valuable information about some API
+that I'm calling:
+
+ http://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx
+"""