Skip to content

Commit 59854e1

Browse files
Properly warn for E262 with non breaking whitespaces
Closes #1034
1 parent faa9a4b commit 59854e1

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

pycodestyle.py

Lines changed: 4 additions & 3 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,7 +1056,7 @@ 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
@@ -1069,10 +1069,11 @@ def whitespace_before_comment(logical_line, tokens):
10691069
Okay: x = x + 1 # Increment x
10701070
Okay: # Block comments:
10711071
Okay: # - Block comment list
1072-
Okay: #  - Block comment list
1072+
Okay: # \xa0- Block comment list
10731073
E261: x = x + 1 # Increment x
10741074
E262: x = x + 1 #Increment x
10751075
E262: x = x + 1 # Increment x
1076+
E262: x = x + 1 # \xa0Increment x
10761077
E265: #Block comment
10771078
E266: ### Block comment
10781079
"""

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)