diff options
-rwxr-xr-x | pep8.py | 5 | ||||
-rw-r--r-- | testsuite/E73.py | 3 |
2 files changed, 7 insertions, 1 deletions
@@ -108,6 +108,7 @@ COMPARE_TYPE_REGEX = re.compile(r'(?:[=!]=|is(?:\s+not)?)\s*type(?:s.\w+Type' KEYWORD_REGEX = re.compile(r'(\s*)\b(?:%s)\b(\s*)' % r'|'.join(KEYWORDS)) OPERATOR_REGEX = re.compile(r'(?:[^,\s])(\s*)(?:[-+*/|!<=>%&^]+)(\s*)') LAMBDA_REGEX = re.compile(r'\blambda\b') +FIELD_ASSIGNMENT_REGEX = re.compile('\s*.+\..+\s=') HUNK_REGEX = re.compile(r'^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@.*$') # Work around Python < 2.6 behaviour, which does not generate NL after @@ -872,7 +873,9 @@ def compound_statements(logical_line): before.count('[') <= before.count(']') and # [1:2] (slice) before.count('(') <= before.count(')'))): # (annotation) if LAMBDA_REGEX.search(before): - yield 0, "E731 do not assign a lambda expression, use a def" + if not FIELD_ASSIGNMENT_REGEX.search(before): + yield 0, ("E731 do not assign a lambda expression, use a" + " def") break if before.startswith('def '): yield 0, "E704 multiple statements on one line (def)" diff --git a/testsuite/E73.py b/testsuite/E73.py index 0673e0f..ede1403 100644 --- a/testsuite/E73.py +++ b/testsuite/E73.py @@ -5,3 +5,6 @@ f = lambda x: 2*x #: E731:2:5 while False: this = lambda y, z: 2 * x +#: Okay +f = object() +f.method = lambda: 'Method' |