classification
Title: Error message incorrect when index is called with keyword argument ("[].index(x=2)")
Type: behavior Stage: resolved
Components: Argument Clinic, Interpreter Core Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Jim Fasarakis-Hilliard, SylvainDe, larry, serhiy.storchaka
Priority: normal Keywords: easy

Created on 2017-06-08 12:25 by SylvainDe, last changed 2017-06-10 04:57 by serhiy.storchaka. This issue is now closed.

Files
File name Uploaded Description Edit
git_bisect_bpo30600.txt SylvainDe, 2017-06-09 12:27
Pull Requests
URL Status Linked Edit
PR 2051 merged SylvainDe, 2017-06-09 23:24
Messages (8)
msg295427 - (view) Author: SylvainDe (SylvainDe) * Date: 2017-06-08 12:25
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)
msg295432 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-06-08 12:37
Good catch! This issue is similar to issue30534, 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).
msg295434 - (view) Author: SylvainDe (SylvainDe) * Date: 2017-06-08 12:39
Can I give this a try or is anyone working on this already ?
msg295437 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-06-08 12:45
Yes, pleas do this.
msg295519 - (view) Author: SylvainDe (SylvainDe) * Date: 2017-06-09 12:27
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 fdd42c481edba4261f861fc1dfe24bbd79b5a17a
bpo-20185: Convert list object implementation to Argument Clinic. (#542)
msg295523 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-06-09 12:38
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.
msg295610 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-06-10 04:51
New changeset 7445381c606faf20e253da42656db478a4349f8e by Serhiy Storchaka (Sylvain) in branch 'master':
bpo-30600: Fix error messages (condition order in Argument Clinic) (#2051)
https://github.com/python/cpython/commit/7445381c606faf20e253da42656db478a4349f8e
msg295611 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-06-10 04:57
The PR LGTM. Thank you for your contribution SylvainDe!
History
Date User Action Args
2017-06-10 04:57:41serhiy.storchakasetstatus: open -> closed
versions: - Python 3.6
messages: + msg295611

resolution: fixed
stage: needs patch -> resolved
2017-06-10 04:51:50serhiy.storchakasetmessages: + msg295610
2017-06-09 23:24:33SylvainDesetpull_requests: + pull_request2113
2017-06-09 12:45:07Jim Fasarakis-Hilliardsetnosy: + Jim Fasarakis-Hilliard
2017-06-09 12:38:07serhiy.storchakasetmessages: + msg295523
2017-06-09 12:27:09SylvainDesetfiles: + git_bisect_bpo30600.txt

messages: + msg295519
2017-06-08 12:45:47serhiy.storchakasetmessages: + msg295437
2017-06-08 12:39:12SylvainDesetmessages: + msg295434
2017-06-08 12:37:59serhiy.storchakasetcomponents: + Argument Clinic
versions: + Python 3.6
keywords: + easy
nosy: + serhiy.storchaka, larry

messages: + msg295432
stage: needs patch
2017-06-08 12:25:37SylvainDecreate