summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
Diffstat (limited to 'Objects')
-rw-r--r--Objects/typeobject.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 8b74e1e..897374d 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -3315,9 +3315,26 @@ object_format(PyObject *self, PyObject *args)
return NULL;
self_as_str = PyObject_Str(self);
- if (self_as_str != NULL)
- result = PyObject_Format(self_as_str, format_spec);
-
+ if (self_as_str != NULL) {
+ /* Issue 7994: If we're converting to a string, we
+ should reject format specifications */
+ if (PyUnicode_GET_SIZE(format_spec) > 0) {
+ if (PyErr_WarnEx(PyExc_PendingDeprecationWarning,
+ "object.__format__ with a non-empty format "
+ "string is deprecated", 1) < 0) {
+ goto done;
+ }
+ /* Eventually this will become an error:
+ PyErr_Format(PyExc_TypeError,
+ "non-empty format string passed to object.__format__");
+ goto done;
+ */
+ }
+
+ result = PyObject_Format(self_as_str, format_spec);
+ }
+
+done:
Py_XDECREF(self_as_str);
return result;