Skip to content

Commit 999e335

Browse files
committed
Report E266 instead of E265 when the block common starts with multiple #; issue #270
2 parents 3fbadb7 + d1c33da commit 999e335

File tree

4 files changed

+41
-10
lines changed

4 files changed

+41
-10
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ Changelog
1212
* Replace codes E111, E112 and E113 with codes E114, E115 and E116
1313
for wrong indentation of comments. (Issue #274)
1414

15+
* Report E266 instead of E265 when the block comment starts with
16+
multiple ``#``. (Issue #270)
17+
1518

1619
1.5.7 (2014-05-29)
1720
------------------

docs/intro.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ This is the current list of error and warning codes:
270270
+----------+----------------------------------------------------------------------+
271271
| E265 | block comment should start with '# ' |
272272
+----------+----------------------------------------------------------------------+
273+
| E266 | too many leading '#' for block comment |
274+
+----------+----------------------------------------------------------------------+
273275
+----------+----------------------------------------------------------------------+
274276
| E271 | multiple spaces after keyword |
275277
+----------+----------------------------------------------------------------------+

pep8.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,7 @@ def whitespace_before_comment(logical_line, tokens):
792792
E262: x = x + 1 #Increment x
793793
E262: x = x + 1 # Increment x
794794
E265: #Block comment
795+
E266: ### Block comment
795796
"""
796797
prev_end = (0, 0)
797798
for token_type, text, start, end, line in tokens:
@@ -802,13 +803,15 @@ def whitespace_before_comment(logical_line, tokens):
802803
yield (prev_end,
803804
"E261 at least two spaces before inline comment")
804805
symbol, sp, comment = text.partition(' ')
805-
bad_prefix = symbol not in ('#', '#:')
806+
bad_prefix = symbol not in '#:' and (symbol.lstrip('#')[:1] or '#')
806807
if inline_comment:
807-
if bad_prefix or comment[:1].isspace():
808+
if bad_prefix or comment[:1] in WHITESPACE:
808809
yield start, "E262 inline comment should start with '# '"
809-
elif bad_prefix:
810-
if text.rstrip('#') and (start[0] > 1 or symbol[1] != '!'):
810+
elif bad_prefix and (bad_prefix != '!' or start[0] > 1):
811+
if bad_prefix != '#':
811812
yield start, "E265 block comment should start with '# '"
813+
elif comment:
814+
yield start, "E266 too many leading '#' for block comment"
812815
elif token_type != tokenize.NL:
813816
prev_end = end
814817

testsuite/E26.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
1-
#: E261
1+
#: E261:1:5
22
pass # an inline comment
3-
#: E262
3+
#: E262:1:12
44
x = x + 1 #Increment x
5-
#: E262
5+
#: E262:1:12
66
x = x + 1 # Increment x
7-
#: E262
7+
#: E262:1:12
88
x = y + 1 #: Increment x
9-
#: E265
9+
#: E265:1:1
1010
#Block comment
1111
a = 1
12-
#: E265
12+
#: E265:2:1
1313
m = 42
1414
#! This is important
1515
mx = 42 - 42
16+
#: E266:3:5 E266:6:5
17+
def how_it_feel(r):
18+
19+
### This is a variable ###
20+
a = 42
21+
22+
### Of course it is unused
23+
return
24+
#: E265:1:1 E266:2:1
25+
##if DEBUG:
26+
## logging.error()
27+
#: W291:1:42
28+
#########################################
29+
#:
30+
1631
#: Okay
1732
#!/usr/bin/env python
1833

@@ -34,3 +49,11 @@ def oof():
3449
"""
3550
#foo not parsed
3651
"""
52+
53+
###########################################################################
54+
# A SEPARATOR #
55+
###########################################################################
56+
57+
# ####################################################################### #
58+
# ########################## another separator ########################## #
59+
# ####################################################################### #

0 commit comments

Comments
 (0)