[New-bugs-announce] [issue38496] Python3 allows mixture of tabs and spaces for indentation

Mikko Rantalainen report at bugs.python.org
Wed Oct 16 04:00:10 EDT 2019


New submission from Mikko Rantalainen <mikko.rantalainen at peda.net>:

Contrary to PEP-8 (https://www.python.org/dev/peps/pep-0008/#tabs-or-spaces) claiming "Python 3 disallows mixing the use of tabs and spaces for indentation", in reality Python 3 allows mixing tabs and spaces without warnings or errors. For example (with all spaces replaced with middle dot and all spaces replaced with a short arrow):

#!/usr/bin/python3
for·i·in·range(2):
··for·j·in·range(3):
➧··for·k·in·range(4):
·➧···print(i,j,k,sep=",")

Either the PEP-8 should be fixed or the parser/compiler should be fixed. 

The current behavior seems a bit unstable because the exact order of spaces and tabs causes "TabError: inconsistent use of tabs and spaces in indentation" to appear more or less random.

I'd prefer python3 to require that *all whitespace* at the start of the all the lines is tabs for the whole file or spaces for the whole file. And first indented line sets the preference for the whole file.

(Personally I'd prefer tabs contrary to PEP-8 language but this bug is not about the preference. This is PEP-8 claiming things that are not true.)

$ python3 --version
Python 3.5.2

----------
components: Interpreter Core
messages: 354779
nosy: Mikko Rantalainen
priority: normal
severity: normal
status: open
title: Python3 allows mixture of tabs and spaces for indentation
versions: Python 3.5

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38496>
_______________________________________


More information about the New-bugs-announce mailing list