|
81 | 81 | SINGLETONS = frozenset(['False', 'None', 'True']) |
82 | 82 | KEYWORDS = frozenset(keyword.kwlist + ['print']) - SINGLETONS |
83 | 83 | UNARY_OPERATORS = frozenset(['>>', '**', '*', '+', '-']) |
84 | | -WS_OPTIONAL_OPERATORS = frozenset(['**', '*', '/', '//', '+', '-']) |
| 84 | +ARITHMETIC_OP = frozenset(['**', '*', '/', '//', '+', '-']) |
| 85 | +WS_OPTIONAL_OPERATORS = ARITHMETIC_OP.union(['^', '&', '|', '<<', '>>', '%']) |
85 | 86 | WS_NEEDED_OPERATORS = frozenset([ |
86 | | - '**=', '*=', '/=', '//=', '+=', '-=', '!=', '<>', |
87 | | - '%=', '^=', '&=', '|=', '==', '<=', '>=', '<<=', '>>=', |
88 | | - '%', '^', '&', '|', '=', '<', '>', '<<']) |
| 87 | + '**=', '*=', '/=', '//=', '+=', '-=', '!=', '<>', '<', '>', |
| 88 | + '%=', '^=', '&=', '|=', '==', '<=', '>=', '<<=', '>>=', '=']) |
89 | 89 | WHITESPACE = frozenset(' \t') |
90 | 90 | SKIP_TOKENS = frozenset([tokenize.COMMENT, tokenize.NL, tokenize.NEWLINE, |
91 | 91 | tokenize.INDENT, tokenize.DEDENT]) |
@@ -626,25 +626,16 @@ def missing_whitespace_around_operator(logical_line, tokens): |
626 | 626 | Okay: hypot2 = x * x + y * y |
627 | 627 | Okay: c = (a + b) * (a - b) |
628 | 628 | Okay: foo(bar, key='word', *args, **kwargs) |
629 | | - Okay: baz(**kwargs) |
630 | | - Okay: negative = -1 |
631 | | - Okay: spam(-1) |
632 | 629 | Okay: alpha[:-i] |
633 | | - Okay: if not -5 < x < +5:\n pass |
634 | | - Okay: lambda *args, **kw: (args, kw) |
635 | | - Okay: z = 2 ** 30 |
636 | | - Okay: x = x / 2 - 1 |
637 | 630 |
|
638 | 631 | E225: i=i+1 |
639 | 632 | E225: submitted +=1 |
640 | | - E225: c = alpha -4 |
641 | 633 | E225: x = x /2 - 1 |
642 | 634 | E225: z = x **y |
643 | 635 | E226: c = (a+b) * (a-b) |
644 | | - E226: z = 2**30 |
645 | | - E226: x = x*2 - 1 |
646 | | - E226: x = x/2 - 1 |
647 | 636 | E226: hypot2 = x*x + y*y |
| 637 | + E227: c = a|b |
| 638 | + E228: msg = fmt%(errno, errmsg) |
648 | 639 | """ |
649 | 640 | parens = 0 |
650 | 641 | need_space = False |
@@ -674,8 +665,13 @@ def missing_whitespace_around_operator(logical_line, tokens): |
674 | 665 | # A needed trailing space was not found |
675 | 666 | yield prev_end, "E225 missing whitespace around operator" |
676 | 667 | else: |
677 | | - yield (need_space[0], |
678 | | - "E226 missing optional whitespace around operator") |
| 668 | + code, optype = 'E226', 'arithmetic' |
| 669 | + if prev_text == '%': |
| 670 | + code, optype = 'E228', 'modulo' |
| 671 | + elif prev_text not in ARITHMETIC_OP: |
| 672 | + code, optype = 'E227', 'bitwise or shift' |
| 673 | + yield (need_space[0], "%s missing whitespace " |
| 674 | + "around %s operator" % (code, optype)) |
679 | 675 | need_space = False |
680 | 676 | elif token_type == tokenize.OP and prev_end is not None: |
681 | 677 | if text == '=' and parens: |
|
0 commit comments