Skip to content

TabError and IndentationError from line continuation #144018

Description

@ays684

Bug report

Bug description:

The documentation states:

Indentation cannot be split over multiple physical lines using backslashes; the whitespace up to the first backslash determines the indentation.

When this rule applies to some, but not all, lines in a block, a TabError is sometimes unexpectedly raised:

L1 = 'if 1:\n'
L2 = '    1\n'
L3 = '    \\\n'
L4 = '        1\n'
exec(L1 + L2 + L3 + L4)
# works as expected

L1 = 'if 1:\n'
L2 = '\t1\n'
L3 = '\t\\\n'
L4 = '\t\t1\n'
exec(L1 + L2 + L3 + L4)
# TabError: inconsistent use of tabs and spaces in indentation

Also, when a line containing only a backslash is explicitly joined with an indented line, an IndentationError is unexpectedly raised:

exec('\\\n    1')
# IndentationError: unexpected indent

CPython versions tested on:

3.10, 3.11, 3.12, 3.13, 3.14

Operating systems tested on:

macOS

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Jan 18, 2026
  2. picnixz commented on Jan 18, 2026

    @picnixz
    Member

    I think the last point is actually the expected behavior, at least to me. The continuation does not continue anything amd then we have a newline and some spaces so the indentation is wrong.

  3. picnixz commented on Jan 18, 2026

    @picnixz
    Member

    As for the mixed tabs error it does look like an issue.

  4. picnixz commented on Jan 18, 2026

    @picnixz
    Member
  5. ays684 commented on Jan 25, 2026

    @ays684
    Author

    I think the last point is actually the expected behavior, at least to me. The continuation does not continue anything amd then we have a newline and some spaces so the indentation is wrong.

    I would consider the whitespace before the backslash to be zero, not undefined. Zero makes more sense: for example, with that interpretation, the indentation levels of

       \
            1
      \
            1
     \
            1
    \
            1

    would be 3, 2, 1, and 8, respectively.

  6. HJX-001 commented on Feb 15, 2026

    @HJX-001
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

    interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-parsertype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions