Mailing List Archive

[issue44456] Improve syntax error for mixing keyword/positional in max patterns
New submission from Pablo Galindo Salgado <pablogsal@gmail.com>:

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

----------
messages: 396088
nosy: brandtbucher, pablogsal
priority: normal
severity: normal
status: open
title: Improve syntax error for mixing keyword/positional in max patterns

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44456>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44456] Improve syntax error for mixing keyword/positional in max patterns [ In reply to ]
Change by Pablo Galindo Salgado <pablogsal@gmail.com>:


----------
keywords: +patch
pull_requests: +25377
stage: -> patch review
pull_request: https://github.com/python/cpython/pull/26793

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44456>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44456] Improve syntax error for mixing keyword/positional in max patterns [ In reply to ]
Pablo Galindo Salgado <pablogsal@gmail.com> added the comment:

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?

----------

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44456>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44456] Improve syntax error for mixing keyword/positional in max patterns [ In reply to ]
Pablo Galindo Salgado <pablogsal@gmail.com> added the comment:

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

----------

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44456>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44456] Improve syntax error for mixing keyword/positional in max patterns [ In reply to ]
Brandt Bucher <brandtbucher@gmail.com> added the comment:

Yep, it's intentional.

And yep, I like the new error message better. :)

----------

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44456>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44456] Improve syntax error for mixing keyword/positional in max patterns [ In reply to ]
Pablo Galindo Salgado <pablogsal@gmail.com> added the comment:


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


----------

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44456>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44456] Improve syntax error for mixing keyword/positional in max patterns [ In reply to ]
Change by miss-islington <mariatta.wijaya+miss-islington@gmail.com>:


----------
nosy: +miss-islington
nosy_count: 2.0 -> 3.0
pull_requests: +25476
pull_request: https://github.com/python/cpython/pull/26900

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44456>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44456] Improve syntax error for mixing keyword/positional in max patterns [ In reply to ]
miss-islington <mariatta.wijaya+miss-islington@gmail.com> added the comment:


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


----------

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44456>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44456] Improve syntax error for mixing keyword/positional in max patterns [ In reply to ]
Change by Pablo Galindo Salgado <pablogsal@gmail.com>:


----------
stage: patch review -> resolved
status: open -> closed

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44456>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44456] Improve syntax error for mixing keyword/positional in max patterns [ In reply to ]
Change by Pablo Galindo Salgado <pablogsal@gmail.com>:


----------
resolution: -> fixed

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44456>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com