@@ -4846,6 +4846,31 @@ sequence_setitem(PyObject *self, PyObject *args)
48464846}
48474847
48484848
4849+ static PyObject *
4850+ hasattr_string (PyObject * self , PyObject * args )
4851+ {
4852+ PyObject * obj ;
4853+ PyObject * attr_name ;
4854+
4855+ if (!PyArg_UnpackTuple (args , "hasattr_string" , 2 , 2 , & obj , & attr_name )) {
4856+ return NULL ;
4857+ }
4858+
4859+ if (!PyUnicode_Check (attr_name )) {
4860+ PyErr_SetString (PyExc_TypeError , "attribute name must a be string" );
4861+ return PyErr_Occurred ();
4862+ }
4863+
4864+ const char * name_str = PyUnicode_AsUTF8 (attr_name );
4865+ if (PyObject_HasAttrString (obj , name_str )) {
4866+ Py_RETURN_TRUE ;
4867+ }
4868+ else {
4869+ Py_RETURN_FALSE ;
4870+ }
4871+ }
4872+
4873+
48494874/* Functions for testing C calling conventions (METH_*) are named meth_*,
48504875 * e.g. "meth_varargs" for METH_VARARGS.
48514876 *
@@ -5707,6 +5732,7 @@ static PyMethodDef TestMethods[] = {
57075732 {"write_unraisable_exc" , test_write_unraisable_exc , METH_VARARGS },
57085733 {"sequence_getitem" , sequence_getitem , METH_VARARGS },
57095734 {"sequence_setitem" , sequence_setitem , METH_VARARGS },
5735+ {"hasattr_string" , hasattr_string , METH_VARARGS },
57105736 {"meth_varargs" , meth_varargs , METH_VARARGS },
57115737 {"meth_varargs_keywords" , _PyCFunction_CAST (meth_varargs_keywords ), METH_VARARGS |METH_KEYWORDS },
57125738 {"meth_o" , meth_o , METH_O },
0 commit comments