@@ -1522,7 +1522,8 @@ def ambiguous_identifier(logical_line, tokens):
15221522 E743: def l(x):
15231523 """
15241524 is_func_def = False # Set to true if 'def' or 'lambda' is found
1525- parameter_parentheses_level = 0
1525+ seen_colon = False # set to true if we're done with function parameters
1526+ brace_depth = 0
15261527 idents_to_avoid = ('l' , 'O' , 'I' )
15271528 prev_type , prev_text , prev_start , prev_end , __ = tokens [0 ]
15281529 for index in range (1 , len (tokens )):
@@ -1531,20 +1532,15 @@ def ambiguous_identifier(logical_line, tokens):
15311532 # find function definitions
15321533 if prev_text in {'def' , 'lambda' }:
15331534 is_func_def = True
1535+ elif is_func_def and text == ':' and brace_depth == 0 :
1536+ seen_colon = True
15341537 # update parameter parentheses level
1535- if parameter_parentheses_level == 0 and \
1536- prev_type == tokenize .NAME and \
1537- token_type == tokenize .OP and text == '(' :
1538- parameter_parentheses_level = 1
1539- elif parameter_parentheses_level > 0 and \
1540- token_type == tokenize .OP :
1541- if text == '(' :
1542- parameter_parentheses_level += 1
1543- elif text == ')' :
1544- parameter_parentheses_level -= 1
1538+ if text in '([{' :
1539+ brace_depth += 1
1540+ elif text in ')]}' :
1541+ brace_depth -= 1
15451542 # identifiers on the lhs of an assignment operator
1546- if token_type == tokenize .OP and text in {'=' , ':=' } and \
1547- parameter_parentheses_level == 0 :
1543+ if text == ':=' or (text == '=' and brace_depth == 0 ):
15481544 if prev_text in idents_to_avoid :
15491545 ident = prev_text
15501546 pos = prev_start
@@ -1557,6 +1553,7 @@ def ambiguous_identifier(logical_line, tokens):
15571553 # function / lambda parameter definitions
15581554 if (
15591555 is_func_def and
1556+ not seen_colon and
15601557 index < len (tokens ) - 1 and tokens [index + 1 ][1 ] in ':,=)' and
15611558 prev_text in {'lambda' , ',' , '*' , '**' , '(' } and
15621559 text in idents_to_avoid
@@ -1571,7 +1568,6 @@ def ambiguous_identifier(logical_line, tokens):
15711568 yield start , "E743 ambiguous function definition '%s'" % text
15721569 if ident :
15731570 yield pos , "E741 ambiguous variable name '%s'" % ident
1574- prev_type = token_type
15751571 prev_text = text
15761572 prev_start = start
15771573
0 commit comments