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

Some messages written to stdout instead of stderr #717

Open herring-swe opened 7 months ago

herring-swe commented 7 months ago

autopep8 outputs some warnings and verbose messages to stdout instead of stderr. This leads to problems when someone (such as vscode extension vscode-autopep8) wants to format not using --in-place flag since there's no distinction between output code and processing messages and thus writes the message into the new code.. See: https://github.com/microsoft/vscode-autopep8/issues/201


Command Line and Configuration

~/.config/pycodestyle

[pycodestyle]
max-complexity = 20

Command Line

$ python -m autopep8 -i file.py -vvv 2>/dev/null
read config path: /home/xyz/.config/pycodestyle
  unknown option 'max-complexity' ignored
$ python -m autopep8 -i file.py -vvv 1>/dev/null
[file:file.py]
--->  10 issue(s) to fix {'E221': {13, 14, 15, 16, 17, 18, 19}, 'E501': {72, 122, 100}}
--->  Not fixing E501 on line 72
--->  Not fixing E501 on line 100
--->  Not fixing E501 on line 122

Your Environment

hhatto commented 1 month ago

This behaviour is part of what autopep8 does on the pycodestyle side when it runs pycodestyle. It is difficult to fix on the autopep8 side.

https://github.com/PyCQA/pycodestyle/blob/710363bd2048d9c7fa3f24dcaf21e40ced7f74d5/pycodestyle.py#L2539

The first step in addressing this issue is to remove configuration options not supported by pycodestyle from the configuration file.