parameters: (logical_line, tokens)
docstring: r"""
      - Always surround these binary operators with a single space on
        either side: assignment (=), augmented assignment (+=, -= etc.),
        comparisons (==, <, >, !=, <>, <=, >=, in, not in, is, is not),
        Booleans (and, or, not).
  
      - Use spaces around arithmetic operators.
  
      Okay: i = i + 1
      Okay: submitted += 1
      Okay: x = x * 2 - 1
      Okay: hypot2 = x * x + y * y
      Okay: c = (a + b) * (a - b)
      Okay: foo(bar, key='word', *args, **kwargs)
      Okay: baz(**kwargs)
      Okay: negative = -1
      Okay: spam(-1)
      Okay: alpha[:-i]
      Okay: if not -5 < x < +5:\n    pass
      Okay: lambda *args, **kw: (args, kw)
  
      E225: i=i+1
      E225: submitted +=1
      E225: x = x*2 - 1
      E225: hypot2 = x*x + y*y
      E225: c = (a+b) * (a-b)
      E225: c = alpha -4
      E225: z = x **y
docstring_summary: r"""
      - Always surround these binary operators with a single space on
        either side: assignment (=), augmented assignment (+=, -= etc.),
        comparisons (==, <, >, !=, <>, <=, >=, in, not in, is, is not),
        Booleans (and, or, not).
docstring_tokens: r - Always surround these binary operators with a single space on either side : assignment ( = ) augmented assignment ( + = - = etc . ) comparisons ( == < > ! = < > < = > = in not in is is not ) Booleans ( and or not ) .
function: def missing_whitespace_around_operator(logical_line, tokens):
      r"""
      - Always surround these binary operators with a single space on
        either side: assignment (=), augmented assignment (+=, -= etc.),
        comparisons (==, <, >, !=, <>, <=, >=, in, not in, is, is not),
        Booleans (and, or, not).
  
      - Use spaces around arithmetic operators.
  
      Okay: i = i + 1
      Okay: submitted += 1
      Okay: x = x * 2 - 1
      Okay: hypot2 = x * x + y * y
      Okay: c = (a + b) * (a - b)
      Okay: foo(bar, key='word', *args, **kwargs)
      Okay: baz(**kwargs)
      Okay: negative = -1
      Okay: spam(-1)
      Okay: alpha[:-i]
      Okay: if not -5 < x < +5:\n    pass
      Okay: lambda *args, **kw: (args, kw)
  
      E225: i=i+1
      E225: submitted +=1
      E225: x = x*2 - 1
      E225: hypot2 = x*x + y*y
      E225: c = (a+b) * (a-b)
      E225: c = alpha -4
      E225: z = x **y
      """
      parens = 0
      need_space = False
      prev_type = tokenize.OP
      prev_text = prev_end = None
      for token_type, text, start, end, line in tokens:
          if token_type in (tokenize.NL, tokenize.NEWLINE, tokenize.ERRORTOKEN):
              # ERRORTOKEN is triggered by backticks in Python 3000
              continue
          if text in ('(', 'lambda'):
              parens += 1
          elif text == ')':
              parens -= 1
          if need_space:
              if start != prev_end:
                  need_space = False
              elif text == '>' and prev_text == '<':
                  # Tolerate the "<>" operator, even if running Python 3
                  pass
              else:
                  return prev_end, "E225 missing whitespace around operator"
          elif token_type == tokenize.OP and prev_end is not None:
              if text == '=' and parens:
                  # Allow keyword args or defaults: foo(bar=None).
                  pass
              elif text in BINARY_OPERATORS:
                  need_space = True
              elif text in UNARY_OPERATORS:
                  # 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"
          prev_type = token_type
          prev_text = text
          prev_end = end
function_tokens: def missing_whitespace_around_operator ( logical_line , tokens ) : parens = 0 need_space = False prev_type = tokenize . OP prev_text = prev_end = None for token_type , text , start , end , line in tokens : if token_type in ( tokenize . NL , tokenize . NEWLINE , tokenize . ERRORTOKEN ) : # ERRORTOKEN is triggered by backticks in Python 3000 continue if text in ( '(' , 'lambda' ) : parens += 1 elif text == ')' : parens -= 1 if need_space : if start != prev_end : need_space = False elif text == '>' and prev_text == '<' : # Tolerate the "<>" operator, even if running Python 3 pass else : return prev_end , "E225 missing whitespace around operator" elif token_type == tokenize . OP and prev_end is not None : if text == '=' and parens : # Allow keyword args or defaults: foo(bar=None). pass elif text in BINARY_OPERATORS : need_space = True elif text in UNARY_OPERATORS : # 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" prev_type = token_type prev_text = text prev_end = end