classification
Title: Indentation explanation is unclear
Type: enhancement Stage:
Components: Documentation Versions: Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Jérôme LAURENS, docs@python
Priority: normal Keywords:

Created on 2019-02-10 17:26 by Jérôme LAURENS, last changed 2019-02-12 13:00 by Jérôme LAURENS.

Messages (2)
msg335165 - (view) Author: Jérôme LAURENS (Jérôme LAURENS) Date: 2019-02-10 17:26
https://docs.python.org/3/reference/lexical_analysis.html#indentation reads

Point 1:
"Tabs are replaced (from left to right) by one to eight spaces such that the total number of characters up to and including the replacement is a multiple of eight"

and in the next paragraph

Point 2:
"Indentation is rejected as inconsistent if a source file mixes tabs and spaces in a way that makes the meaning dependent on the worth of a tab in spaces"

In point 1, each tab has definitely a unique space counterpart, in point 2, tabs may have different space counterpart, which one is reliable ?

The documentation should state that Point 1 concerns cPython, or at least indicate that the 8 may depend on the implementation, which then gives sense to point 2.
msg335300 - (view) Author: Jérôme LAURENS (Jérôme LAURENS) Date: 2019-02-12 13:00
To be more precise, consider code

def f(x):
       \tx=0 # 7 spaces + one tab
        return x # 8 spaces

In cpython, both indentation levels are 8 and no indentation error is reported (this is the case where both tab size and alt tab size are equal)

If instead of 8 the tab would count for 6 spaces, then we would have 12 and 8 as indentation level, resulting in a mismatch and an indentation error being reported, according to the documentation. This is inconsistent.
Then either the documentation is faulty or cpython is.

Actually, cpython accepts a mix of space and tabs only when tabs are in 8, 16, 24... positions.
History
Date User Action Args
2019-02-12 13:00:45Jérôme LAURENSsetmessages: + msg335300
2019-02-10 17:26:57Jérôme LAURENScreate