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