Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Allow multi-line comments between logical blocks (E302) #10

Closed
florentx opened this Issue · 4 comments

2 participants

@florentx

(I've added it as comment of ticket #1, but ticket is closed)

Such code gives an error E302:

def a():
    pass


# Foo
# Bar

def b():
    pass

We should allow multi-line comments between sections (a.k.a Block Comments in PEP 8).
It is enough to find 2 successive blank lines somewhere before or after the block comments to satisfy the PEP8 requirement for blank lines.

Here is the proposed patch:

--- a/pep8.py      2009-10-20 10:08:22.450102000 +0200
+++ b/pep8.py     2009-10-20 14:51:27.686839248 +0200
@@ -233,6 +233,8 @@
     Use blank lines in functions, sparingly, to indicate logical sections.

     Okay: def a():\n    pass\n\n\ndef b():\n    pass
+    Okay: def a():\n    pass\n\n\n# Foo\n# Bar\n\ndef b():\n    pass
+
     E301: class Foo:\n    def bar():\n        pass
     E302: def a():\n    pass\n\ndef b(n):\n    pass
     E302: def a():\n    pass\n\n\n\ndef b(n):\n    pass
@@ -849,7 +851,8 @@
                 source_line = token[4]
                 token_start = token[2][1]
                 if source_line[:token_start].strip() == '':
-                    self.blank_lines_before_comment = self.blank_lines
+                    self.blank_lines_before_comment = max(self.blank_lines,
+                        self.blank_lines_before_comment)
                     self.blank_lines = 0
                 if text.endswith('\n') and not parens:
                     # The comment also ends a physical line.  This works around
@cburroughs
Owner

florentx could you provide a test case along with the patch?

(It it is easier for you I would be happy to accept pull requests instead of patches.)

@florentx

ok, i pushed the patch in my repo, with additional testcases

@cburroughs
Owner

This branch is ready for review. Testcases included.
It fixes issues #9 and #10 and improve performance by 60%.

Pull request received will review.

@florentx

outdated

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.