diff options
Diffstat (limited to 'Python/bltinmodule.c')
| -rw-r--r-- | Python/bltinmodule.c | 33 | 
1 files changed, 18 insertions, 15 deletions
| diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 75afa86..5291565 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -659,7 +659,7 @@ builtin_compile(PyObject *self, PyObject *args, PyObject *kwds)          goto finally;      } -    str = source_as_string(cmd, "compile", "string, bytes, AST or code", &cf); +    str = source_as_string(cmd, "compile", "string, bytes or AST", &cf);      if (str == NULL)          goto error; @@ -1810,10 +1810,10 @@ For most object types, eval(repr(object)) == object.");  static PyObject *  builtin_round(PyObject *self, PyObject *args, PyObject *kwds)  { -    static PyObject *round_str = NULL;      PyObject *ndigits = NULL;      static char *kwlist[] = {"number", "ndigits", 0}; -    PyObject *number, *round; +    PyObject *number, *round, *result; +    _Py_IDENTIFIER(__round__);      if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:round",                                       kwlist, &number, &ndigits)) @@ -1824,24 +1824,21 @@ builtin_round(PyObject *self, PyObject *args, PyObject *kwds)              return NULL;      } -    if (round_str == NULL) { -        round_str = PyUnicode_InternFromString("__round__"); -        if (round_str == NULL) -            return NULL; -    } - -    round = _PyType_Lookup(Py_TYPE(number), round_str); +    round = _PyObject_LookupSpecial(number, &PyId___round__);      if (round == NULL) { -        PyErr_Format(PyExc_TypeError, -                     "type %.100s doesn't define __round__ method", -                     Py_TYPE(number)->tp_name); +        if (!PyErr_Occurred()) +            PyErr_Format(PyExc_TypeError, +                         "type %.100s doesn't define __round__ method", +                         Py_TYPE(number)->tp_name);          return NULL;      }      if (ndigits == NULL) -        return PyObject_CallFunction(round, "O", number); +        result = PyObject_CallFunctionObjArgs(round, NULL);      else -        return PyObject_CallFunction(round, "OO", number, ndigits); +        result = PyObject_CallFunctionObjArgs(round, ndigits, NULL); +    Py_DECREF(round); +    return result;  }  PyDoc_STRVAR(round_doc, @@ -2408,6 +2405,12 @@ PyObject *  _PyBuiltin_Init(void)  {      PyObject *mod, *dict, *debug; + +    if (PyType_Ready(&PyFilter_Type) < 0 || +        PyType_Ready(&PyMap_Type) < 0 || +        PyType_Ready(&PyZip_Type) < 0) +        return NULL; +      mod = PyModule_Create(&builtinsmodule);      if (mod == NULL)          return NULL; | 
