@@ -1810,10 +1810,10 @@ For most object types, eval(repr(object)) == object.");
18101810static PyObject *
18111811builtin_round (PyObject * self , PyObject * args , PyObject * kwds )
18121812{
1813- static PyObject * round_str = NULL ;
18141813 PyObject * ndigits = NULL ;
18151814 static char * kwlist [] = {"number" , "ndigits" , 0 };
1816- PyObject * number , * round ;
1815+ PyObject * number , * round , * result ;
1816+ _Py_IDENTIFIER (__round__ );
18171817
18181818 if (!PyArg_ParseTupleAndKeywords (args , kwds , "O|O:round" ,
18191819 kwlist , & number , & ndigits ))
@@ -1824,24 +1824,21 @@ builtin_round(PyObject *self, PyObject *args, PyObject *kwds)
18241824 return NULL ;
18251825 }
18261826
1827- if (round_str == NULL ) {
1828- round_str = PyUnicode_InternFromString ("__round__" );
1829- if (round_str == NULL )
1830- return NULL ;
1831- }
1832-
1833- round = _PyType_Lookup (Py_TYPE (number ), round_str );
1827+ round = _PyObject_LookupSpecial (number , & PyId___round__ );
18341828 if (round == NULL ) {
1835- PyErr_Format (PyExc_TypeError ,
1836- "type %.100s doesn't define __round__ method" ,
1837- Py_TYPE (number )-> tp_name );
1829+ if (!PyErr_Occurred ())
1830+ PyErr_Format (PyExc_TypeError ,
1831+ "type %.100s doesn't define __round__ method" ,
1832+ Py_TYPE (number )-> tp_name );
18381833 return NULL ;
18391834 }
18401835
18411836 if (ndigits == NULL )
1842- return PyObject_CallFunction (round , "O" , number );
1837+ result = PyObject_CallFunctionObjArgs (round , NULL );
18431838 else
1844- return PyObject_CallFunction (round , "OO" , number , ndigits );
1839+ result = PyObject_CallFunctionObjArgs (round , ndigits , NULL );
1840+ Py_DECREF (round );
1841+ return result ;
18451842}
18461843
18471844PyDoc_STRVAR (round_doc ,
0 commit comments