You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python: _ styled as a keyword in case[_]: int = 1 #242
Applies to the PyCaseWildcardPattern added in #236 (not on main yet).
When a snippet has no enclosing block, the pattern accepts any line that looks like a case clause. case[_]: int = 1 at the top level fits that shape, so its _ gets keyword styling even though Python reads the line as an annotated assignment to case[_].
Steps to reproduce
useTempest\Highlight\Highlighter;
echo (newHighlighter())->parse('case[_]: int = 1', 'python');
Expected
_ stays plain. Python's ast parses the line as AnnAssign(target=Subscript(value=Name('case'), slice=Name('_'))).
Actual
case[<span class="hl-keyword">_</span>]: ...
Notes
This only happens at a snippet's top level. Inside an if, def or any block other than match, the line is left alone.
Top-level snippets are still accepted on purpose, because docs often show case _: without its match line. Telling the two apart would need something like "only = after the colon means an annotation", which a real case body such as case [x]: y = 1 breaks.
Activity