Search code examples
python-3.xflake8

How to split a return statement in several lines to fulfill flake8 style


I have a function with a return statement like:

return apple, banana, orange, pear, grape, kiwi

But it exceeds the maximum number of characters that flake8 lets me (in the example I've just put a dummy example), so how should I do it?

I've tried things like

return apple, banana, orange,\
    pear, grape, kiwi

return apple, banana, orange,
    pear, grape, kiwi

return apple, banana, orange,
pear, grape, kiwi

And nothing works. The last one was accepted by flake8 but it throws an execution error.

Thank you very much for your help


Solution

  • You return a tuple, so you can do like this:

    return (
        apple,
        banana,
        orange,
        pear,
        grape,
        kiwi
    )