Skip to content

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

Open

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

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