[New-bugs-announce] [issue30600] Error message incorrect when index is called with keyword argument ("[].index(x=2)")

SylvainDe report at bugs.python.org
Thu Jun 8 08:25:37 EDT 2017


New submission from SylvainDe:

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)

----------
components: Interpreter Core
messages: 295427
nosy: SylvainDe
priority: normal
severity: normal
status: open
title: Error message incorrect when index is called with keyword argument ("[].index(x=2)")
type: behavior
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30600>
_______________________________________


More information about the New-bugs-announce mailing list