Skip to content

Mixed tabs and spaces in indentation compile silently with tab = 8 instead of being rejected #227

Description

@zimri-leisher

PythonIndenter counts a tab as 8 columns and never checks that the lines of a block use consistent indentation characters, so a file mixing tabs and spaces compiles with whatever nesting the 8-column rule happens to give. Python rejects the same input with TabError. A sequence written in an editor that shows tabs as 4 columns therefore silently changes meaning: below, the author reads the last assignment as inside if b, but the compiler puts it inside if a only, so n ends at 10 and the assert fails at runtime on both backends.

a: bool = True
b: bool = False
n: I64 = 0
if a:
	if b:                 # one tab
		n = n + 1         # two tabs
        n = n + 10        # eight spaces: dedents to `if a` for the compiler, looks like two tabs to the author
assert n == 0, 1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions