Skip to content

Confusing SyntaxError when using {**_} inside PM's mapping pattern #162045

Open

Description

@sobolevn
>>> match {}:
...     case {**_}: print('a')
...     
  File "<python-input-0>", line 2
    case {**_}: print('a')
            ^
SyntaxError: invalid syntax

and

>>> match {}:
...     case {'a': a, **_}: print('a', a)
...     
  File "<python-input-2>", line 2
    case {'a': a, **_}: print('a', a)
                    ^
SyntaxError: invalid syntax

But:

>>> match {}:
...     case {**_name}: print('a')
...     
a

Refs https://peps.python.org/pep-0634/#mapping-patterns
Which says:

(Note that **_ is disallowed by this syntax.)

I think that the syntax error must be better here :)
Related to #138865

Linked PRs

Activity

  1. self-assigned this
    on Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-parsertype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions