hhatto / autopep8

A tool that automatically formats Python code to conform to the PEP 8 style guide.
https://pypi.org/project/autopep8/
MIT License
4.54k stars 291 forks source link

Autopep8 adds a space before every @ decorator when syntax is incorrect #666

Closed NicolasM-Forsk closed 4 months ago

NicolasM-Forsk commented 1 year ago

When python syntax is incorrect (ex: unclosed parenthesis), autopep8 adds a space after "@". It doesn't remove it when I fix the code syntax.

Could you please improve that? Thanks a lot


Python Code


def toto():
    print(

def tata():
    pass

@staticmethod
def decorated_function():
    pass

@staticmethod
def decorated_function2():
    pass

Command Line and Configuration

default

Command Line default

Your Environment

hhatto commented 4 months ago

If an invalid code is entered, pycodestyle/autopep8 does not support the correct behavior.

nmoreaud commented 4 months ago

So, you think it's ok to have the whole file containing:

@ staticmethod
def decorated_function():
    pass

@ staticmethod
def decorated_function2():
    pass

There doesn't seem to exist a PEP 8 rule concerning this space, though I've never seen a code on the internet with a space between @ and the decorator. Can I disable autopep8 when the code is invalid?