Skip to content

Commit f925a0e

Browse files
committed
Update fix for E731
Thanks to @mypalmike for thinking of the extra cases
1 parent 397719c commit f925a0e

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

pep8.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
KEYWORD_REGEX = re.compile(r'(\s*)\b(?:%s)\b(\s*)' % r'|'.join(KEYWORDS))
109109
OPERATOR_REGEX = re.compile(r'(?:[^,\s])(\s*)(?:[-+*/|!<=>%&^]+)(\s*)')
110110
LAMBDA_REGEX = re.compile(r'\blambda\b')
111-
FIELD_ASSIGNMENT_REGEX = re.compile('\s*.+\..+\s=')
111+
IDENTIFIER_REGEX = re.compile('\s*[^.[\]]+\s=')
112112
HUNK_REGEX = re.compile(r'^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@.*$')
113113

114114
# Work around Python < 2.6 behaviour, which does not generate NL after
@@ -873,7 +873,7 @@ def compound_statements(logical_line):
873873
before.count('[') <= before.count(']') and # [1:2] (slice)
874874
before.count('(') <= before.count(')'))): # (annotation)
875875
if LAMBDA_REGEX.search(before):
876-
if not FIELD_ASSIGNMENT_REGEX.search(before):
876+
if IDENTIFIER_REGEX.match(before):
877877
yield 0, ("E731 do not assign a lambda expression, use a"
878878
" def")
879879
break

testsuite/E73.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,11 @@
88
#: Okay
99
f = object()
1010
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'

0 commit comments

Comments
 (0)