Monday 1 September 2014

Bad indentation :: Pylint :: W0311


Error:

Bad indentation

Description

Raised by Pylint, when an  statements use indentations that are not standard four spaces. PEP recommend 4 spaces to be used as single indent. This warning is shown when other then four spaces are used as indentation. This error is not fatal but considered a bad practice.

Example(s)

Given sample of code describe basic divide function, it takes two arguments a and b. We have simple divided first argument with second and returned result. We have used eight spaces as single indentation

def divide(a, b):
        """
        function to take two arguments to divide first by second
        """
        try:
                result = a/b
        except ZeroDivisionError:
                result = 0
        return result


Solution(s)

PEP recommend four spaces to be used as indentation, So this could be resolved using standard four spaces for indentation.

Use Four spaces
Use four spaces for single indentation.

    def divide(a, b):
        """
        function to take two arguments to divide first by second
        """
        try:
            result = a/b
        except ZeroDivisionError:
            result = 0
        return result


1 comment:

  1. I like that indent size is is overridable with --indent-string, but I dislike that the default pylint behavior is to scream about something that is not important. Throwing a lot of complaints about things that are totally acceptable is how how you make people ignore warnings in bulk. Warning fatigue.

    ReplyDelete