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.56k stars 290 forks source link

Parameter “--max-line-length” does not take effect. #393

Open gao-xuejian opened 6 years ago

gao-xuejian commented 6 years ago

I want to limit the length of each line to less than 80,But parameter “--max-line-length 79” does not take effect.

sanjeethboddi commented 6 years ago

@jayvdb can i be assigned to this one

migumun commented 5 years ago

This is also failing from me. It does not work when passed as part of the options in a python call.

sh9901 commented 5 years ago

try using this option together with --aggressive 2

chrisspen commented 5 years ago

I can reproduce this bug. Autopep8 seems to largely ignore the --max-line-length setting. Even with three "aggressive" flags, that only made it wrap a long comment, but not a docstring or if statement. Is enforcing line length not a supported feature yet?

hashedhyphen commented 4 years ago

Here is an example case.

(autopep8-test) ~/w/autopep8-test@ autopep8 --version
autopep8 1.4.4 (pycodestyle: 2.5.0)

(autopep8-test) ~/w/autopep8-test@ cat main.py 
def foo(arg1, arg2, tooooooooooooooooooooooooooooooooooooooooooooooooooolongarg):
    pass

(autopep8-test) ~/w/autopep8-test@ autopep8 -v -v --max-line-length=80 main.py
[file:main.py]
--->  Applying global fix for E265
--->  1 issue(s) to fix {'E501': {1}}
--->  Not fixing E501 on line 1
def foo(arg1, arg2, tooooooooooooooooooooooooooooooooooooooooooooooooooolongarg):
    pass

In this case, compile() in check_syntax() throws SyntaxError for fix candidates, e.g.

def foo(arg1,
        arg2, tooooooooooooooooooooooooooooooooooooooooooooooooooolongarg):

https://github.com/hhatto/autopep8/blob/120537a051d7f3cbbb5c4ede19b9e515156bd3d1/autopep8.py#L3189-L3194

There may be alternatives for the syntax checker, such as codeop.compile_command() or ast.parse(), but they might cause additional issues.