How to fix Pylint "Wrong hanging indentation" and PEP8 E121?

Jatin Kumar picture Jatin Kumar · Aug 14, 2014 · Viewed 21.8k times · Source

I am trying to properly indent following piece of code:

RULES_LIST = [
    ('Name1', 1, 'Long string upto 40 chars'),
    ('Name2', 2, 'Long string upto 40 chars'),
    ('Name3', 3, 'Long string upto 40 chars'),
    ('Name4', 4, 'Long string upto 40 chars'),
    ('Name5', 5, 'Long string upto 40 chars'),
    ('Name6', 6, 'Long string upto 40 chars'),
    ('Name7', 7, 'Long string upto 40 chars'),
    ('Name8', 8, 'Long string upto 40 chars')
]

Pylint complains Wrong hanging indentation. for above code, and PEP8 complains E121: under-indented for hanging indent.

A possible fix for pylint is changing it to:

RULES_LIST = [\
    ('Name1', 1, 'Long string upto 40 chars'),
     ...
    ('Name8', 8, 'Long string upto 40 chars')]

but PEP8 complains E121 and E502

PEP8: 1.5.7 (default configuration)
Pylint: 1.3.0 (default configuration)
Python: 2.7.5 (Running on OSX 10.9.3)

The list can grow longer. Can someone please suggest a proper indentation for this?

Answer

James Brierley picture James Brierley · Nov 24, 2016

If you want to continue using tabs, you can change the following settings in the .pylintrc file:

indent-string='\t'
indent-after-paren=1

If you only change the first one, pylint will expect four tabs to be used for indentation.