Skip to content

No complaint about inconsistent indentation levels #430

@schmiddy

Description

@schmiddy

pep8 neglects to complain about code with mismatched indentation levels, such as this snippet:

if True:
        print 'yes'
else:
    print 'no'

Example taken from a complaint about this problem on StackOverflow. pylint gives a reasonable error here, namely:

W: 2, 0: Bad indentation. Found 8 spaces, expected 4 (bad-indentation)

The PEP 8 standard says simply:

Use 4 spaces per indentation level.

And I would like to have a warning about any indentation level other than 4 spaces. Here's the beginning of a fix. I think these errors might need to be separated based on:

a. mixing different indentation levels, as in the example above
b. using any indentation level other than 4 spaces (including tabs)

IMO a.) should definitely be an error by default. I can see the case for b.) being off by default and/or just a warning, particularly since PEP 8 makes an allowance for tabs by saying:

Tabs should be used solely to remain consistent with code that is already indented with tabs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions