PyCQA / pycodestyle

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

E101 false positives due to mismatched indentation in module docstring #1156

Closed tushar-deepsource closed 1 year ago

tushar-deepsource commented 1 year ago

If the docstring has indentation with tabs, and the code is indented with spaces (or vice versa), then E101 is raised on every single indented line of the codebase.

For example:

"""
foo bar
    (<-- tab here) some description
"""

def four_spaces_only():
    pass        # E101

def foo_bar():
    def baz():  # E101
        pass    # E101

I guess this can be fixed by not treating the indentation inside docstrings as the de-facto, rather using the first INDENT token. Logic here: https://github.com/PyCQA/pycodestyle/blob/d4dadf593e56f5b969b206e80ae2923f8bfd30b8/pycodestyle.py#L1987

asottile commented 1 year ago

this is correct. the docstring should use spaces too

asottile commented 1 year ago

there's also a bunch of duplicates -- they are all tagged by the error code so please search that next time!

tusharsadhwani commented 1 year ago

It is correct, but it's really bad UX imo.

I'll give you a valid usecase: someone was using tabs, then ran the codebase through black. now everything is spaces except the docstrings, and pycodestyle raises thousands issues on lines of code, even though all code is indented with 4 spaces.

asottile commented 1 year ago

still doesn't sound like a pycodestyle problem -- sounds like someone wants to run git ls-files -- '*.py' | xargs sed -i 's/\t/ /g'