summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2014-05-29 19:33:09 +0200
committerFlorent Xicluna <florent.xicluna@gmail.com>2014-05-29 19:33:09 +0200
commit999e3357c73a48fea6df8a772435af696b3f01c0 (patch)
tree9c2ee84afa40d828b5466496acfa57f6881a2bbf
parent3fbadb7007436c029a3ede4c057ce43171dcd617 (diff)
parentd1c33daa99c1325c16cba857248134008328fc8a (diff)
downloadpep8-999e3357c73a48fea6df8a772435af696b3f01c0.tar.gz
Report E266 instead of E265 when the block common starts with multiple #; issue #270
-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 ########################## #
+ # ####################################################################### #