Skip to content

Commit 397719c

Browse files
committed
Fix #311. Add regex to check for field assignment
1 parent 4c5bf00 commit 397719c

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

pep8.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +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=')
111112
HUNK_REGEX = re.compile(r'^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@.*$')
112113

113114
# Work around Python < 2.6 behaviour, which does not generate NL after
@@ -872,7 +873,9 @@ def compound_statements(logical_line):
872873
before.count('[') <= before.count(']') and # [1:2] (slice)
873874
before.count('(') <= before.count(')'))): # (annotation)
874875
if LAMBDA_REGEX.search(before):
875-
yield 0, "E731 do not assign a lambda expression, use a def"
876+
if not FIELD_ASSIGNMENT_REGEX.search(before):
877+
yield 0, ("E731 do not assign a lambda expression, use a"
878+
" def")
876879
break
877880
if before.startswith('def '):
878881
yield 0, "E704 multiple statements on one line (def)"

testsuite/E73.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
#: E731:2:5
66
while False:
77
this = lambda y, z: 2 * x
8+
#: Okay
9+
f = object()
10+
f.method = lambda: 'Method'

0 commit comments

Comments
 (0)