spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.21k stars 1.59k forks source link

TabError: inconsistent use of tabs and spaces in indentation #10561

Open SvenMeyer opened 4 years ago

SvenMeyer commented 4 years ago

Description

What steps will reproduce the problem?

I prefer Sypder over a larger IDE to have a lighter tool to try some code. So I am copy-pasting a lot of code from external source, add something, ... Too often I get the error message "TabError: inconsistent use of tabs and spaces in indentation", likely because some code uses spaces other tabs. Manual fixing this is quite cumbersome. The function "fix identation" does help here either.

On top of that when I actually give up and replace tabs with spaces, delete the tab, insert spaces, the "tool tips" pop up for no reason ... and if I press the wrong button, I also suddenly have some code in there which I did not want.

Makes this version of Spyder almost unusable ....

Versions

Dependencies

cloudpickle >=0.5.0          :  1.2.2 (OK)
pygments >=2.0               :  2.4.2 (OK)
qtconsole >=4.5.5            :  4.5.5 (OK)
nbconvert >=4.0              :  5.6.1 (OK)
sphinx >=0.6.6               :  2.2.1 (OK)
pylint >=0.25                :  2.4.3 (OK)
psutil >=0.3                 :  5.6.3 (OK)
qtawesome >=0.5.7            :  0.6.0 (OK)
qtpy >=1.5.0                 :  1.9.0 (OK)
pickleshare >=0.4            :  0.7.5 (OK)
zmq >=17                     :  18.1.0 (OK)
chardet >=2.0.0              :  3.0.4 (OK)
numpydoc >=0.6.0             :  0.9.1 (OK)
spyder_kernels >=1.5.0;<2.0.0:  1.6.0 (OK)
qdarkstyle >=2.7             :  2.7 (OK)
atomicwrites >=1.2.0         :  1.3.0 (OK)
diff_match_patch >=20181111  :  20181111 (OK)
watchdog                     :  None (OK)
keyring                      :  None (OK)
pexpect >=4.4.0              :  4.7.0 (OK)
pympler                      :  None (OK)
sympy >=0.7.3                :  None (NOK)
cython >=0.21                :  None (NOK)
IPython >=4.0                :  7.9.0 (OK)
matplotlib >=2.0.0           :  None (NOK)
pandas >=0.13.1              :  None (NOK)
numpy >=1.7                  :  None (NOK)
scipy >=0.17.0               :  None (NOK)
pyls >=0.28.2;<0.29.0        :  0.28.3 (OK)
xdg >=0.26                   :  0.26 (OK)
ccordoba12 commented 4 years ago

The function "fix identation" does help here either.

I guess you mean here "does not help". But why not? What's the problem? Please be more specific.

On top of that when I actually give up and replace tabs with spaces, delete the tab, insert spaces, the "tool tips" pop up for no reason ... and if I press the wrong button, I also suddenly have some code in there which I did not want.

I don't understand very well what you mean here. Please create a simple video and post it here to clarify.

isalirezag commented 4 years ago

this error is so annoying, im not sure why it happens, everytime it happens i have to fix it by opening the code in sublime text-->view-->identation-->convert identation to tabs

ccordoba12 commented 4 years ago

this error is so annoying

But what is the error? Please post the error so we can understand how to fix it.

SvenMeyer commented 4 years ago

As I described in the initial post: "So I am copy-pasting a lot of code from external source, add something, ..." Likely there is some code with used tabs for indentation others spaces, so you end up with mixture of both and get said error message. In the meantime I discovered the option to display spaces and tabs, so in that case you could spot the problem, but still you would need to (manually?) change every ident.

ccordoba12 commented 4 years ago

@SvenMeyer, please upload a file with mixed tabs and spaces for which "Fix indentation" is not working, to see if we can reproduce the error in our side.

isalirezag commented 4 years ago

@ccordoba12 fyi it is hard to provide an example here. why? because by copying and pasting it here it can mix the hiden info that cause that error to happens

goanpeca commented 4 years ago

You can attach a file @isalirezag or provide us with an error traceback (or both :-) )

ccordoba12 commented 4 years ago

@isalirezag, you can upload a file directly here instead of pasting its contents.

ccordoba12 commented 4 years ago

@SvenMeyer, @isalirezag, we're still waiting for a file from you guys.

isalirezag commented 4 years ago

untitled0.py.zip

@ccordoba12 This should give you the error :)

ccordoba12 commented 4 years ago

Great, thanks!

seyeeet commented 4 years ago

@ccordoba12 This bug still exists in spyder 4.1.1 I'm using ubuntu 16.04 Python 3.6.6 64-bit | Qt 5.9.6 | PyQt5 5.9.2 | Linux 4.15.0-91-generic

nishant2k commented 4 years ago

just clear the indentation and then again give identation by tab. It works in my case in spyder4

seyeeet commented 4 years ago

@nishant2k how to clear the indentation? it does not work for me

shivsn commented 3 years ago

Temporary solution is to change the indentation characters to 4 spaces in Tools>Preferences>Editor>Advanced settings.

behnood-eghbali commented 3 years ago

same issue here: Ubuntu 18.04 Spyder 4.1.4 Python 3.8.3