0

I am using Flake8 to get a standardized code. At the moment, I struggle to find any examples of multi-line if conditions.

Example of if statement that I have:

if 'name' in names and data and len(data) > MAX_ACCEPTABLE_LENGTH:

I cannot change the length of the constant. I tried to do (cond1 and cond2 and cond3) and separate them by lines but cannot get it right.

How can I do it?

Dmytro Chasovskyi
  • 3,209
  • 4
  • 40
  • 82
  • You may want to look at [this post](https://stackoverflow.com/a/181557/12273727) – Foussy Dec 10 '19 at 12:57
  • @ChristianHiricoiu I looked into the post that above and similar posts but couldn't find a configuration that worked for `flake8` linter specifically. – Dmytro Chasovskyi Dec 10 '19 at 13:14

1 Answers1

3

According to PEP 8 style guide for 'multiline if statements', here's what you are allowed to do :

# No extra indentation.
if (this_is_one_thing and
    that_is_another_thing):
    do_something()

# Add a comment, which will provide some distinction in editors
# supporting syntax highlighting.
if (this_is_one_thing and
    that_is_another_thing):
    # Since both conditions are true, we can frobnicate.
    do_something()

# Add some extra indentation on the conditional continuation line.
if (this_is_one_thing
        and that_is_another_thing):
    do_something()
Foussy
  • 287
  • 2
  • 11