PyCQA / pycodestyle

Simple Python style checker in one Python file
https://pycodestyle.pycqa.org
Other
5.03k stars 753 forks source link

E101 false positive caused by docstring #1113

Closed pblemel closed 2 years ago

pblemel commented 2 years ago

A tab-indented .py file begins with a docstring that is not indented, but the content of the string is indented using spaces to get some disclaimers and license information to line up. E.g.,

"""
<Some text>
<arbitrary number of spaces>Some boilerplate text
"""

This causes the first tab-indented statement in the file to be flagged by pycodestyle as having inconsistent indentation.

def foo:
<tab>foo=bar()  <--- This line is flagged as having inconsistent indentation

Pylint will ignore this by setting the indentation type manually in .pylintrc:

indent-string='\t'

Which causes pylint to not complain about the first indented line (because it knows that tabs are expected) any still complain about code that has been inadvertently indented with spaces.

I don't see a similar setting for pycodestyle, which causes my IDE to flag the "issue" even though pylint will ignore it. Obviously, this is cosmetic but it would be nice to be able to have both tools behave the same to avoid some unwitting developer reformat the entire legacy code base.

Is there a way to force pycodestyle to use tab indentation, instead of inferring it?

asottile commented 2 years ago

I've tagged the issues with the error codes to make it very easy to find duplicates