[docs] [issue29387] Tabs vs spaces FAQ out of date

Martin Panter report at bugs.python.org
Sat Feb 4 03:33:17 EST 2017


Martin Panter added the comment:

Marco: I agree “Python reports an error” would have been simpler. That is what I meant to say. Anyway, perhaps we should put

Python raises :exc:`IndentationError` if mixed tabs and spaces are causing problems in leading whitespace.

In general, the exception seems to be IndentationError. TabError is a subclass, but is not raised in all circumstances. It seems the compiler assumes a particular tab model, so the exact exception depends on the amount of tabs and spaces:

>>> exec("if True:\n" + " "*8 + "1\n" "\t2\n")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 3
    2
    ^
TabError: inconsistent use of tabs and spaces in indentation
>>> exec("if True:\n" + " "*9 + "1\n" "\t2\n")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 3
    2
    ^
IndentationError: unindent does not match any outer indentation level

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29387>
_______________________________________


More information about the docs mailing list