summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-10-30 17:37:46 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-10-30 17:37:46 (GMT)
commit7984bff52a9952219a3c15b88ff6514244dd7498 (patch)
treebcf67bde15ab80a95d773d75b6400082ca5e492b /Objects
parenta1fd5e4bc744bc972691f1d5c23130395e1e306a (diff)
parentd1af5effc214f474bcb1df62eb2089c48f657ee5 (diff)
downloadcpython-7984bff52a9952219a3c15b88ff6514244dd7498.zip
cpython-7984bff52a9952219a3c15b88ff6514244dd7498.tar.gz
cpython-7984bff52a9952219a3c15b88ff6514244dd7498.tar.bz2
Issue #28385: An error message when non-empty format spec is passed to
object.__format__ now contains the name of actual type.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/typeobject.c28
1 files changed, 9 insertions, 19 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index bfbeb40..9836961 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -4392,13 +4392,6 @@ PyDoc_STRVAR(object_init_subclass_doc,
"The default implementation does nothing. It may be\n"
"overridden to extend subclasses.\n");
-/*
- from PEP 3101, this code implements:
-
- class object:
- def __format__(self, format_spec):
- return format(str(self), format_spec)
-*/
static PyObject *
object_format(PyObject *self, PyObject *args)
{
@@ -4409,22 +4402,19 @@ object_format(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "U:__format__", &format_spec))
return NULL;
+ /* Issue 7994: If we're converting to a string, we
+ should reject format specifications */
+ if (PyUnicode_GET_LENGTH(format_spec) > 0) {
+ PyErr_Format(PyExc_TypeError,
+ "unsupported format string passed to %.200s.__format__",
+ self->ob_type->tp_name);
+ return NULL;
+ }
self_as_str = PyObject_Str(self);
if (self_as_str != NULL) {
- /* Issue 7994: If we're converting to a string, we
- should reject format specifications */
- if (PyUnicode_GET_LENGTH(format_spec) > 0) {
- PyErr_SetString(PyExc_TypeError,
- "non-empty format string passed to object.__format__");
- goto done;
- }
-
result = PyObject_Format(self_as_str, format_spec);
+ Py_DECREF(self_as_str);
}
-
-done:
- Py_XDECREF(self_as_str);
-
return result;
}