@@ -47,12 +47,13 @@ get_functools_state(PyObject *module)
4747// The 'Placeholder' singleton indicates which formal positional
4848// parameters are to be bound first when using a 'partial' object.
4949
50- static PyObject * placeholder_instance ;
51-
5250typedef struct {
5351 PyObject_HEAD
5452} placeholderobject ;
5553
54+ static inline _functools_state *
55+ get_functools_state_by_type (PyTypeObject * type );
56+
5657PyDoc_STRVAR (placeholder_doc ,
5758"The type of the Placeholder singleton.\n\n"
5859"Used as a placeholder for partial arguments." );
@@ -91,10 +92,11 @@ placeholder_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
9192 PyErr_SetString (PyExc_TypeError , "PlaceholderType takes no arguments" );
9293 return NULL ;
9394 }
94- if (placeholder_instance == NULL ) {
95- placeholder_instance = PyType_GenericNew (type , NULL , NULL );
95+ _functools_state * state = get_functools_state_by_type (type );
96+ if (state -> placeholder == NULL ) {
97+ state -> placeholder = PyType_GenericNew (type , NULL , NULL );
9698 }
97- return placeholder_instance ;
99+ return state -> placeholder ;
98100}
99101
100102static PyType_Slot placeholder_type_slots [] = {
@@ -209,7 +211,7 @@ partial_new(PyTypeObject *type, PyObject *args, PyObject *kw)
209211 /* Count placeholders */
210212 Py_ssize_t phcount = 0 ;
211213 for (Py_ssize_t i = 0 ; i < new_nargs - 1 ; i ++ ) {
212- if (Py_Is ( PyTuple_GET_ITEM (new_args , i ), pto -> placeholder ) ) {
214+ if (PyTuple_GET_ITEM (new_args , i ) == pto -> placeholder ) {
213215 phcount ++ ;
214216 }
215217 }
@@ -225,7 +227,7 @@ partial_new(PyTypeObject *type, PyObject *args, PyObject *kw)
225227 for (Py_ssize_t i = 0 , j = 0 ; i < tot_nargs ; i ++ ) {
226228 if (i < npargs ) {
227229 item = PyTuple_GET_ITEM (pto_args , i );
228- if (( j < new_nargs ) && Py_Is ( item , pto -> placeholder ) ) {
230+ if (j < new_nargs && item == pto -> placeholder ) {
229231 item = PyTuple_GET_ITEM (new_args , j );
230232 j ++ ;
231233 pto_phcount -- ;
@@ -678,7 +680,7 @@ partial_setstate(partialobject *pto, PyObject *state)
678680 /* Count placeholders */
679681 Py_ssize_t phcount = 0 ;
680682 for (Py_ssize_t i = 0 ; i < nargs - 1 ; i ++ ) {
681- if (PyTuple_GET_ITEM (fnargs , i ), pto -> placeholder ) {
683+ if (PyTuple_GET_ITEM (fnargs , i ) == pto -> placeholder ) {
682684 phcount ++ ;
683685 }
684686 }
0 commit comments