@@ -4846,6 +4846,31 @@ sequence_setitem(PyObject *self, PyObject *args)
4846
4846
}
4847
4847
4848
4848
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
+
4849
4874
/* Functions for testing C calling conventions (METH_*) are named meth_*,
4850
4875
* e.g. "meth_varargs" for METH_VARARGS.
4851
4876
*
@@ -5707,6 +5732,7 @@ static PyMethodDef TestMethods[] = {
5707
5732
{"write_unraisable_exc" , test_write_unraisable_exc , METH_VARARGS },
5708
5733
{"sequence_getitem" , sequence_getitem , METH_VARARGS },
5709
5734
{"sequence_setitem" , sequence_setitem , METH_VARARGS },
5735
+ {"hasattr_string" , hasattr_string , METH_VARARGS },
5710
5736
{"meth_varargs" , meth_varargs , METH_VARARGS },
5711
5737
{"meth_varargs_keywords" , _PyCFunction_CAST (meth_varargs_keywords ), METH_VARARGS |METH_KEYWORDS },
5712
5738
{"meth_o" , meth_o , METH_O },
0 commit comments