bpo-25750: Add test on bad descriptor __get__() (GH-9084) · python/cpython@5a30620

Original file line numberDiff line numberDiff line change

@@ -4550,6 +4550,28 @@ new_hamt(PyObject *self, PyObject *args)

45504550

}

45514551
45524552
4553+

/* def bad_get(self, obj, cls):

4554+

cls()

4555+

return repr(self)

4556+

*/

4557+

static PyObject*

4558+

bad_get(PyObject *module, PyObject *const *args, Py_ssize_t nargs)

4559+

{

4560+

if (nargs != 3) {

4561+

PyErr_SetString(PyExc_TypeError, "bad_get requires exactly 3 arguments");

4562+

return NULL;

4563+

}

4564+
4565+

PyObject *res = PyObject_CallObject(args[2], NULL);

4566+

if (res == NULL) {

4567+

return NULL;

4568+

}

4569+

Py_DECREF(res);

4570+
4571+

return PyObject_Repr(args[0]);

4572+

}

4573+
4574+
45534575

static PyObject *

45544576

encode_locale_ex(PyObject *self, PyObject *args)

45554577

{

@@ -5017,6 +5039,7 @@ static PyMethodDef TestMethods[] = {

50175039

{"get_mapping_items", get_mapping_items, METH_O},

50185040

{"test_pythread_tss_key_state", test_pythread_tss_key_state, METH_VARARGS},

50195041

{"hamt", new_hamt, METH_NOARGS},

5042+

{"bad_get", bad_get, METH_FASTCALL},

50205043

{"EncodeLocaleEx", encode_locale_ex, METH_VARARGS},

50215044

{"DecodeLocaleEx", decode_locale_ex, METH_VARARGS},

50225045

{"get_coreconfig", get_coreconfig, METH_NOARGS},