autopep8
autopep8 copied to clipboard
E501 not fixed for function already spread across mutliple lines
Python Code
def func(foo, bar, baz, ham, spam, eggs, qux, quux,
quuux):
pass
def func(foo, bar, baz, ham, spam, eggs, qux, quux, quuux):
pass
The idea here is that in both examples are equivalent, and both contain a line that's too long. When running autopep8 -a --max-line-length=40 file.py
(no config; line length for demonstration purposes), we get:
def func(foo, bar, baz, ham, spam, eggs, qux, quux,
quuux):
pass
def func(foo, bar, baz, ham,
spam, eggs, qux, quux, quuux):
pass
The second result seems correct, the first one was ignored and still violates E501, despite having an obvious solution. I would have expected that both yield the same result.
The reason for this is that when attempting to fix the first expression, get_fixed_long_line
tries to call generate_tokens(source)
, where source
is the first line, i.e.:
def func(foo, bar, baz, ham, spam, eggs, qux, quux,
This means that tokenize
raises an error (SyntaxError
, I guess), which results in fix_long_line_(physically|logically)
to give up. It seems to me that fix_long_line_*
will basically ignore any situation where an expression is split over multiple lines.
Is my assessment correct? Is this a known limitation? If not, then I would suggest adding this to a list of known limitations, as encountering this problem is quite confusing to the user.
Are there plans to fix this? Maybe the algorithm could try to remove line breaks before and after the offending line until a valid expression is obtained to circumvent the problem?
Your Environment
- Python version: 3.7.8
- autopep8 version: autopep8 1.5.5 (pycodestyle: 2.6.0)
- Platform: macOS 11.2.3
I have the same kind of issue. (I'm using autopep8 2.0.4)