homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Python3 allows mixture of tabs and spaces for indentation
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.5
process
Status: closed Resolution: duplicate
Dependencies: Superseder: TabError behavior doesn't match documentation
View: 24260
Assigned To: Nosy List: Mikko Rantalainen, eric.smith, serhiy.storchaka, steven.daprano, xtreak
Priority: normal Keywords:

Created on 2019年10月16日 08:00 by Mikko Rantalainen, last changed 2022年04月11日 14:59 by admin. This issue is now closed.

Messages (6)
msg354779 - (view) Author: Mikko Rantalainen (Mikko Rantalainen) Date: 2019年10月16日 08:00
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
msg354780 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2019年10月16日 08:05
I can verify this on 3.7.4.
msg354788 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2019年10月16日 08:57
I believe that the interpreter only requires that each block is consistent, not that all blocks in a module are consistent.
msg354791 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019年10月16日 09:25
Thank you for your report Mikko. Yes, the heuristic used in Python 3 is unable to catch all inconsistencies in using tabs and spaces.
Such bug was already reported early. There should be an open issue.
msg354795 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019年10月16日 11:30
Seems related issue24260 
msg354796 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2019年10月16日 11:32
Thanks, Serhiy. This has been reported in 24260, so I'm closing this issue.
History
Date User Action Args
2022年04月11日 14:59:21adminsetgithub: 82677
2019年10月16日 11:32:00eric.smithsetstatus: open -> closed
superseder: TabError behavior doesn't match documentation
messages: + msg354796

type: behavior
resolution: duplicate
stage: resolved
2019年10月16日 11:30:15xtreaksetnosy: + xtreak
messages: + msg354795
2019年10月16日 09:25:58serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg354791
2019年10月16日 08:57:31steven.dapranosetnosy: + steven.daprano
messages: + msg354788
2019年10月16日 08:05:23eric.smithsetnosy: + eric.smith
messages: + msg354780
2019年10月16日 08:00:10Mikko Rantalainencreate

AltStyle によって変換されたページ (->オリジナル) /