@@ -50,22 +50,10 @@ static PyTypeObject* PyDecimal_Type;
5050/* *
5151 * Import all supported key types from Python which are not built-in. Make them
5252 * available globally so that their reference counts need not be managed.
53- *
54- * @return `true` if successful, else `false`.
5553 */
56- static bool import_supported_key_types (void )
54+ void import_supported_key_types (void )
5755{
58- // Import each type only once.
59- static bool import_decimal = []
60- {
61- return (PyDecimal_Type = import_python_type (" decimal" , " Decimal" )) != nullptr ;
62- }();
63- if (!import_decimal)
64- {
65- PyErr_SetString (PyExc_ImportError, " failed to import the `decimal.Decimal` type" );
66- return false ;
67- }
68- return true ;
56+ PyDecimal_Type = import_python_type (" decimal" , " Decimal" );
6957}
7058
7159/* *
@@ -139,7 +127,7 @@ bool SortedDictType::are_key_type_and_key_value_pair_good(PyObject* key, PyObjec
139127 };
140128 for (PyTypeObject* allowed_key_type : allowed_key_types)
141129 {
142- if (Py_IS_TYPE (key, allowed_key_type) != 0 )
130+ if (allowed_key_type != nullptr && Py_IS_TYPE (key, allowed_key_type) != 0 )
143131 {
144132 this ->key_type = allowed_key_type;
145133 key_type_set_here = true ;
@@ -523,11 +511,6 @@ int SortedDictType::init(PyObject* args, PyObject* kwargs)
523511
524512PyObject* SortedDictType::New (PyTypeObject* type, PyObject* args, PyObject* kwargs)
525513{
526- if (!import_supported_key_types ())
527- {
528- return nullptr ;
529- }
530-
531514 PyObject* self = type->tp_alloc (type, 0 ); // 🆕
532515 if (self == nullptr )
533516 {
0 commit comments