diff options
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: |