Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: jcrocholl/pep8
...
head fork: jcrocholl/pep8
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 2 contributors
Commits on Apr 30, 2012
Rick Harris rconradharris Avoid extraneous whitespace around keywords.
Fixes #57
341d13a
Commits on May 23, 2012
Florent Xicluna florentx Merge pull request #58 from rconradharris/keyword_whitespace
Avoid extraneous whitespace around keywords.
742178e
Showing with 36 additions and 2 deletions.
  1. +26 −2 pep8.py
  2. +10 −0 testsuite/E27.py
28 pep8.py
View
@@ -121,6 +121,8 @@ def blank_lines(logical_line, blank_lines, indent_level, line_number)
DOCSTRING_REGEX = re.compile(r'u?r?["\']')
WHITESPACE_AROUND_OPERATOR_REGEX = \
re.compile('([^\w\s]*)\s*(\t| )\s*([^\w\s]*)')
+WHITESPACE_AROUND_KEYWORD_REGEX = \
+ re.compile('([^\s]*)\s*(\t| )\s*([^\s]*)')
EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),;:]')
WHITESPACE_AROUND_NAMED_PARAMETER_REGEX = \
re.compile(r'[()]|\s=[^=]|[^=!<>]=\s')
@@ -136,8 +138,8 @@ def blank_lines(logical_line, blank_lines, indent_level, line_number)
OPERATORS = BINARY_OPERATORS | UNARY_OPERATORS
SKIP_TOKENS = frozenset([tokenize.COMMENT, tokenize.NL, tokenize.INDENT,
tokenize.DEDENT, tokenize.NEWLINE])
-E225NOT_KEYWORDS = (frozenset(keyword.kwlist + ['print']) -
- frozenset(['False', 'None', 'True']))
+KEYWORDS = frozenset(keyword.kwlist + ['print'])
+E225NOT_KEYWORDS = KEYWORDS - frozenset(['False', 'None', 'True'])
BENCHMARK_KEYS = ('directories', 'files', 'logical lines', 'physical lines')
options = None
@@ -338,6 +340,28 @@ def extraneous_whitespace(logical_line):
return found, "E203 whitespace before '%s'" % char
+def whitespace_around_keywords(logical_line):
+ """
+ Avoid extraneous whitespace around keywords.
+
+ Okay: True and False
+ E271: True and False
+ E272: True and False
+ E273: True and\tFalse
+ E274: True\tand False
+ """
+ for match in WHITESPACE_AROUND_KEYWORD_REGEX.finditer(logical_line):
+ before, whitespace, after = match.groups()
+ tab = whitespace == '\t'
+ offset = match.start(2)
+ if before in KEYWORDS:
+ return offset, (tab and "E273 tab after keyword" or
+ "E271 multiple spaces after keyword")
+ elif after in KEYWORDS:
+ return offset, (tab and "E274 tab before keyword" or
+ "E272 multiple spaces before keyword")
+
+
def missing_whitespace(logical_line):
"""
JCR: Each comma, semicolon or colon should be followed by whitespace.
10 testsuite/E27.py
View
@@ -0,0 +1,10 @@
+#: Okay
+True and False
+#: E271
+True and False
+#: E272
+True and False
+#: E273
+True and False
+#: E274
+True and False

No commit comments for this range

Something went wrong with that request. Please try again.