Skip to content

Commit ddebc11

Browse files
committed
Report E266 instead of E265 when the block common starts with multiple #; issue #270
1 parent a176b77 commit ddebc11

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ Bug fixes:
99

1010
* Skip the traceback on "Broken pipe" signal. (Issue #275)
1111

12+
* Report E266 instead of E265 when the block comment starts with
13+
multiple ``#``. (Issue #270)
14+
1215

1316
1.5.6 (2014-04-14)
1417
------------------

docs/intro.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ This is the current list of error and warning codes:
263263
+----------+----------------------------------------------------------------------+
264264
| E265 | block comment should start with '# ' |
265265
+----------+----------------------------------------------------------------------+
266+
| E266 | too many leading '#' for block comment |
267+
+----------+----------------------------------------------------------------------+
266268
+----------+----------------------------------------------------------------------+
267269
| E271 | multiple spaces after keyword |
268270
+----------+----------------------------------------------------------------------+

pep8.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,7 @@ def whitespace_before_comment(logical_line, tokens):
787787
E262: x = x + 1 #Increment x
788788
E262: x = x + 1 # Increment x
789789
E265: #Block comment
790+
E266: ### Block comment
790791
"""
791792
prev_end = (0, 0)
792793
for token_type, text, start, end, line in tokens:
@@ -797,13 +798,15 @@ def whitespace_before_comment(logical_line, tokens):
797798
yield (prev_end,
798799
"E261 at least two spaces before inline comment")
799800
symbol, sp, comment = text.partition(' ')
800-
bad_prefix = symbol not in ('#', '#:')
801+
bad_prefix = symbol not in '#:' and (symbol.lstrip('#')[:1] or '#')
801802
if inline_comment:
802-
if bad_prefix or comment[:1].isspace():
803+
if bad_prefix or comment[:1] in WHITESPACE:
803804
yield start, "E262 inline comment should start with '# '"
804-
elif bad_prefix:
805-
if text.rstrip('#') and (start[0] > 1 or symbol[1] != '!'):
805+
elif bad_prefix and (bad_prefix != '!' or start[0] > 1):
806+
if bad_prefix != '#':
806807
yield start, "E265 block comment should start with '# '"
808+
elif comment:
809+
yield start, "E266 too many leading '#' for block comment"
807810
elif token_type != tokenize.NL:
808811
prev_end = end
809812

testsuite/E26.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@
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)