Skip to content

Commit

Permalink
Fix E225: reject True+False when running on Python 3.
Browse files Browse the repository at this point in the history
  • Loading branch information
florentx committed Mar 15, 2010
1 parent 45c02d7 commit 4abc33b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Expand Up @@ -7,6 +7,8 @@ Changelog

* Performance improvements.

* Fix E225: reject ``True+False`` when running on Python 3.

* Fix an exception when the line starts with an operator.

* Allow a new line before closing ``)``, ``}`` or ``]``. (Issue #5)
Expand Down
19 changes: 13 additions & 6 deletions pep8.py
Expand Up @@ -99,9 +99,9 @@ def blank_lines(logical_line, blank_lines, indent_level, line_number)
import re
import time
import inspect
import keyword
import tokenize
from optparse import OptionParser
from keyword import iskeyword
from fnmatch import fnmatch
try:
frozenset
Expand Down Expand Up @@ -132,6 +132,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) - frozenset(['False', 'None', 'True'])

options = None
args = None
Expand Down Expand Up @@ -383,7 +385,7 @@ def whitespace_before_parameters(logical_line, tokens):
start != prev_end and
prev_type == tokenize.NAME and
(index < 2 or tokens[index - 2][1] != 'class') and
(not iskeyword(prev_text))):
(not keyword.iskeyword(prev_text))):
return prev_end, "E211 whitespace before '%s'" % text
prev_type = token_type
prev_text = text
Expand Down Expand Up @@ -472,10 +474,15 @@ def missing_whitespace_around_operator(logical_line, tokens):
elif text in BINARY_OPERATORS:
need_space = True
elif text in UNARY_OPERATORS:
if ((prev_type != tokenize.OP or prev_text in '}])') and not
(prev_type == tokenize.NAME and iskeyword(prev_text))):
# Allow unary operators: -123, -x, +1.
# Allow argument unpacking: foo(*args, **kwargs).
# Allow unary operators: -123, -x, +1.
# Allow argument unpacking: foo(*args, **kwargs).
if prev_type == tokenize.OP:
if prev_text in '}])':
need_space = True
elif prev_type == tokenize.NAME:
if prev_text not in E225NOT_KEYWORDS:
need_space = True
else:
need_space = True
if need_space and start == prev_end:
return prev_end, "E225 missing whitespace around operator"
Expand Down
1 change: 1 addition & 0 deletions testsuite/E225h.py
@@ -0,0 +1 @@
norman = True+False

0 comments on commit 4abc33b

Please sign in to comment.