summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2021-11-06 12:49:48 +0100
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2021-11-09 09:21:36 +0100
commit59854e1caa96d31a5e100a7a3edbe32cf8fc5209 (patch)
treed704f04f7313bc7a8b3bc90ec1c7b745c7b1706a
parentfaa9a4bb62b9466e5b0b98288097f1d47bf773f4 (diff)
downloadpep8-59854e1caa96d31a5e100a7a3edbe32cf8fc5209.tar.gz
Properly warn for E262 with non breaking whitespaces
Closes #1034
-rwxr-xr-xpycodestyle.py7
-rw-r--r--testsuite/E26.py7
2 files changed, 11 insertions, 3 deletions
diff --git a/pycodestyle.py b/pycodestyle.py
index e0c9e42..b839e35 100755
--- a/pycodestyle.py
+++ b/pycodestyle.py
@@ -126,7 +126,7 @@ WS_NEEDED_OPERATORS = frozenset([
'%=', '^=', '&=', '|=', '==', '<=', '>=', '<<=', '>>=', '=',
'and', 'in', 'is', 'or', '->'] +
ASSIGNMENT_EXPRESSION_OP)
-WHITESPACE = frozenset(' \t')
+WHITESPACE = frozenset(' \t\xa0')
NEWLINE = frozenset([tokenize.NL, tokenize.NEWLINE])
SKIP_TOKENS = NEWLINE.union([tokenize.INDENT, tokenize.DEDENT])
# ERRORTOKEN is triggered by backticks in Python 3
@@ -1056,7 +1056,7 @@ def whitespace_around_named_parameter_equals(logical_line, tokens):
@register_check
def whitespace_before_comment(logical_line, tokens):
- r"""Separate inline comments by at least two spaces.
+ """Separate inline comments by at least two spaces.
An inline comment is a comment on the same line as a statement.
Inline comments should be separated by at least two spaces from the
@@ -1069,10 +1069,11 @@ def whitespace_before_comment(logical_line, tokens):
Okay: x = x + 1 # Increment x
Okay: # Block comments:
Okay: # - Block comment list
- Okay: #  - Block comment list
+ Okay: # \xa0- Block comment list
E261: x = x + 1 # Increment x
E262: x = x + 1 #Increment x
E262: x = x + 1 # Increment x
+ E262: x = x + 1 # \xa0Increment x
E265: #Block comment
E266: ### Block comment
"""
diff --git a/testsuite/E26.py b/testsuite/E26.py
index c3537ff..937ef72 100644
--- a/testsuite/E26.py
+++ b/testsuite/E26.py
@@ -57,3 +57,10 @@ def oof():
# ################################################################ #
# ####################### another separator ###################### #
# ################################################################ #
+#: E262:3:9
+# -*- coding: utf8 -*-
+#  (One space one NBSP) Ok for block comment
+a = 42 #  (One space one NBSP)
+#: E262:2:9
+# (Two spaces) Ok for block comment
+a = 42 # (Two spaces)