Skip to content

Python: case wildcard missed after a continuation line at column 0 #241

Closed as not planned

Description

@ArtMin96

Applies to the PyCaseWildcardPattern added in #236 (not on main yet).

A wildcard _ is missed when a statement in the previous case body continues onto a line at column 0, either inside brackets or after a \. The pattern finds the enclosing block by indentation, so it reads that continuation line as the enclosing block instead of the match.

Steps to reproduce

use Tempest\Highlight\Highlighter;

echo (new Highlighter())->parse("match command:\n    case 1:\n        y = foo(\n1)\n    case _:\n        pass", 'python');

Expected

case <span class="hl-keyword">_</span>:. Python's ast parses the second clause as MatchAs(), a wildcard.

Actual

case _:, with no highlighting.

Notes

  • y = 1 + \ followed by 2 at column 0 fails the same way.
  • With normal indentation (foo(\n 1)) the wildcard is highlighted.
  • A possible fix: track bracket depth and \ continuations in the existing lexing pass, and skip lines that start inside them.

Activity

  1. brendt commented on Oct 27, 2026

    @brendt
    Member

    Is this still an issue?

  2. Amoifr commented on Oct 27, 2026

    @Amoifr
    Contributor

    For what it's worth: this one is about PyCaseWildcardPattern from #236, which was closed so it could be split into smaller PRs. On current main (fca3aa7) there is no wildcard highlighting at all (case _: stays plain, and so does case[_]: int = 1), so it doesn't reproduce there. It would only matter again if the pattern comes back in one of the split PRs.

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