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.py23
4 files changed, 35 insertions, 4 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index e12f89d..e44ef4f 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -9,6 +9,9 @@ Bug fixes:
* Skip the traceback on "Broken pipe" signal. (Issue #275)
+* Report E266 instead of E265 when the block comment starts with
+ multiple ``#``. (Issue #270)
+
1.5.6 (2014-04-14)
------------------
diff --git a/docs/intro.rst b/docs/intro.rst
index 018521d..c0ed737 100644
--- a/docs/intro.rst
+++ b/docs/intro.rst
@@ -263,6 +263,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 a254716..ac6bfed 100755
--- a/pep8.py
+++ b/pep8.py
@@ -787,6 +787,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:
@@ -797,13 +798,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..9971f13 100644
--- a/testsuite/E26.py
+++ b/testsuite/E26.py
@@ -13,6 +13,21 @@ a = 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 ########################## #
+ # ####################################################################### #