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

E501 error cannot be detected #521

Open hayata-yamamoto opened 4 years ago

hayata-yamamoto commented 4 years ago

I'm glad to use this library. I appreciate your updates.

Anyway, I wonder why E501 error cannot be detected by autopep8, although flake8 which uses the same pycodestyle can do that. From my perspective, this problem could be big because format checking is incorporated into OSS services' CI settings.

Unfortunately, I'm not sure the reason for this problem, but I'm quite in trouble. For example, autopep8 passed my codes, but flake8 doesn't allow my code. Since flake8 does not provide formatting methods, I'm fixing by myself even if I use autopep8... :(

Would it be possible to investigate and modify if this error would happen by some bugs?


Python Code

For example, the following is over 99 words, but autopep8 says nothing.

import random

def func():
    return min(max(random.random(), random.randint(1, 100)), max(random.randint(0, 100), random.randint(0, 100)))

Command Line and Configuration

Command Line

$ autopep8 [filename] --max-line-length 99 --diff

FYI: flake8 can detect this error.

# setup.cfg
[flake8]
max-line-length = 99
$ flake8 [filename]

Your Environment

m3nu commented 4 years ago

Seeing the same.

hhatto commented 4 years ago

@hayata-yamamoto @m3nu

Thanks for using autopep8 👍

You need to add the -a option (-aa, -aaa too) to fix the indication about max-line-length.

$ cat target.py
import random

def func():
    return min(max(random.random(), random.randint(1, 100)), max(random.randint(0, 100), random.randint(0, 100)))

$ autopep8 -d target.py

$ autopep8 -a -d target.py
--- original/target.py
+++ fixed/target.py
@@ -2,4 +2,5 @@

 def func():
-    return min(max(random.random(), random.randint(1, 100)), max(random.randint(0, 100), random.randint(0, 100)))
+    return min(max(random.random(), random.randint(1, 100)),
+               max(random.randint(0, 100), random.randint(0, 100)))