jupyter / jupyter/notebook

Bad python syntax recognition for match-case statement

Open
#7,763 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Jupyter Notebook
Stars
13.3k
Forks
5.8k
Avg merge
6d 11h
Merged PRs (30d)
7

Description

## Description

The notebook editor seems to not recognise match-case statements properly, if the condition isn't extra simple.

Of course, this means bad highlighting which is a bit disappointing, but also messes up auto-indenting which really makes editing the code difficult.

## Reproduce

Make a python notebook, and add the following code (a simplified example, I encountered this with more meaningful code):

```python
match 1:
case 1 if True==True and True:
print(1)
case 2:
pass
```

If reproduced correctly, the `case 2:` part (line 4) has no highlight (make sure that the other stuff is highlighting as usual, I think I had to select a kernel? Usual notebook stuff).
In fact, the editor treats the match-case statement as ending at the first case, and inserting a newline at the beginning of it (`` with cursor at the end of line 2) will automatically drop the indent.

Notably, the same does not occur if line 2 is simply replaced by `case 1 if True and True:` or `case 1 if True==True:`.

The same reproduces in a fresh pyenv virtualenv, after a `pip install jupyterlab` (only `pip` and `wheel` in the base 3.13.3 install).
Let me know if hard to reproduce, I'll see what I can figure out to narrow stuff down.

## Expected behavior

Correctly handled match-case syntax.

## Context

- Operating System and version: Linux 6.17.7, Garuda Linux (arch derivative)
- Browser and version: Firefox 145.0
- Jupyter Notebook version: 7.4.4

Am using pyenv (don't think that should be an issue).

Troubleshoot Output
Yes, my $PATH is awful 😆

$PATH:

/home/james/.pyenv/versions/testrun/bin
/home/james/.pyenv/libexec
/home/james/.pyenv/plugins/python-build/bin
/home/james/.pyenv/plugins/pyenv-virtualenv/bin
/home/james/.pyenv/plugins/pyenv-update/bin
/home/james/.pyenv/plugins/pyenv-doctor/bin
/home/james/.nodenv/shims
/home/james/.pyenv/shims
/opt/llama-cpp/bin
/home/james/.nodenv/bin
/home/james/.cargo/bin
/home/james/.pyenv/bin
/home/james/.nodenv/shims
/usr/local/sbin
/usr/local/bin
/usr/bin
/usr/bin/site_perl
/usr/bin/vendor_perl
/usr/bin/core_perl
/home/james/.cargo/bin
/home/james/.pyenv/bin
/home/james/.cargo/bin
/home/james/.pyenv/bin

sys.path:
/home/james/.pyenv/versions/3.13.3/envs/testrun/bin
/home/james/.pyenv/versions/3.13.3/lib/python313.zip
/home/james/.pyenv/versions/3.13.3/lib/python3.13
/home/james/.pyenv/versions/3.13.3/lib/python3.13/lib-dynload
/home/james/.pyenv/versions/3.13.3/envs/testrun/lib/python3.13/site-packages

sys.executable:
/home/james/.pyenv/versions/3.13.3/envs/testrun/bin/python

sys.version:
3.13.3 (main, Nov 13 2025, 16:46:05) [GCC 15.2.1 20250813]

platform.platform():
Linux-6.17.7-zen1-1-zen-x86_64-with-glibc2.42

which -a jupyter:
/home/james/.pyenv/versions/testrun/bin/jupyter
/home/james/.pyenv/shims/jupyter

pip list:
Package Version
------------------------- -----------
anyio 4.11.0
argon2-cffi 25.1.0
argon2-cffi-bindings 25.1.0
arrow 1.4.0
asttokens 3.0.0
async-lru 2.0.5
attrs 25.4.0
babel 2.17.0
beautifulsoup4 4.14.2
bleach 6.3.0
certifi 2025.11.12
cffi 2.0.0
charset-normalizer 3.4.4
comm 0.2.3
debugpy 1.8.17
decorator 5.2.1
defusedxml 0.7.1
executing 2.2.1
fastjsonschema 2.21.2
fqdn 1.5.1
h11 0.16.0
httpcore 1.0.9
httpx 0.28.1
idna 3.11
ipykernel 7.1.0
ipython 9.7.0
ipython_pygments_lexers 1.1.1
isoduration 20.11.0
jedi 0.19.2
Jinja2 3.1.6
json5 0.12.1
jsonpointer 3.0.0
jsonschema 4.25.1
jsonschema-specifications 2025.9.1
jupyter_client 8.6.3
jupyter_core 5.9.1
jupyter-events 0.12.0
jupyter-lsp 2.3.0
jupyter_server 2.17.0
jupyter_server_terminals 0.5.3
jupyterlab 4.4.10
jupyterlab_pygments 0.3.0
jupyterlab_server 2.28.0
lark 1.3.1
MarkupSafe 3.0.3
matplotlib-inline 0.2.1
mistune 3.1.4
nbclient 0.10.2
nbconvert 7.16.6
nbformat 5.10.4
nest-asyncio 1.6.0
notebook_shim 0.2.4
packaging 25.0
pandocfilters 1.5.1
parso 0.8.5
pexpect 4.9.0
pip 25.0.1
platformdirs 4.5.0
prometheus_client 0.23.1
prompt_toolkit 3.0.52
psutil 7.1.3
ptyprocess 0.7.0
pure_eval 0.2.3
pycparser 2.23
Pygments 2.19.2
python-dateutil 2.9.0.post0
python-json-logger 4.0.0
PyYAML 6.0.3
pyzmq 27.1.0
referencing 0.37.0
requests 2.32.5
rfc3339-validator 0.1.4
rfc3986-validator 0.1.1
rfc3987-syntax 1.1.0
rpds-py 0.28.0
Send2Trash 1.8.3
setuptools 80.9.0
six 1.17.0
sniffio 1.3.1
soupsieve 2.8
stack-data 0.6.3
terminado 0.18.1
tinycss2 1.4.0
tornado 6.5.2
traitlets 5.14.3
typing_extensions 4.15.0
tzdata 2025.2
uri-template 1.3.0
urllib3 2.5.0
wcwidth 0.2.14
webcolors 25.10.0
webencodings 0.5.1
websocket-client 1.9.0

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the provided match-case example in a fresh JupyterLab installation, checking both syntax highlighting and auto-indentation in the notebook editor. Trace the editor's Python syntax-recognition behavior for the conditional expression and verify that the second case remains highlighted and indentation is preserved.

Written by the indexing model from the issue text.

Assessment

Tech stack
jupyter-notebook, python
Domain
developer-experience, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.