I have a very weird issue affecting my code. I'm getting set up on a new machine, and in VS Code the Python terminal is passing different code than what I wrote in the editor. I'm not sure if there is a setting that I need to change, but I never had this issue on any of the other machines that I've worked on.
The terminal seems to be passing indentions that do not exist in the written code if I include the code in a function. All of this code is highlighted in the code editor and run by hitting Shift+Enter. When I run the function, it gives an Unexpected Indent error.
If I have the code:
var1 = 1
var2 = 2
print(var1+var2)
it works.
If I wrap it in a function:
def test_function():
var1 = 1
var2 = 2
print(var1+var2)
it does not.
When I look in the terminal, the code that is passed looks like this:
This is not the way the code is written:
I have ensured that the indention setting is set to four. I've tried this with both tabs and spaces.
The only thing that seems to work is if I remove all the white space, and now it works when I highlight it.
I have tried searching for settings to change, but nothing has worked.
Python 3.13.0 VS code 1.96.2
I am able to reproduce the problem on command prompt, Python version 3.13.1.
As vimchun said, switching to version 3.12.X will resolve the indentation issue.