Skip to content

[Bug]: Key error from failed pattern matching #1003

Description

@da-woods

Describe the bug

def f(arg):
    match arg:
        case {"a": a, "b": b}:
            print(f"case ab: {a} {b}")
        case {"x": x, "y": y, **keys}:
            print(f"case xy: {x} {y} {keys}")
       case {**keys}:
            print(f"case keys: {keys}")
       case _:
            print("Unmatched")
>>> f(dict(p=1, q=2))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 5, in f
KeyError: 'x'

(The traceback comes from the line case {"x": x, "y": y, **keys}: but my quick copy-paste demo from the REPL doesn't show that very well).

The expected result is that this should be matched by case {**keys}:

Operating system

Linux

CPU architecture

x86_64

GraalPy version

25.1.3 / Python 3.12.8 (Tue Jun 23 15:26:01 UTC 2026)

JDK version

No response

Context configuration

No response

Steps to reproduce

See description section

Expected behavior

See description section

Stack trace

Additional context

This started failing in the Cython test suite when run as a pure-Python (i.e. not compiled) test (it runs file compiled, but that isn't your problem)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions