Skip to content

Incorrect error message: "missing 1 required positional argument" #90795

Open

Description

@boxed
mannequin
BPO 46637
Nosy @terryjreedy, @ericvsmith, @aroberge, @boxed, @AlexWaygood

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 = None
created_at = <Date 2022-02-04.15:54:15.436>
labels = ['interpreter-core', 'type-feature', '3.11']
title = 'Incorrect error message: "missing 1 required positional argument"'
updated_at = <Date 2022-02-05.00:40:55.384>
user = 'https://github.com/boxed'

bugs.python.org fields:

activity = <Date 2022-02-05.00:40:55.384>
actor = 'AlexWaygood'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Interpreter Core']
creation = <Date 2022-02-04.15:54:15.436>
creator = 'Anders.Hovm\xc3\xb6ller'
dependencies = []
files = []
hgrepos = []
issue_num = 46637
keywords = []
message_count = 6.0
messages = ['412510', '412511', '412514', '412519', '412520', '412530']
nosy_count = 5.0
nosy_names = ['terry.reedy', 'eric.smith', 'aroberge', 'Anders.Hovm\xc3\xb6ller', 'AlexWaygood']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue46637'
versions = ['Python 3.11']

Linked PRs

Activity

  1. boxed commented on Feb 4, 2022

    boxedmannequin
    MannequinAuthor
    >>> def foo(a):
    ...     pass
    ... 
    >>> foo()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: foo() missing 1 required positional argument: 'a'

    This error is incorrect. It says "positional argument", but it's just "argument". The proof is that if you call it with

    foo(a=3)

    it works fine.

  2. ericvsmith commented on Feb 4, 2022

    @ericvsmith
    Member

    I guess the technically correct term is positional-or-keyword, but that seems like too much: https://docs.python.org/3/glossary.html

    I think dropping "positional" doesn't increase the precision of the error message, but I'll admit I can't think of anything better. And lacking something better I don't think we should change this.

  3. boxed commented on Feb 4, 2022

    boxedmannequin
    MannequinAuthor

    Just dropping the word "positional" is very good. That word is a lie, and just removing it makes it true.

  4. ericvsmith commented on Feb 4, 2022

    @ericvsmith
    Member

    Given this current behavior:

    >>> def foo(a, /, b): pass
    ...
    >>> foo()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: foo() missing 2 required positional arguments: 'a' and 'b'

    What would you suggest?

    I agree the current messages aren't perfect.

  5. boxed commented on Feb 4, 2022

    boxedmannequin
    MannequinAuthor

    For foo(a, /, b), it could be:

    "TypeError: foo() missing 1 required argument 'a', and one required positional argument 'b'.

    If we start on this road there are some more, like for def foo(a, *, b) you get the error "TypeError: foo() missing 1 required positional argument: 'a'" which leaves out that the keyword only argument is also required.

    Another solution would be something like:

    TypeError: foo() missing 3 required arguments: 'a' (positional only), 'b', 'c' (keyword only)

    This solution scales to the worst complex cases, and is a lot clearer imo. Could even be further improved with some nicer formatting:

    TypeError: foo() missing 3 required arguments:
    'a' (positional only)
    'b'
    'c' (keyword only)

    But that might be a bit overkill :)

  6. terryjreedy commented on Feb 4, 2022

    @terryjreedy
    Member

    I think the incorrect qualification should be dropped, if sanely feasible.

    More misleading are hidden positional-only args. Doc:
    min(iterable, *[, key, default])
    min(arg1, arg2, *args[, key])

    >>> min(iterator=(1,3))
    Traceback (most recent call last):
      File "<pyshell#0>", line 1, in <module>
        min(iterator=(1,3))
    TypeError: min expected at least 1 argument, got 0

    1 was passed, but 0 were gotten, as the 1 passed was silently ignored.

  7. added
    3.11only security fixes
    and removed on Feb 4, 2022
  8. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions