File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change 112
112
KEYWORD_REGEX = re .compile (r'(\s*)\b(?:%s)\b(\s*)' % r'|' .join (KEYWORDS ))
113
113
OPERATOR_REGEX = re .compile (r'(?:[^,\s])(\s*)(?:[-+*/|!<=>%&^]+)(\s*)' )
114
114
LAMBDA_REGEX = re .compile (r'\blambda\b' )
115
+ IDENTIFIER_REGEX = re .compile ('\s*[^.[\]]+\s=' )
115
116
HUNK_REGEX = re .compile (r'^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@.*$' )
116
117
117
118
# Work around Python < 2.6 behaviour, which does not generate NL after
@@ -923,7 +924,9 @@ def compound_statements(logical_line):
923
924
before .count ('[' ) <= before .count (']' ) and # [1:2] (slice)
924
925
before .count ('(' ) <= before .count (')' ))): # (annotation)
925
926
if LAMBDA_REGEX .search (before ):
926
- yield 0 , "E731 do not assign a lambda expression, use a def"
927
+ if IDENTIFIER_REGEX .match (before ):
928
+ yield 0 , ("E731 do not assign a lambda expression, use a"
929
+ " def" )
927
930
break
928
931
if before .startswith ('def ' ):
929
932
yield 0 , "E704 multiple statements on one line (def)"
Original file line number Diff line number Diff line change 5
5
#: E731:2:5
6
6
while False :
7
7
this = lambda y , z : 2 * x
8
+ #: Okay
9
+ f = object ()
10
+ f .method = lambda : 'Method'
11
+ #: Okay
12
+ f = {}
13
+ f ['a' ] = lambda x : x ** 2
14
+ #: Okay
15
+ f = []
16
+ f .append (lambda x : x ** 2 )
17
+ #: Okay
18
+ lambda : 'no-op'
You can’t perform that action at this time.
0 commit comments