Python indentation very buggy

Problem description

This is about multiple indentation bugs (mostly specific to python because of the lack of braces).

  1. The editor thinks that some functions encompass much more code than they actually do. Minimizing this function hides code outside of the function, often the entire rest of the file.
  2. The above bug also causes any indentation during code writing somewhere after the function to be incorrect, so when you type a new line, it starts out at the wrong indentation.
  3. The indentation gets confused by a slightly uncommon python feature: using an else clause with a while or for loop.
  4. (Applies to almost all languages/files) The editor allows you to customize the indentation style per file: the number of spaces, and using tabs or spaces. This is not saved after you exit the session, and will always reset back to the global user settings.

Two unsolved bug reports about function minimizing:
Replit Computer App Bug w/Closing functions/while/if loops
Editor minimizes multiple functions into one group in Python

Expected behavior

  1. Editor correctly identifies function scope. Function minimizing only hides the function code.
  2. Editor does not put new lines at the wrong indentation.
  3. Editor correctly recognizes else clause of loops, and does not mess up their indentation.
  4. Editor saves the per-file custom indentation settings permanently. (Otherwise, the setting is much less useful.)

Actual behavior

  1. Editor thinks function is larger than it is. Minimizes too much code.
  2. After an incorrectly measured function, editor indents new lines incorrectly.
  3. Editor does not recognize else clause of loops, and reindents them incorrectly.
  4. Editor forgets all per-file indentation settings after a session.

Steps to reproduce

An example repl:
https://replit.com/@NuclearPasta0/indentation-bad
Follow the instructions. (My global indentation settings is 2 spaces.)

Browser

chrome

OS

MacOS, ChromeOS

Device if mobile

n/A

Plan

free tier

4 Likes

Hmm… I encountered an indentation bug as well everytime I code, in the last few days.
The indents are too much, or too little, so I will need to backspace or add more indents.
Because of this, the else in the if statement gets unindented to no indents, causing an error, so I would need to indent the else line.
Is this the same bug?

1 Like

I believe this is the first/second issue in my report. The editor doesn’t know where your functions end. This causes code written later in the file to be messed up as the editor is confused about indentation.

Diagnosis:
Right click the file tab in the editor and click “Toggle all folds”. If your function folds are hiding too much code, then it suggests the editor is getting confused.

2 Likes

Thanks for the detailed write-up and examples @NuclearPasta0. There are multiple issues here, but I’ll get this reported and see what we can address.

2 Likes

I never collapse any code.
I tried it, nothing helped t fix the indents. I still need to indent 3-5 times to get the indents correct

1 Like

@NuclearPasta0 We pushed a fix that we believe fixed the first two issues. Would you be able to verify?

The third issue we are investigating separately. That may take a bit longer.

The fourth issue is expected behavior at this time. However, you can enable “Indentation Detection” in the User Settings if you want your indentation to be adapted to the file. We might consider making this a default setting if it’s less confusing for folks. Also, we may add configuration in the future so that people can save a set indentation, but this is not planned yet and would be a feature enhancement.

4 Likes

Thanks, the first two issues are fixed.

I will also now use indentation detection as it basically solves the 4th issue without downsides.

Since two issues are solved, one has a feature that works for it, and one is pending, I will mark this topic as solved.

3 Likes

I can confirm that my issue is fixed.
Thanks @SuzyAtReplit !

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.