diff --git a/msgspec/_core.c b/msgspec/_core.c index e6293905..069ad5b2 100644 --- a/msgspec/_core.c +++ b/msgspec/_core.c @@ -6038,7 +6038,7 @@ Struct_vectorcall(PyTypeObject *cls, PyObject *const *args, size_t nargsf, PyObj } /* Unknown keyword */ - PyErr_SetString(PyExc_TypeError, "Extra keyword arguments provided"); + PyErr_Format(PyExc_TypeError, "Unexpected keyword argument '%U'", kwname); goto error; kw_found: diff --git a/tests/test_struct.py b/tests/test_struct.py index 15060520..bfcf3c3b 100644 --- a/tests/test_struct.py +++ b/tests/test_struct.py @@ -421,7 +421,7 @@ class Test(Struct): with pytest.raises(TypeError, match="Argument 'a' given by name and position"): Test(1, 2, a=3) - with pytest.raises(TypeError, match="Extra keyword arguments provided"): + with pytest.raises(TypeError, match="Unexpected keyword argument 'e'"): Test(1, 2, e=5) def test_init_kw_only(self): @@ -441,7 +441,7 @@ class Test(Struct, kw_only=True): with pytest.raises(TypeError, match="Extra positional arguments provided"): Test(1) - with pytest.raises(TypeError, match="Extra keyword arguments provided"): + with pytest.raises(TypeError, match="Unexpected keyword argument 'e'"): Test(a=1, e=5) def test_init_kw_only_mixed(self): @@ -468,7 +468,7 @@ class Test(Base): with pytest.raises(TypeError, match="Extra positional arguments provided"): Test(1, 5.0, 3) - with pytest.raises(TypeError, match="Extra keyword arguments provided"): + with pytest.raises(TypeError, match="Unexpected keyword argument 'e'"): Test(1, e=5)