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

Report details of excess arguments in object_new & object_init #75708

Open
ncoghlan opened this issue Sep 20, 2017 · 3 comments
Open

Report details of excess arguments in object_new & object_init #75708

ncoghlan opened this issue Sep 20, 2017 · 3 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@ncoghlan
Copy link
Contributor

BPO 31527
Nosy @ncoghlan, @serhiy-storchaka
Dependencies
  • bpo-31506: Improve the error message logic for object_new & object_init
  • 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 2017-09-20.05:17:57.406>
    labels = ['type-feature']
    title = 'Report details of excess arguments in object_new & object_init'
    updated_at = <Date 2017-09-20.06:14:25.997>
    user = 'https://github.com/ncoghlan'

    bugs.python.org fields:

    activity = <Date 2017-09-20.06:14:25.997>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = []
    creation = <Date 2017-09-20.05:17:57.406>
    creator = 'ncoghlan'
    dependencies = ['31506']
    files = []
    hgrepos = []
    issue_num = 31527
    keywords = []
    message_count = 3.0
    messages = ['302591', '302592', '302597']
    nosy_count = 2.0
    nosy_names = ['ncoghlan', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'needs patch'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue31527'
    versions = []

    @ncoghlan
    Copy link
    Contributor Author

    object_new and object_init currently use their own argument checking logic, and hence haven't benefited from the error reporting enhancements in PyArg_ParseTupleAndKeywords

    Compare:

    >>> str(1, 2, 3, 4, 5, x=1)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: str() takes at most 3 arguments (6 given)
    >>> str(x=1)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: 'x' is an invalid keyword argument for this function

    To:

    >>> C(1, 2, 3, 4)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: object() takes no parameters
    >>> C(x=1)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: object() takes no parameters

    bpo-31506 amends the latter to at least report the subclass name rather than the base class name, but doesn't cover any other enhancements, like reporting how many arguments were actually given, or the first unknown keyword argument name.

    @ncoghlan ncoghlan added the type-feature A feature request or enhancement label Sep 20, 2017
    @ncoghlan
    Copy link
    Contributor Author

    Adding a dependency on bpo-31506, as this shouldn't be tackled until those simpler amendments are resolved.

    @serhiy-storchaka
    Copy link
    Member

    str(x=1) is not the best example since str() takes keyword arguments. Look at tuple() and list():

    >>> tuple(x=1)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: tuple() takes no keyword arguments
    >>> list(x=1)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: list() takes no keyword arguments

    Initial version of my patch for bpo-31506 reported error messages similar to tuple() and list(), but at end I simplified it since in any case the error message was not perfect.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @iritkatriel iritkatriel added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Nov 23, 2023
    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

    3 participants