Skip to content

Commit f5c2531

Browse files
committed
pythongh-145098: Fix incorrect type name in dict_vectorcall error message
dict_vectorcall() is shared by both dict and frozendict. When called with too many positional arguments, it previously hardcoded "dict" in the error message even when invoked as frozendict. For example, `frozendict(1, 2)` raised: TypeError: dict expected at most 1 argument, got 2 After this fix it correctly raises: TypeError: frozendict expected at most 1 argument, got 2 https://claude.ai/code/session_01EdeU6enhg5YoLvKmBPpiZf
1 parent 72eca2a commit f5c2531

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

Lib/test/test_dict.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,6 +1746,10 @@ def test_constructor(self):
17461746
with self.assertRaises(TypeError):
17471747
dict.__init__(d, x=1)
17481748

1749+
# Error message uses "frozendict", not "dict"
1750+
with self.assertRaisesRegex(TypeError, r"frozendict expected at most 1"):
1751+
frozendict(1, 2)
1752+
17491753
def test_copy(self):
17501754
d = frozendict(x=1, y=2)
17511755
d2 = d.copy()

Objects/dictobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5107,7 +5107,7 @@ dict_vectorcall(PyObject *type, PyObject * const*args,
51075107
size_t nargsf, PyObject *kwnames)
51085108
{
51095109
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
5110-
if (!_PyArg_CheckPositional("dict", nargs, 0, 1)) {
5110+
if (!_PyArg_CheckPositional(((PyTypeObject*)type)->tp_name, nargs, 0, 1)) {
51115111
return NULL;
51125112
}
51135113

0 commit comments

Comments
 (0)