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
-
1\$\begingroup\$ What are the two regular expressions? Please provide full context for your question. \$\endgroup\$200_success– 200_success2017年02月10日 13:14:22 +00:00Commented Feb 10, 2017 at 13:14
1 Answer 1
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.
-
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\$Adriano Repetti– Adriano Repetti2017年02月10日 12:04:01 +00:00Commented 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):
whenif is_foo(thing) and is_bar(thing):
is just as readable! \$\endgroup\$jonrsharpe– jonrsharpe2017年02月10日 12:35:21 +00:00Commented 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 beis_buz(thing)
(becausefoo
andbar
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\$Adriano Repetti– Adriano Repetti2017年02月10日 14:47:44 +00:00Commented Feb 10, 2017 at 14:47