question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

autopep8 formatting not working

See original GitHub issue

Environment data

  • VS Code version: 1.28.0 (user setup)
  • Extension version (available under the Extensions sidebar): 2018.9.0 (9 Oct 2018)
  • OS and version: Windows 10
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)]
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): pipenv
  • Relevant/affected Python packages and their versions: autopep8 1.3.5 (pycodestyle: 2.4.0) pylint 2.0.1

Actual behavior

Executing the command ‘Format Document’ does nothing to the document. It does however show “Formatting with autopep8” in the blue bottom bar. I have tried my best reading the various guides for VS Code Python and formatting but to no avail.

Expected behavior

I expected it to at least format something.

Steps to reproduce:

  1. Copy&paste the code found on https://pypi.org/project/autopep8/
import math, sys;

def example1():
    ####This is a long comment. This should be wrapped to fit within 72 characters.
    some_tuple=(   1,2, 3,'a'  );
    some_variable={'long':'Long code lines should be wrapped within 79 characters.',
    'other':[math.pi, 100,200,300,9876543210,'This is a long string that goes on'],
    'more':{'inner':'This whole logical line should be wrapped.',some_tuple:[1,
    20,300,40000,500000000,60000000000000000]}}
    return (some_tuple, some_variable)
def example2(): return {'has_key() is deprecated':True}.has_key({'f':2}.has_key(''));
class Example3(   object ):
    def __init__    ( self, bar ):
     #Comments should have a space after the hash.
     if bar : bar+=1;  bar=bar* bar   ; return bar
     else:
                    some_string = """
                       Indentation in multiline strings should not be touched.
Only actual code should be reindented.
"""
                    return (sys.path, some_string)
  1. Try to format with the command ‘Format Document’

Logs

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
brettcannoncommented, Oct 16, 2018

@thernstig your settings aren’t quite right; you want as you have to make each individual item you would pass on the command line an individual thing in the array:

"python.formatting.autopep8Args": ["--max-line-length", "100"]

@gaziqbal yes, -i will break the extension as we read the diff to format the document for you.

And yes, outputting what command we are running for you would be useful and adding more logging is on our (very long) TODO list.

1reaction
thernstigcommented, Oct 17, 2018

@brettcannon Good answers as always, thank you for being so easygoing. Keep on making the Python extension even more awesome! 🎸

Read more comments on GitHub >

github_iconTop Results From Across the Web

Format Document not working (autopep8, python, vscode)
When I run "Format Document", the file is not formatted. Steps to reproduce: Open a Workspace; Open up a Python File in the...
Read more >
Atom editor : autopep8 is not working and no error message at ...
it's just silent and autopep8 is not working (turn on 'format on save' already). At the bottom of the editor , there's small...
Read more >
Autopep8 not working in VSCode. Not sure what i've changed ...
today I noticed autopep8 (running on save) has not been working in vscode for a while. it should be set up to run...
Read more >
Formatting | Python in Visual Studio Code
The default code format provider is autopep8. Auto Formatting. Formatting the source code as and when you save the contents of the file...
Read more >
Editing Python in Visual Studio Code
Troubleshooting formatting ; The formatter is not installed in the current environment. Open a command prompt, navigate to the location where your selected ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found