Skip to content

"SyntaxError: non-default argument follows default argument" confuses #91210

Closed

Description

@Bluenix2
mannequin
BPO 47054
Nosy @terryjreedy, @gpshead, @vedgar, @pablogsal, @Bluenix2
PRs
  • bpo-47054: Call params parameters not arguments in SyntaxErrors. #32014
  • 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 = 'https://github.com/gpshead'
    closed_at = None
    created_at = <Date 2022-03-18.01:17:42.872>
    labels = ['interpreter-core', 'type-bug', '3.10', '3.11']
    title = '"SyntaxError: non-default argument follows default argument" confuses'
    updated_at = <Date 2022-03-20.21:18:26.112>
    user = 'https://github.com/Bluenix2'

    bugs.python.org fields:

    activity = <Date 2022-03-20.21:18:26.112>
    actor = 'gregory.p.smith'
    assignee = 'gregory.p.smith'
    closed = False
    closed_date = None
    closer = None
    components = ['Interpreter Core']
    creation = <Date 2022-03-18.01:17:42.872>
    creator = 'bluenix'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 47054
    keywords = ['patch']
    message_count = 4.0
    messages = ['415463', '415469', '415526', '415530']
    nosy_count = 5.0
    nosy_names = ['terry.reedy', 'gregory.p.smith', 'veky', 'pablogsal', 'bluenix']
    pr_nums = ['32014']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue47054'
    versions = ['Python 3.10', 'Python 3.11']

    Activity

    1. Bluenix2 commented on Mar 18, 2022

      Bluenix2mannequin
      MannequinAuthor

      Running the code below will produce a SyntaxError with the message: "non-default argument follows default argument".

          def test(a=None, b):
              return b if a is None else a

      The issue is that a and b aren't arguments, rather, they are parameters. The error message should be changed to: "non-default parameter follows default parameter".

      This change appears simple enough and although it is not something I've found to be troublesome, it will help users to use correct keywords (arguments vs. parameters) when searching on the internet.

    2. vedgar commented on Mar 18, 2022

      vedgarmannequin
      Mannequin

      The problem is more subtle. The thing is, "default parameter" doesn't make sense in this context. Yes, a and b are parameter, but a is not "default parameter" in any sensible way. It is _None_ which is the default argument for parameter a, while parameter b has no default argument. In other words, if the function weren't called with a first argument, the default argument would be used.

      So, the fix should be a bit more complicated. Maybe, "a parameter without a default follows a parameter with a default"?

    3. Bluenix2 commented on Mar 18, 2022

      Bluenix2mannequin
      MannequinAuthor

      Yes I agree, that would be the best.

    4. terryjreedy commented on Mar 19, 2022

      @terryjreedy
      Member

      Current message same in 3.11 and 3.9, but I am not sure about backporting to old parser. However merges a change, if any, can decide.

    5. 7 remaining items

    6. added
      type-bugAn unexpected behavior, bug, or error
      and removed on Mar 19, 2022
    7. changed the title [-]"SyntaxError: non-default argument follows default argument" should be "parameter"[/-] [+]"SyntaxError: non-default argument follows default argument" confuses[/+] on Mar 19, 2022
    8. changed the title [-]"SyntaxError: non-default argument follows default argument" should be "parameter"[/-] [+]"SyntaxError: non-default argument follows default argument" confuses[/+] on Mar 19, 2022
    9. transferred this issue fromon Apr 10, 2022
    10. lysnikolaou commented on Aug 12, 2022

      @lysnikolaou
      Member

      In addition to this, we fall back to the generic invalid syntax message, in case there are positional-only parameters before the failing ones:

      >>> def test(a=None, b):
        File "<stdin>", line 1
          def test(a=None, b):
                           ^
      SyntaxError: non-default argument follows default argument
      >>> def test(a, /, b=None, c):
        File "<stdin>", line 1
          def test(a, /, b=None, c):
                                  ^
      SyntaxError: invalid syntax

      @gpshead you still intend to work on this? I can open a PR for it in case you won't.

    11. gpshead commented on Aug 12, 2022

      @gpshead
      Member

      I've lost track of why I assigned this to myself (I didn't leave myself a comment? tsk tsk), so no, feel free to take it!

    12. removed their assignment
      on Aug 12, 2022
    13. self-assigned this
      on Aug 12, 2022
    14. added a commit that references this issue on Aug 12, 2022
    15. added a commit that references this issue on Sep 17, 2022
    16. hauntsaninja commented on Oct 12, 2022

      @hauntsaninja
      Contributor

      Thanks, looks like this has been fixed :-)

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    3.10 (EOL)end of life3.11only security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions