Skip to content

Commit f0ce4dc

Browse files
authored
Merge pull request #1035 from Pierre-Sassoulas/false-negative-e262-with-non-breaking-whitespace
Properly warn for E262 with non breaking whitespaces
2 parents 598092f + 59854e1 commit f0ce4dc

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

docs/intro.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,9 @@ This is the current list of error and warning codes:
406406
+------------+----------------------------------------------------------------------+
407407
| **W5** | *Line break warning* |
408408
+------------+----------------------------------------------------------------------+
409-
| W503 (*)   | line break before binary operator                         |
409+
| W503 (*) | line break before binary operator |
410410
+------------+----------------------------------------------------------------------+
411-
| W504 (*)   | line break after binary operator                         |
411+
| W504 (*) | line break after binary operator |
412412
+------------+----------------------------------------------------------------------+
413413
| W505 (\*^) | doc line too long (82 > 79 characters) |
414414
+------------+----------------------------------------------------------------------+

pycodestyle.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def lru_cache(maxsize=128): # noqa as it's a fake implementation.
126126
'%=', '^=', '&=', '|=', '==', '<=', '>=', '<<=', '>>=', '=',
127127
'and', 'in', 'is', 'or', '->'] +
128128
ASSIGNMENT_EXPRESSION_OP)
129-
WHITESPACE = frozenset(' \t')
129+
WHITESPACE = frozenset(' \t\xa0')
130130
NEWLINE = frozenset([tokenize.NL, tokenize.NEWLINE])
131131
SKIP_TOKENS = NEWLINE.union([tokenize.INDENT, tokenize.DEDENT])
132132
# ERRORTOKEN is triggered by backticks in Python 3
@@ -1056,21 +1056,24 @@ def whitespace_around_named_parameter_equals(logical_line, tokens):
10561056

10571057
@register_check
10581058
def whitespace_before_comment(logical_line, tokens):
1059-
r"""Separate inline comments by at least two spaces.
1059+
"""Separate inline comments by at least two spaces.
10601060
10611061
An inline comment is a comment on the same line as a statement.
10621062
Inline comments should be separated by at least two spaces from the
10631063
statement. They should start with a # and a single space.
10641064
1065-
Each line of a block comment starts with a # and a single space
1066-
(unless it is indented text inside the comment).
1065+
Each line of a block comment starts with a # and one or multiple
1066+
spaces as there can be indented text inside the comment.
10671067
10681068
Okay: x = x + 1 # Increment x
10691069
Okay: x = x + 1 # Increment x
1070-
Okay: # Block comment
1070+
Okay: # Block comments:
1071+
Okay: # - Block comment list
1072+
Okay: # \xa0- Block comment list
10711073
E261: x = x + 1 # Increment x
10721074
E262: x = x + 1 #Increment x
10731075
E262: x = x + 1 # Increment x
1076+
E262: x = x + 1 # \xa0Increment x
10741077
E265: #Block comment
10751078
E266: ### Block comment
10761079
"""

testsuite/E26.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,10 @@ def oof():
5757
# ################################################################ #
5858
# ####################### another separator ###################### #
5959
# ################################################################ #
60+
#: E262:3:9
61+
# -*- coding: utf8 -*-
62+
#  (One space one NBSP) Ok for block comment
63+
a = 42 #  (One space one NBSP)
64+
#: E262:2:9
65+
# (Two spaces) Ok for block comment
66+
a = 42 # (Two spaces)

0 commit comments

Comments
 (0)