1

Sublime Text, build 3175, Macos

Every so often I will randomly get an IndentationError: unexpected indent message on a previously working Python file.

Inspecting the file in the editor does not show an indentation issue and I suspect a tab got sneaked in somehow.

Clicking at the bottom right of the window, Spaces, next to Python which indicates the source language, allows me to pick Convert indentation to spaces. That "changes the file" which now shows as changed and will request a save if closed. And my problem is solved.

This has only happened since the past 2 or 3 months and I never had this problem before, so I assume it was a recent change in Sublime that occasionally mangles either the tab vs. space indentation.

This is extremely irritating as there is a) no indication of what caused the problem and b) it can happy at any time on any file that has been edited at some point. And even more so when it hits at the end of a long build process.

How do I avoid this? I tried creating a Packages/User/Python.sublime-settings file, with the following in it, but that didn't help.

// These settings override both User and Default settings for the Python syntax
{
    "translate_tabs_to_spaces" : 1
}
2

As far as I know, the translate_tabs_to_spaces only accepts boolean values, so you need to write your settings like this:

{
    "translate_tabs_to_spaces": true
}

I also recommend setting draw_white_space to all. This highlights all whitespace, making it easier to distinguish spaces from tabs:

enter image description here

| improve this answer | |
  • since it was an intermittent issue I waited a bit, but this did the trick – JL Peyret Jul 4 '18 at 5:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.