|
16 | 16 | #endif |
17 | 17 |
|
18 | 18 | #include "Python.h" |
| 19 | +#include "pycore_dict.h" // _PyDict_CopyAsDict() |
19 | 20 | #include "pycore_pyhash.h" // _Py_HashSecret |
20 | 21 | #include "pycore_weakref.h" // FT_CLEAR_WEAKREFS() |
21 | 22 |
|
@@ -382,13 +383,14 @@ get_attrib_from_keywords(PyObject *kwds) |
382 | 383 | /* If attrib was found in kwds, copy its value and remove it from |
383 | 384 | * kwds |
384 | 385 | */ |
385 | | - if (!PyDict_Check(attrib)) { |
386 | | - PyErr_Format(PyExc_TypeError, "attrib must be dict, not %.100s", |
387 | | - Py_TYPE(attrib)->tp_name); |
| 386 | + if (!PyAnyDict_Check(attrib)) { |
| 387 | + PyErr_Format(PyExc_TypeError, |
| 388 | + "attrib must be dict or frozendict, not %T", |
| 389 | + attrib); |
388 | 390 | Py_DECREF(attrib); |
389 | 391 | return NULL; |
390 | 392 | } |
391 | | - Py_SETREF(attrib, PyDict_Copy(attrib)); |
| 393 | + Py_SETREF(attrib, _PyDict_CopyAsDict(attrib)); |
392 | 394 | } |
393 | 395 | else { |
394 | 396 | attrib = PyDict_New(); |
@@ -416,12 +418,18 @@ element_init(PyObject *self, PyObject *args, PyObject *kwds) |
416 | 418 | PyObject *attrib = NULL; |
417 | 419 | ElementObject *self_elem; |
418 | 420 |
|
419 | | - if (!PyArg_ParseTuple(args, "O|O!:Element", &tag, &PyDict_Type, &attrib)) |
| 421 | + if (!PyArg_ParseTuple(args, "O|O:Element", &tag, &attrib)) |
420 | 422 | return -1; |
| 423 | + if (attrib != NULL && !PyAnyDict_Check(attrib)) { |
| 424 | + PyErr_Format(PyExc_TypeError, |
| 425 | + "Element() argument 2 must be dict or frozendict, not %T", |
| 426 | + attrib); |
| 427 | + return -1; |
| 428 | + } |
421 | 429 |
|
422 | 430 | if (attrib) { |
423 | 431 | /* attrib passed as positional arg */ |
424 | | - attrib = PyDict_Copy(attrib); |
| 432 | + attrib = _PyDict_CopyAsDict(attrib); |
425 | 433 | if (!attrib) |
426 | 434 | return -1; |
427 | 435 | if (kwds) { |
@@ -2111,10 +2119,10 @@ static int |
2111 | 2119 | element_attrib_setter(PyObject *op, PyObject *value, void *closure) |
2112 | 2120 | { |
2113 | 2121 | _VALIDATE_ATTR_VALUE(value); |
2114 | | - if (!PyDict_Check(value)) { |
| 2122 | + if (!PyAnyDict_Check(value)) { |
2115 | 2123 | PyErr_Format(PyExc_TypeError, |
2116 | | - "attrib must be dict, not %.200s", |
2117 | | - Py_TYPE(value)->tp_name); |
| 2124 | + "attrib must be dict or frozendict, not %T", |
| 2125 | + value); |
2118 | 2126 | return -1; |
2119 | 2127 | } |
2120 | 2128 | ElementObject *self = _Element_CAST(op); |
|
0 commit comments