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

more argument error improving #56565

Closed
benjaminp opened this issue Jun 18, 2011 · 4 comments
Closed

more argument error improving #56565

benjaminp opened this issue Jun 18, 2011 · 4 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@benjaminp
Copy link
Contributor

BPO 12356
Nosy @ncoghlan, @benjaminp
Files
  • argerror.patch
  • 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 2011-06-24.14:37:39.562>
    created_at = <Date 2011-06-18.00:45:31.191>
    labels = ['interpreter-core', 'type-feature']
    title = 'more argument error improving'
    updated_at = <Date 2011-06-24.14:37:39.561>
    user = 'https://github.com/benjaminp'

    bugs.python.org fields:

    activity = <Date 2011-06-24.14:37:39.561>
    actor = 'python-dev'
    assignee = 'none'
    closed = True
    closed_date = <Date 2011-06-24.14:37:39.562>
    closer = 'python-dev'
    components = ['Interpreter Core']
    creation = <Date 2011-06-18.00:45:31.191>
    creator = 'benjamin.peterson'
    dependencies = []
    files = ['22399']
    hgrepos = []
    issue_num = 12356
    keywords = ['patch']
    message_count = 4.0
    messages = ['138563', '138868', '138887', '138950']
    nosy_count = 3.0
    nosy_names = ['ncoghlan', 'benjamin.peterson', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue12356'
    versions = ['Python 3.3']

    @benjaminp
    Copy link
    Contributor Author

    After completing bpo-12265, it was pointed out to me that the error message is still not perfect:

    >>> def f(a, b, c=3, d=4, e=6, f=3, g=32): pass
    ... 
    >>> f(1, f=4, d=90)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: f() takes from 2 to 7 positional arguments but 3 were given

    Here is a new patch.

    Some samples:

    >>> def f(a): pass
    ... 
    >>> f()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: f() missing 1 required positional argument: 'a'
    >>> def f(a, b): pass
    ... 
    >>> f()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: f() missing 2 required positional arguments: 'a' and 'b'
    
    >>> def f(a, b, c): pass
    ... 
    >>> f()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: f() missing 3 required positional arguments: 'a', 'b', and 'c
    >>> def f(a, b, c, d): pass
    >>> f()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: f() missing 4 required positional arguments: 'a', 'b', 'c', and 'd'

    Same with kwonly:

    >>> def f(*, w): pass
    ... 
    >>> f()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: f() missing 1 required keyword-only argument: 'w'
    >>> def f(*, a, b, c, d, e): pass
    ... 
    >>> f()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: f() missing 5 required keyword-only arguments: 'a', 'b', 'c', 'd', and 'e'

    For too many positional arguments, the old (new) error is retained:

    >>> def f(a): pass
    ... 
    >>> f(1, 2, 3)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: f() takes 1 positional argument but 3 were given
    >>> f(3, 4, 5)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: f() takes from 1 to 2 positional arguments but 3 were given

    @benjaminp benjaminp added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement labels Jun 18, 2011
    @benjaminp
    Copy link
    Contributor Author

    Nick (or anyone else), do you want to look at this?

    @ncoghlan
    Copy link
    Contributor

    Revised error messages and tests look reasonable and the code seems fine on a visual scan.

    +1 from me.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jun 24, 2011

    New changeset 52744a5a9260 by Benjamin Peterson in branch 'default':
    give the names of missing positional or keyword-only arguments (closes bpo-12356)
    http://hg.python.org/cpython/rev/52744a5a9260

    @python-dev python-dev mannequin closed this as completed Jun 24, 2011
    @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
    interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants