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>
This commit is contained in:
Furkan Onder 2024-01-29 02:05:29 +03:00 committed by GitHub
parent 3bb6912d88
commit f7c05d7ad3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 28 additions and 1 deletions

View file

@ -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;
}