@@ -3988,7 +3988,7 @@ subtype_dict(PyObject *obj, void *context)
39883988int
39893989_PyObject_SetDict (PyObject * obj , PyObject * value )
39903990{
3991- if (value != NULL && !PyDict_Check (value )) {
3991+ if (value != NULL && !_PyAnyDict_Check (value )) {
39923992 PyErr_Format (PyExc_TypeError ,
39933993 "__dict__ must be set to a dictionary, "
39943994 "not a '%.200s'" , Py_TYPE (value )-> tp_name );
@@ -4891,6 +4891,37 @@ type_new_init(type_new_ctx *ctx)
48914891}
48924892
48934893
4894+ static int
4895+ type_new_frozendict (PyTypeObject * type )
4896+ {
4897+ PyObject * __frozendict__ ;
4898+ if (PyDict_GetItemStringRef (type -> tp_dict , "__frozendict__" ,
4899+ & __frozendict__ ) < 0 ) {
4900+ return -1 ;
4901+ }
4902+ if (__frozendict__ == NULL ) {
4903+ return 0 ;
4904+ }
4905+ int is_true = PyObject_IsTrue (__frozendict__ );
4906+ Py_DECREF (__frozendict__ );
4907+ if (is_true < 0 ) {
4908+ return -1 ;
4909+ }
4910+ if (!is_true ) {
4911+ return 0 ;
4912+ }
4913+
4914+ PyObject * frozendict ;
4915+ frozendict = PyObject_CallOneArg ((PyObject * )& PyFrozenDict_Type , type -> tp_dict );
4916+ if (frozendict == NULL ) {
4917+ return -1 ;
4918+ }
4919+
4920+ Py_SETREF (type -> tp_dict , frozendict );
4921+ return 0 ;
4922+ }
4923+
4924+
48944925static PyObject *
48954926type_new_impl (type_new_ctx * ctx )
48964927{
@@ -4930,6 +4961,10 @@ type_new_impl(type_new_ctx *ctx)
49304961 goto error ;
49314962 }
49324963
4964+ if (type_new_frozendict (type ) < 0 ) {
4965+ goto error ;
4966+ }
4967+
49334968 assert (_PyType_CheckConsistency (type ));
49344969#if defined(Py_GIL_DISABLED ) && defined(Py_DEBUG ) && SIZEOF_VOID_P > 4
49354970 // After this point, other threads can potentally use this type.
@@ -5977,7 +6012,7 @@ find_name_in_mro(PyTypeObject *type, PyObject *name, int *error)
59776012 for (Py_ssize_t i = 0 ; i < n ; i ++ ) {
59786013 PyObject * base = PyTuple_GET_ITEM (mro , i );
59796014 PyObject * dict = lookup_tp_dict (_PyType_CAST (base ));
5980- assert (dict && PyDict_Check (dict ));
6015+ assert (dict && _PyAnyDict_Check (dict ));
59816016 if (_PyDict_GetItemRef_KnownHash ((PyDictObject * )dict , name , hash , & res ) < 0 ) {
59826017 * error = -1 ;
59836018 goto done ;
0 commit comments