Commits

Torsten Marek  committed e7aad70

Emit warnings about lines exceeding the column limit when those lines are inside multiline docstrings.

  • Participants
  • Parent commits 3e994f1

Comments (0)

Files changed (4)

 ====================
 
 --
-   * Do not double-check parameter names with the regex for parameters and
+    * Emit warnings about lines exceeding the column limit when
+      those lines are inside multiline docstrings.
+
+    * Do not double-check parameter names with the regex for parameters and
       inline variables.
 
     * Added a new warning missing-final-newline (C0304) for files missing

File checkers/format.py

         previous = None
         self._lines = {}
         self._visited_lines = {}
+        new_line_delay = False
         for (tok_type, token, start, _, line) in tokens:
+            if new_line_delay:
+                new_line_delay = False
+                self.new_line(tok_type, line, line_num, junk)
             if start[0] != line_num:
                 if previous is not None and previous[0] == tokenize.OP and previous[1] == ';':
                     self.add_message('W0301', line=previous[2])
                 previous = None
                 line_num = start[0]
-                self.new_line(tok_type, line, line_num, junk)
+                # A tokenizer oddity: if an indented line contains a multi-line
+                # docstring, the line member of the INDENT token does not contain
+                # the full line; therefore we delay checking the new line until
+                # the next token.
+                if tok_type == tokenize.INDENT:
+                    new_line_delay = True
+                else:
+                    self.new_line(tok_type, line, line_num, junk)
             if tok_type not in (indent, dedent, newline) + junk:
                 previous = tok_type, token, start[0]
 

File test/input/func_toolonglines.py

 badname = 'This line is already longer than 80 characters even without the pragma.'  # pylint:disable=invalid-name
 
 # http://example.com/this/is/a/very/long/url?but=splitting&urls=is&a=pain&so=they&can=be&long
+
+
+def function():
+    """This is a docstring.
+
+    That contains a very, very long line that exceeds the 80 character limit by a good margin.
+    """
+    pass

File test/messages/func_toolonglines.txt

 C:  2: Line too long (94/80)
 C: 11: Line too long (101/80)
 C: 17: Line too long (83/80)
+C: 25: Line too long (94/80)
 W: 11: Cannot decode using encoding "ascii", unexpected byte at position 37