summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt3
-rw-r--r--docs/intro.rst2
-rwxr-xr-xpep8.py11
-rw-r--r--testsuite/E26.py35
4 files changed, 41 insertions, 10 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 9bd0c74..e18add4 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -12,6 +12,9 @@ Changelog
* Replace codes E111, E112 and E113 with codes E114, E115 and E116
for wrong indentation of comments. (Issue #274)
+* Report E266 instead of E265 when the block comment starts with
+ multiple ``#``. (Issue #270)
+
1.5.7 (2014-05-29)
------------------
diff --git a/docs/intro.rst b/docs/intro.rst
index cdff2ac..88f0000 100644
--- a/docs/intro.rst
+++ b/docs/intro.rst
@@ -270,6 +270,8 @@ This is the current list of error and warning codes:
+----------+----------------------------------------------------------------------+
| E265 | block comment should start with '# ' |
+----------+----------------------------------------------------------------------+
+| E266 | too many leading '#' for block comment |
++----------+----------------------------------------------------------------------+
+----------+----------------------------------------------------------------------+
| E271 | multiple spaces after keyword |
+----------+----------------------------------------------------------------------+
diff --git a/pep8.py b/pep8.py
index fbb2526..b64dfda 100755
--- a/pep8.py
+++ b/pep8.py
@@ -792,6 +792,7 @@ def whitespace_before_comment(logical_line, tokens):
E262: x = x + 1 #Increment x
E262: x = x + 1 # Increment x
E265: #Block comment
+ E266: ### Block comment
"""
prev_end = (0, 0)
for token_type, text, start, end, line in tokens:
@@ -802,13 +803,15 @@ def whitespace_before_comment(logical_line, tokens):
yield (prev_end,
"E261 at least two spaces before inline comment")
symbol, sp, comment = text.partition(' ')
- bad_prefix = symbol not in ('#', '#:')
+ bad_prefix = symbol not in '#:' and (symbol.lstrip('#')[:1] or '#')
if inline_comment:
- if bad_prefix or comment[:1].isspace():
+ if bad_prefix or comment[:1] in WHITESPACE:
yield start, "E262 inline comment should start with '# '"
- elif bad_prefix:
- if text.rstrip('#') and (start[0] > 1 or symbol[1] != '!'):
+ elif bad_prefix and (bad_prefix != '!' or start[0] > 1):
+ if bad_prefix != '#':
yield start, "E265 block comment should start with '# '"
+ elif comment:
+ yield start, "E266 too many leading '#' for block comment"
elif token_type != tokenize.NL:
prev_end = end
diff --git a/testsuite/E26.py b/testsuite/E26.py
index d838e70..509babf 100644
--- a/testsuite/E26.py
+++ b/testsuite/E26.py
@@ -1,18 +1,33 @@
-#: E261
+#: E261:1:5
pass # an inline comment
-#: E262
+#: E262:1:12
x = x + 1 #Increment x
-#: E262
+#: E262:1:12
x = x + 1 # Increment x
-#: E262
+#: E262:1:12
x = y + 1 #: Increment x
-#: E265
+#: E265:1:1
#Block comment
a = 1
-#: E265
+#: E265:2:1
m = 42
#! This is important
mx = 42 - 42
+#: E266:3:5 E266:6:5
+def how_it_feel(r):
+
+ ### This is a variable ###
+ a = 42
+
+ ### Of course it is unused
+ return
+#: E265:1:1 E266:2:1
+##if DEBUG:
+## logging.error()
+#: W291:1:42
+#########################################
+#:
+
#: Okay
#!/usr/bin/env python
@@ -34,3 +49,11 @@ def oof():
"""
#foo not parsed
"""
+
+ ###########################################################################
+ # A SEPARATOR #
+ ###########################################################################
+
+ # ####################################################################### #
+ # ########################## another separator ########################## #
+ # ####################################################################### #