Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use continuation line over-indented for visual indent?

Tags:

python

pep8

I'm having a hard time trying to fix this piece of code in order for it to fit PEP8's guidelines. I have tried breaking the line with a backslash and then enclosing it with a set of brackets. Furthermore, I made sure that the second line came right after the position first right bracket.

    if (len(self._stools[origin]) > 0 and len(self._stools[dest]) and
        self.top_cheese(origin).size > self.top_cheese(dest).size):
        raise IllegalMoveError

Thus, every time I run pep8.py on this piece of code I get:

TOAHModel.py:94:14: E127 continuation line over-indented for visual indent.

like image 768
wonggr Avatar asked Feb 06 '14 01:02

wonggr


1 Answers

I'm guessing you are getting a "Continuation line does not distinguish itself from next logical line". The solution is to move the second line another indent -

if (len(self._stools[origin]) > 0 and len(self._stools[dest]) and
        self.top_cheese(origin).size > self.top_cheese(dest).size):
    raise IllegalMoveError

The reason is that self.top_cheese(origin).size is at the same indent level as raise IllegalMoveError, which can be difficult for the reader, because it might is not obvious where the if statement ends and the actual block within the if statement begins. You can argue that this does not look much better, but that's the way it is.

like image 174
Shashank Agarwal Avatar answered Oct 20 '22 18:10

Shashank Agarwal