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.

Detect Indentation using 8-character indentation instead of 4 characters

See original GitHub issue

Environment data

  • VS Code version: 1.27.2
  • Extension version (available under the Extensions sidebar): 2018.8.0
  • OS and version: macOS 10.12.6
  • Python version (& distribution if applicable, e.g. Anaconda): 3.6.5, Anaconda Intel build
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): conda
  • Relevant/affected Python packages and their versions: None

Actual behavior

Pressing return e.g. after a function signature (def somefunc():) or tab (whether there is text selected or not) results in an indentation eight characters wide.

This appears to be specific to the contents of my code file as I cannot reproduce with a new Python file.

Expected behavior

Four-character indentation as per previous versions of vscode-python and PEP 8.

Steps to reproduce:

  1. Open a new file and save with .py extension.
  2. Verify that Settings -> Detect Indentation is checked.
  3. Paste in code from an existing Python file lasted edited with an earlier version of VS Code. See attached example.
  4. Press return or tab as indicated in description of actual behavior.

Steps that DO NOT reproduce:

  1. Open a new file and save with .py extension.
  2. Verify that Settings -> Detect Indentation is checked.
  3. Start typing. Indentation is four characters per keypress.

Unchecking Settings -> Detect Indentation does result in expected behavior.

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

##########Linting Output - pylint##########

--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)

[pylint apparently doesn’t pick up on the 8-char indentation either?]

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help)

log.ts:159  INFO no standard startup: not just one window
TMSyntax.ts:47 Overwriting grammar scope name to file mapping for scope source.python.
Old grammar file: file:///Applications/Visual%20Studio%20Code.app/Contents/Resources/app/extensions/python/syntaxes/MagicPython.tmLanguage.json.
New grammar file: file:///Users/arg/.vscode/extensions/magicstack.magicpython-1.0.12/grammars/MagicPython.tmLanguage
e.register @ TMSyntax.ts:47

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ralexxcommented, Oct 21, 2021

Thank you for pointing out that extension @karrtikr. It’s clearly popular, and probably will satisfy my use case.

I will leave this issue open in case the vscode-python team wishes to incorporate this functionality at some future point (which would not be unusual in the Python world; perhaps microservices are still favored in JS/TS applications?)

0reactions
karrtikrcommented, Dec 20, 2022

Pylance now supports auto-indentation so this should no longer be an issue, if you still face it feel free to open up an issue on https://github.com/microsoft/pylance-release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to change indentation in Visual Studio Code?
Edit 1 · Step 1: Click on Preferences > Settings · Step 2: The setting you are looking for is "Detect Indentation", begin...
Read more >
What's the deal with tab size (8 spaces) in the GitHub UI?
"Tabs are 8 characters, and thus indentations are also 8 characters. There are heretic movements that try to make indentations 4 (or even ......
Read more >
Why is GitHub's default tab size 8 spaces instead of 4 ... - Quora
Spaces are always spaces. Spaces allow you to dictate the size, so you can have indents less that 8 characters, which is important...
Read more >
VS Code tips — Indentation settings and the ... - YouTube
VS Code shows the indentation settings for the current in the status bar. Click on this entry to quickly change the tab size...
Read more >
Indentation | IntelliJ IDEA Documentation - JetBrains
Use the tab or space character for indentation and code formatting. ... When the option is on, the part of indentation defined by...
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