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

Error message incorrect when index is called with keyword argument ("[].index(x=2)") #74785

Closed
SylvainDe mannequin opened this issue Jun 8, 2017 · 8 comments
Closed
Labels
3.7 (EOL) end of life easy interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-argument-clinic type-bug An unexpected behavior, bug, or error

Comments

@SylvainDe
Copy link
Mannequin

SylvainDe mannequin commented Jun 8, 2017

BPO 30600
Nosy @larryhastings, @serhiy-storchaka, @SylvainDe, @DimitrisJim
PRs
  • bpo-30600: Fix error messages (condition order in Argument Clinic) #2051
  • Files
  • git_bisect_bpo30600.txt
  • 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 2017-06-10.04:57:41.194>
    created_at = <Date 2017-06-08.12:25:37.283>
    labels = ['interpreter-core', 'easy', 'type-bug', '3.7', 'expert-argument-clinic']
    title = 'Error message incorrect when index is called with keyword argument ("[].index(x=2)")'
    updated_at = <Date 2017-06-10.04:57:41.192>
    user = 'https://github.com/SylvainDe'

    bugs.python.org fields:

    activity = <Date 2017-06-10.04:57:41.192>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-06-10.04:57:41.194>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core', 'Argument Clinic']
    creation = <Date 2017-06-08.12:25:37.283>
    creator = 'SylvainDe'
    dependencies = []
    files = ['46939']
    hgrepos = []
    issue_num = 30600
    keywords = ['easy']
    message_count = 8.0
    messages = ['295427', '295432', '295434', '295437', '295519', '295523', '295610', '295611']
    nosy_count = 4.0
    nosy_names = ['larry', 'serhiy.storchaka', 'SylvainDe', 'Jim Fasarakis-Hilliard']
    pr_nums = ['2051']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue30600'
    versions = ['Python 3.7']

    @SylvainDe
    Copy link
    Mannequin Author

    SylvainDe mannequin commented Jun 8, 2017

    Issue found while trying to write tests for https://bugs.python.org/issue30592 .

    Issue related to http://bugs.python.org/issue30534 .

    The following code:

    [].index(x=2)
    

    should raise the following error:

    TypeError: index() takes no keyword arguments
    

    but currently raises:

    TypeError: index() takes at least 1 argument (0 given)
    

    This is easily reproduced with the following unit test:

        # AssertionError: "^index\(\) takes no keyword arguments$" does not match "index() takes at least 1 argument (0 given)"
        def test_varargs4_kw(self):
            msg = r"^index\(\) takes no keyword arguments$"
            self.assertRaisesRegex(TypeError, msg, [].index, x=2)

    @SylvainDe SylvainDe mannequin added 3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Jun 8, 2017
    @serhiy-storchaka
    Copy link
    Member

    Good catch! This issue is similar to bpo-30534, but caused by generated code.

    The solution is easy: make Argument Clinic (Tools/clinic/clinic.py) generating _PyArg_NoStackKeywords() before _PyArg_ParseStack() and regenerate all generated by Argument Clinic code (make clinic).

    @SylvainDe
    Copy link
    Mannequin Author

    SylvainDe mannequin commented Jun 8, 2017

    Can I give this a try or is anyone working on this already ?

    @serhiy-storchaka
    Copy link
    Member

    Yes, pleas do this.

    @SylvainDe
    Copy link
    Mannequin Author

    SylvainDe mannequin commented Jun 9, 2017

    Thanks Serhiy Storchaka for the tip! I am currently investigating how the argument clinic works. I have used git bisect to find when the issue got introduced.

    commit fdd42c4
    bpo-20185: Convert list object implementation to Argument Clinic. (#542)

    @serhiy-storchaka
    Copy link
    Member

    This commit only exposed existing bug in Argument Clinic. The same bug should be exposed for other methods that takes no keyword arguments converted to Argument Clinic.

    @serhiy-storchaka
    Copy link
    Member

    New changeset 7445381 by Serhiy Storchaka (Sylvain) in branch 'master':
    bpo-30600: Fix error messages (condition order in Argument Clinic) (bpo-2051)
    7445381

    @serhiy-storchaka
    Copy link
    Member

    The PR LGTM. Thank you for your contribution SylvainDe!

    @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
    3.7 (EOL) end of life easy interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-argument-clinic type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant