diff options
author | Florent Xicluna <florent.xicluna@gmail.com> | 2014-04-26 18:34:09 +0200 |
---|---|---|
committer | Florent Xicluna <florent.xicluna@gmail.com> | 2014-04-26 18:34:09 +0200 |
commit | b29fb6a086edcf7638a9ef02790fad8dc0d24e34 (patch) | |
tree | 677836b059c7dacfa3ac7a1249fe01a53c70d056 /pep8.py | |
parent | f4e57cd75e7d949d42be58d59982f2b40bdce989 (diff) | |
download | pep8-b29fb6a086edcf7638a9ef02790fad8dc0d24e34.tar.gz |
Report E731 for lambda assignment, return E704 for one-liner def instead of E701; issue #277
Diffstat (limited to 'pep8.py')
-rwxr-xr-x | pep8.py | 21 |
1 files changed, 15 insertions, 6 deletions
@@ -834,6 +834,9 @@ def compound_statements(logical_line): on the same line, never do this for multi-clause statements. Also avoid folding such long lines! + Always use a def statement instead of an assignment statement that + binds a lambda expression directly to a name. + Okay: if foo == 'blah':\n do_blah_thing() Okay: do_one() Okay: do_two() @@ -847,20 +850,26 @@ def compound_statements(logical_line): E701: try: something() E701: finally: cleanup() E701: if foo == 'blah': one(); two(); three() - E702: do_one(); do_two(); do_three() E703: do_four(); # useless semicolon + E704: def f(x): return 2*x + E731: f = lambda x: 2*x """ line = logical_line last_char = len(line) - 1 found = line.find(':') while -1 < found < last_char: before = line[:found] - if (before.count('{') <= before.count('}') and # {'a': 1} (dict) - before.count('[') <= before.count(']') and # [1:2] (slice) - before.count('(') <= before.count(')') and # (Python 3 annotation) - not LAMBDA_REGEX.search(before)): # lambda x: x - yield found, "E701 multiple statements on one line (colon)" + if ((before.count('{') <= before.count('}') and # {'a': 1} (dict) + 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" + break + if before.startswith('def '): + yield 0, "E704 multiple statements on one line (def)" + else: + yield found, "E701 multiple statements on one line (colon)" found = line.find(':', found + 1) found = line.find(';') while -1 < found: |