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 112112KEYWORD_REGEX = re .compile (r'(\s*)\b(?:%s)\b(\s*)' % r'|' .join (KEYWORDS ))
113113OPERATOR_REGEX = re .compile (r'(?:[^,\s])(\s*)(?:[-+*/|!<=>%&^]+)(\s*)' )
114114LAMBDA_REGEX = re .compile (r'\blambda\b' )
115- IDENTIFIER_REGEX = re .compile ('\s*[^.[\]]+\s=' )
116115HUNK_REGEX = re .compile (r'^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@.*$' )
117116
118117# Work around Python < 2.6 behaviour, which does not generate NL after
@@ -923,10 +922,11 @@ def compound_statements(logical_line):
923922 if ((before .count ('{' ) <= before .count ('}' ) and # {'a': 1} (dict)
924923 before .count ('[' ) <= before .count (']' ) and # [1:2] (slice)
925924 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"
930930 break
931931 if before .startswith ('def ' ):
932932 yield 0 , "E704 multiple statements on one line (def)"
Original file line number Diff line number Diff line change 88#: Okay
99f = object ()
1010f .method = lambda : 'Method'
11- #: Okay
11+
1212f = {}
1313f ['a' ] = lambda x : x ** 2
14- #: Okay
14+
1515f = []
1616f .append (lambda x : x ** 2 )
17- #: Okay
17+
1818lambda : 'no-op'
You can’t perform that action at this time.
0 commit comments