1
\$\begingroup\$

I'm using pylint and flake8 to control the code quality. However I am in check-mate position, where styling one does not suit the pylint or flake8:

if (not re.search(regexp, summary) and
 not re.search(regexp2, summary)): 
 return False 

Output from flake8:

visually indented line with same indent as next logical line [E129] 

Moving return is not helping, the previous error still occurs and there is new one thrown by pylint:

if (not re.search(regexp, summary) and
 not re.search(regexp2, summary)): 
 return False 

Output from pylint:

[bad-indentation] Bad indentation. Found 8 spaces, expected 4 
alecxe
17.5k8 gold badges52 silver badges93 bronze badges
asked Feb 10, 2017 at 11:54
\$\endgroup\$
1
  • 1
    \$\begingroup\$ What are the two regular expressions? Please provide full context for your question. \$\endgroup\$ Commented Feb 10, 2017 at 13:14

1 Answer 1

4
\$\begingroup\$

Per PEP-8, you can ("Acceptable options in this situation include, but are not limited to...") further indent the second line of the condition:

# Add some extra indentation on the conditional continuation line.
if (this_is_one_thing
 and that_is_another_thing):
 do_something()

The difference is that indentation in the continuation lines is purely stylistic, whereas indentation of the next code block has semantic meaning. In your case:

if (not re.search(regexp, summary)
 and not re.search(regexp2, summary)): 
 return False 

Note I have moved the and per the same guidance.

answered Feb 10, 2017 at 12:02
\$\endgroup\$
3
  • 1
    \$\begingroup\$ In addition: I'd also consider to move that complex condition into a separate function. There are good chances that the purpose of a long wall of text isn't immediately obvious \$\endgroup\$ Commented Feb 10, 2017 at 12:04
  • \$\begingroup\$ @AdrianoRepetti that would be another option, although if the regexes have sensible names I think a two-part conditional is OK. You don't want to end up writing if is_foo_and_bar(thing): when if is_foo(thing) and is_bar(thing): is just as readable! \$\endgroup\$ Commented Feb 10, 2017 at 12:35
  • 1
    \$\begingroup\$ I agree but it won't then be probably long enough to need to split. Also is_foo_and_bar(thing) might be is_buz(thing) (because foo and bar together mean something else), in that case a local variable or a function will definitely clarify. Anyway, it's just another option to consider, not The Way to Go \$\endgroup\$ Commented Feb 10, 2017 at 14:47

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.