classification
Title: Improve syntax error for mixing keyword/positional in max patterns
Type: Stage: resolved
Components: Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: brandtbucher, miss-islington, pablogsal
Priority: normal Keywords: patch

Created on 2021-06-18 21:07 by pablogsal, last changed 2021-06-24 15:36 by pablogsal. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 26793 merged pablogsal, 2021-06-18 21:09
PR 26900 merged miss-islington, 2021-06-24 15:10
Messages (6)
msg396088 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-06-18 21:07
This got me confused for a sec when doing some live demo:

>>> match x:
...    case A(y=1, foo):
  File "<stdin>", line 2
    case A(y=1, foo):
                   ^
SyntaxError: invalid syntax

I propose to improve this to:

>>> match x:
...    case A(y=1, foo):
  File "<stdin>", line 2
    case A(y=1, foo):
                ^^^
SyntaxError: cannot mix keyword patterns and positional patterns
msg396090 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-06-18 21:11
Btw, I noticed this is allowed:

>>> match x:
...    case A(foo, t=3):
...        ...
...

but this is not:

>>> match x:
...    case A(foo=3, t):

Is that on pourpose?
msg396091 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-06-18 21:14
If this is supposed to mirror function calls, maybe the error should be::

>>> match a:
...    case A(foo=3, t):
  File "<stdin>", line 2
    case A(foo=3, t):
                  ^
SyntaxError: positional patterns follow keyword patterns
msg396100 - (view) Author: Brandt Bucher (brandtbucher) * (Python committer) Date: 2021-06-18 21:40
Yep, it's intentional.

And yep, I like the new error message better. :)
msg396493 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-06-24 15:10
New changeset 0acc258fe6f0ec200ca2f6f9294adbf52a244802 by Pablo Galindo in branch 'main':
bpo-44456: Improve the syntax error when mixing keyword and positional patterns (GH-26793)
https://github.com/python/cpython/commit/0acc258fe6f0ec200ca2f6f9294adbf52a244802
msg396495 - (view) Author: miss-islington (miss-islington) Date: 2021-06-24 15:34
New changeset 11f1a30cdb59f9da0209798d2057f7afacbd9547 by Miss Islington (bot) in branch '3.10':
bpo-44456: Improve the syntax error when mixing keyword and positional patterns (GH-26793)
https://github.com/python/cpython/commit/11f1a30cdb59f9da0209798d2057f7afacbd9547
History
Date User Action Args
2021-06-24 15:36:05pablogsalsetresolution: fixed
2021-06-24 15:36:01pablogsalsetstatus: open -> closed
stage: patch review -> resolved
2021-06-24 15:34:42miss-islingtonsetmessages: + msg396495
2021-06-24 15:10:11miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request25476
2021-06-24 15:10:06pablogsalsetmessages: + msg396493
2021-06-18 21:40:03brandtbuchersetmessages: + msg396100
2021-06-18 21:14:02pablogsalsetmessages: + msg396091
2021-06-18 21:11:13pablogsalsetmessages: + msg396090
2021-06-18 21:09:02pablogsalsetkeywords: + patch
stage: patch review
pull_requests: + pull_request25377
2021-06-18 21:07:47pablogsalcreate