diff options
author | Greg Ward <greg@gerg.ca> | 2013-11-08 15:04:39 -0500 |
---|---|---|
committer | Greg Ward <greg@gerg.ca> | 2013-11-08 16:21:23 -0500 |
commit | 5d24e16b633904135f42fbba2a4bc390e5d15a85 (patch) | |
tree | 3539740daf3b2c8c639f6f29a5d05428ab8676d4 | |
parent | 66d353dd2e68197d6c168f188bfad68b6f738908 (diff) | |
download | pep8-5d24e16b633904135f42fbba2a4bc390e5d15a85.tar.gz |
Allow long lines in multiline strings if they cannot be wrapped (issue #224).
-rwxr-xr-x | pep8.py | 9 | ||||
-rw-r--r-- | testsuite/E50.py | 12 |
2 files changed, 20 insertions, 1 deletions
@@ -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 +""" |