Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve syntax error for mixing keyword/positional in max patterns #88622

Closed
pablogsal opened this issue Jun 18, 2021 · 6 comments
Closed

Improve syntax error for mixing keyword/positional in max patterns #88622

pablogsal opened this issue Jun 18, 2021 · 6 comments

Comments

@pablogsal
Copy link
Member

BPO 44456
Nosy @pablogsal, @miss-islington, @brandtbucher
PRs
  • bpo-44456: Improve the syntax error when mixing keyword and positional patterns #26793
  • [3.10] bpo-44456: Improve the syntax error when mixing keyword and positional patterns (GH-26793) #26900
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-06-24.15:36:01.476>
    created_at = <Date 2021-06-18.21:07:47.426>
    labels = []
    title = 'Improve syntax error for mixing keyword/positional in max patterns'
    updated_at = <Date 2021-06-24.15:36:05.975>
    user = 'https://github.com/pablogsal'

    bugs.python.org fields:

    activity = <Date 2021-06-24.15:36:05.975>
    actor = 'pablogsal'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-06-24.15:36:01.476>
    closer = 'pablogsal'
    components = []
    creation = <Date 2021-06-18.21:07:47.426>
    creator = 'pablogsal'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 44456
    keywords = ['patch']
    message_count = 6.0
    messages = ['396088', '396090', '396091', '396100', '396493', '396495']
    nosy_count = 3.0
    nosy_names = ['pablogsal', 'miss-islington', 'brandtbucher']
    pr_nums = ['26793', '26900']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue44456'
    versions = []

    @pablogsal
    Copy link
    Member Author

    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

    @pablogsal
    Copy link
    Member Author

    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?

    @pablogsal
    Copy link
    Member Author

    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

    @brandtbucher
    Copy link
    Member

    Yep, it's intentional.

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

    @pablogsal
    Copy link
    Member Author

    New changeset 0acc258 by Pablo Galindo in branch 'main':
    bpo-44456: Improve the syntax error when mixing keyword and positional patterns (GH-26793)
    0acc258

    @miss-islington
    Copy link
    Contributor

    New changeset 11f1a30 by Miss Islington (bot) in branch '3.10':
    bpo-44456: Improve the syntax error when mixing keyword and positional patterns (GH-26793)
    11f1a30

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    None yet
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants