@@ -1494,14 +1494,18 @@ def ambiguous_identifier(logical_line, tokens):
1494
1494
E741: I = 42
1495
1495
1496
1496
Variables can be bound in several other contexts, including class
1497
- and function definitions, 'global' and 'nonlocal' statements,
1498
- exception handlers, and 'with' and 'for' statements.
1497
+ and function definitions, lambda functions, 'global' and 'nonlocal'
1498
+ statements, exception handlers, and 'with' and 'for' statements.
1499
1499
In addition, we have a special handling for function parameters.
1500
1500
1501
1501
Okay: except AttributeError as o:
1502
1502
Okay: with lock as L:
1503
1503
Okay: foo(l=12)
1504
+ Okay: foo(l=I)
1504
1505
Okay: for a in foo(l=12):
1506
+ Okay: lambda arg: arg * l
1507
+ Okay: lambda a=l[I:5]: None
1508
+ Okay: lambda x=a.I: None
1505
1509
E741: except AttributeError as O:
1506
1510
E741: with lock as l:
1507
1511
E741: global I
@@ -1510,17 +1514,23 @@ def ambiguous_identifier(logical_line, tokens):
1510
1514
E741: def foo(l=12):
1511
1515
E741: l = foo(l=12)
1512
1516
E741: for l in range(10):
1517
+ E741: [l for l in lines if l]
1518
+ E741: lambda l: None
1519
+ E741: lambda a=x[1:5], l: None
1520
+ E741: lambda **l:
1521
+ E741: def f(**l):
1513
1522
E742: class I(object):
1514
1523
E743: def l(x):
1515
1524
"""
1516
- is_func_def = False # Set to true if 'def' is found
1525
+ is_func_def = False # Set to true if 'def' or 'lambda' is found
1517
1526
parameter_parentheses_level = 0
1518
1527
idents_to_avoid = ('l' , 'O' , 'I' )
1519
1528
prev_type , prev_text , prev_start , prev_end , __ = tokens [0 ]
1520
- for token_type , text , start , end , line in tokens [1 :]:
1529
+ for index in range (1 , len (tokens )):
1530
+ token_type , text , start , end , line = tokens [index ]
1521
1531
ident = pos = None
1522
1532
# find function definitions
1523
- if prev_text == 'def' :
1533
+ if prev_text in { 'def' , 'lambda' } :
1524
1534
is_func_def = True
1525
1535
# update parameter parentheses level
1526
1536
if parameter_parentheses_level == 0 and \
@@ -1545,11 +1555,15 @@ def ambiguous_identifier(logical_line, tokens):
1545
1555
if text in idents_to_avoid :
1546
1556
ident = text
1547
1557
pos = start
1548
- # function parameter definitions
1549
- if is_func_def :
1550
- if text in idents_to_avoid :
1551
- ident = text
1552
- pos = start
1558
+ # function / lambda parameter definitions
1559
+ if (
1560
+ is_func_def and
1561
+ index < len (tokens ) - 1 and tokens [index + 1 ][1 ] in ':,=)' and
1562
+ prev_text in {'lambda' , ',' , '*' , '**' , '(' } and
1563
+ text in idents_to_avoid
1564
+ ):
1565
+ ident = text
1566
+ pos = start
1553
1567
if prev_text == 'class' :
1554
1568
if text in idents_to_avoid :
1555
1569
yield start , "E742 ambiguous class definition '%s'" % text
0 commit comments