Python 3 allows mixing spaces and tabs?

Viewed 6785

I know there are many questions on tabs vs. spaces, but it appears that, contrary to what PEP 0008 says about Python 3, mixing tabs and spaces is not always illegal. Specifically, mixing tabs and spaces in the same block is illegal, but blocks with spaces and blocks with tabs are allowed in the same file.

For example, this throws a TabError on Python 3.4:

for x in range(10):
    print(x)  # Spaces
    print(x)  # Tab

But this runs fine:

for x in range(10):
    print(x)  # Spaces

for y in range(5):
    print(y)  # Tab

Is this by design?

Edit: The question is not whether tabs are better than spaces. The question is whether Python's allowing tabs and spaces in the same file is by design.

2 Answers
Related