@@ -1522,7 +1522,8 @@ def ambiguous_identifier(logical_line, tokens):
1522
1522
E743: def l(x):
1523
1523
"""
1524
1524
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
1526
1527
idents_to_avoid = ('l' , 'O' , 'I' )
1527
1528
prev_type , prev_text , prev_start , prev_end , __ = tokens [0 ]
1528
1529
for index in range (1 , len (tokens )):
@@ -1531,20 +1532,15 @@ def ambiguous_identifier(logical_line, tokens):
1531
1532
# find function definitions
1532
1533
if prev_text in {'def' , 'lambda' }:
1533
1534
is_func_def = True
1535
+ elif is_func_def and text == ':' and brace_depth == 0 :
1536
+ seen_colon = True
1534
1537
# 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
1545
1542
# 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 ):
1548
1544
if prev_text in idents_to_avoid :
1549
1545
ident = prev_text
1550
1546
pos = prev_start
@@ -1557,6 +1553,7 @@ def ambiguous_identifier(logical_line, tokens):
1557
1553
# function / lambda parameter definitions
1558
1554
if (
1559
1555
is_func_def and
1556
+ not seen_colon and
1560
1557
index < len (tokens ) - 1 and tokens [index + 1 ][1 ] in ':,=)' and
1561
1558
prev_text in {'lambda' , ',' , '*' , '**' , '(' } and
1562
1559
text in idents_to_avoid
@@ -1571,7 +1568,6 @@ def ambiguous_identifier(logical_line, tokens):
1571
1568
yield start , "E743 ambiguous function definition '%s'" % text
1572
1569
if ident :
1573
1570
yield pos , "E741 ambiguous variable name '%s'" % ident
1574
- prev_type = token_type
1575
1571
prev_text = text
1576
1572
prev_start = start
1577
1573
0 commit comments