Reed_Xia
Reed_Xia

Reputation: 1452

Python coding convention "Wrong continued indentation before block: found by pylint

I used pylint to check my python code, and found this convention problem:

C:11, 0: Wrong continued indentation before block.
                    + this_time <= self.max):
                    ^   | (bad-continuation)

I tried to refine for times but the problem is still present, can someone help? Thanks!

if len(remaining_obj_list) > 0:
    for i in a_list:
        this_time = self.__get_time(i)
        for remaining_obj in remaining_obj_list:
            if (remaining_obj.get_time() # to fit 78 char rule
                + this_time <= self.max):
                i.append(remaining_obj)
                remaining_obj.set_used(True)
        if 0 == len(self.__get_unused_list):
            break

Upvotes: 28

Views: 28714

Answers (4)

feasel0
feasel0

Reputation: 317

According to PEP8 the preferred place to break around a binary operator is before the operator. This did not used to be the case, but it changed to be consistent with mathematical formula conventions.

Upvotes: 0

user10106944
user10106944

Reputation:

Check for spurious tabs (in Sublime: Ctrl + F, then enter a single space) and replace them by the correct number of spaces. I had the same issue and while PyLint was complaining about line continuation, the error was actually triggered by misplaced tabs.

At indentations, PyLint seems to count spaces only and throws this error if the numbers don't add up to multiples of 4. Depending on the editor, misplaced tabs may not be immediately visible.

Upvotes: 0

sthenault
sthenault

Reputation: 15125

Pylint doesn't want such continuation to start on the same column as the next indentation block. Also, notice that the message includes a hint on columns that it considers correct.

Upvotes: 40

Amber
Amber

Reputation: 527183

Try putting the + on the previous line:

        if (remaining_obj.get_time() +
            this_time <= self.max):

As a side note though, you might want to consider the factors that are causing your code to have to fit within ~40 characters - perhaps you have a few too many indentation levels and your code could be refactored to have fewer nested blocks.

Upvotes: 2

Related Questions