@@ -200,7 +200,7 @@ def missing_newline(physical_line):
200200 return len (physical_line ), "W292 no newline at end of file"
201201
202202
203- def maximum_line_length (physical_line , max_line_length ):
203+ def maximum_line_length (physical_line , max_line_length , multiline ):
204204 """
205205 Limit all lines to a maximum of 79 characters.
206206
@@ -216,6 +216,10 @@ def maximum_line_length(physical_line, max_line_length):
216216 line = physical_line .rstrip ()
217217 length = len (line )
218218 if length > max_line_length and not noqa (line ):
219+ # Sometimes, long lines in docstrings are hard to avoid -- like,
220+ # a long URL that can't be wrapped because it has no whitespace.
221+ if multiline and re .match (r'^\s*\S+$' , line ):
222+ return
219223 if hasattr (line , 'decode' ): # Python 2
220224 # The line could contain multi-byte characters
221225 try :
@@ -1187,6 +1191,7 @@ def __init__(self, filename=None, lines=None,
11871191 self ._logical_checks = options .logical_checks
11881192 self ._ast_checks = options .ast_checks
11891193 self .max_line_length = options .max_line_length
1194+ self .multiline = False # in a multiline string?
11901195 self .hang_closing = options .hang_closing
11911196 self .verbose = options .verbose
11921197 self .filename = filename
@@ -1358,10 +1363,12 @@ def maybe_check_physical(self, token):
13581363 # *not* check the last line: its newline is outside of the
13591364 # multiline string, so we consider it a regular physical line
13601365 # (it will be checked when we see the newline token).
1366+ self .multiline = True
13611367 self .line_number = token [2 ][0 ]
13621368 for line in token [1 ].split ('\n ' )[:- 1 ]:
13631369 self .check_physical (line + '\n ' )
13641370 self .line_number += 1
1371+ self .multiline = False
13651372 elif token [0 ] in (tokenize .NEWLINE , tokenize .NL ):
13661373 self .check_physical (token [4 ])
13671374
0 commit comments