diff options
author | Furkan Onder <furkanonder@protonmail.com> | 2024-01-28 23:05:29 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-28 23:05:29 (GMT) |
commit | f7c05d7ad3075a1dbeed86b6b12903032e4afba6 (patch) | |
tree | 3c92db62086b6701bebfb2a01ba57753cfb3b096 /Objects | |
parent | 3bb6912d8832e6e0a98c74de360dc1b23906c4b3 (diff) | |
download | cpython-f7c05d7ad3075a1dbeed86b6b12903032e4afba6.zip cpython-f7c05d7ad3075a1dbeed86b6b12903032e4afba6.tar.gz cpython-f7c05d7ad3075a1dbeed86b6b12903032e4afba6.tar.bz2 |
gh-55664: Add warning when creating a type using a namespace dictionary with non-string keys. (GH-105338)
Co-authored-by: Daniel Urban <durban@users.noreply.github.com>
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/typeobject.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 114cf21..a850473 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -3828,6 +3828,17 @@ type_new_impl(type_new_ctx *ctx) // Put the proper slots in place fixup_slot_dispatchers(type); + if (!_PyDict_HasOnlyStringKeys(type->tp_dict)) { + if (PyErr_WarnFormat( + PyExc_RuntimeWarning, + 1, + "non-string key in the __dict__ of class %.200s", + type->tp_name) == -1) + { + goto error; + } + } + if (type_new_set_names(type) < 0) { goto error; } |