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

Error in Visual Studio when formatting with no newline at end of file #617

Open AdamYoblick opened 2 years ago

AdamYoblick commented 2 years ago

When trying to format a document in Visual Studio using the autopep8 formatter, an error is thrown when there is no newline at the end of the file. Please see https://github.com/microsoft/PTVS/issues/6752 for details.


Python Code (remove the newline at the end!!!)


######this is a comment
import os,sys;
spam( ham [ 1 ], { eggs : 2 } )
def foo    ():pass
x=1;y     =2;
y = 2
#comment no newline

The error looks like this:

image

Command Line and Configuration

Looks like the command is run by the PTVS extension here: https://github.com/microsoft/PTVS/blob/main/Python/Product/PythonTools/PythonTools/Editor/Formatting/PythonFormatterAutopep8.cs#L27

Your Environment