Why not enforce four space indentations in version 3.x?

David Bolen db3l.net at gmail.com
Tue Jul 14 17:06:03 EDT 2009


John Nagle <nagle at animats.com> writes:

>    Python 3 enforces the rule that you can't mix tabs and spaces
> for indentation in the same file.  That (finally) guarantees that
> the indentation you see is what the Python parser sees.  That's
> enough to prevent non-visible indentation errors.

Are you sure?  It seems to restrict them in the same block, but not in
the entire file.  At least I was able to use both space and tab
indented blocks in the same file with Python 3.0 and 3.1.  I suspect
precluding any mixture at all at the file level would be more
intrusive, for example, when trying to combine multiple code sources
in a single file.

Not that this really changes your final point, since the major risk
of a mismatch between the parser vs. visual display is within a single
block.

>    It also means that the Python parser no longer has to have
> any concept of how many spaces equal a tab.  So the problem
> is now essentially solved.

"has to have" being a future possibility at this point, since I'm
fairly sure the 3.x parser does technically still have the concept of
a tab size of 8, though now it can be an internal implementation
detail.

-- David



More information about the Python-list mailing list