def whitespace_around_named_parameter_equals(logical_line, tokens):
 parens = 0
 no_space = False
 prev_end = None
 annotated_func_arg = False
 in_def = logical_line.startswith('def')
 message = 'E251 unexpected spaces around keyword / parameter equals'
 for (token_type, text, start, end, line) in tokens:
  if (token_type == tokenize.NL):
   continue
  if no_space:
   no_space = False
   if (start != prev_end):
    (yield (prev_end, message))
  if (token_type == tokenize.OP):
   if (text == '('):
    parens += 1
   elif (text == ')'):
    parens -= 1
   elif (in_def and (text == ':') and (parens == 1)):
    annotated_func_arg = True
   elif (parens and (text == ',') and (parens == 1)):
    annotated_func_arg = False
   elif (parens and (text == '=') and (not annotated_func_arg)):
    no_space = True
    if (start != prev_end):
     (yield (prev_end, message))
   if (not parens):
    annotated_func_arg = False
  prev_end = end

def whitespace_around_named_parameter_equals ( logical_line , tokens ) : parens = 0 no_space = False prev_end = None annotated_func_arg = False in_def = logical_line . startswith ( 'def' ) message = 'E251 unexpected spaces around keyword / parameter equals' for ( token_type , text , start , end , line ) in tokens : if ( token_type == tokenize . NL ) : continue if no_space : no_space = False if ( start != prev_end ) : ( yield ( prev_end , message ) ) if ( token_type == tokenize . OP ) : if ( text == '(' ) : parens += 1 elif ( text == ')' ) : parens -= 1 elif ( in_def and ( text == ':' ) and ( parens == 1 ) ) : annotated_func_arg = True elif ( parens and ( text == ',' ) and ( parens == 1 ) ) : annotated_func_arg = False elif ( parens and ( text == '=' ) and ( not annotated_func_arg ) ) : no_space = True if ( start != prev_end ) : ( yield ( prev_end , message ) ) if ( not parens ) : annotated_func_arg = False prev_end = end
dont use spaces around the = sign in function arguments .