summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorEric Smith <eric@trueblade.com>2010-09-13 20:48:43 (GMT)
committerEric Smith <eric@trueblade.com>2010-09-13 20:48:43 (GMT)
commite4d6317c8725f9f341c6f2dd628e3b3ac79ef309 (patch)
tree708a741bc323f4ed96680a02659355adfd2159f0 /Objects
parentaf9d10aa30fc1e3dd043519b2ea145c4a06c9199 (diff)
downloadcpython-e4d6317c8725f9f341c6f2dd628e3b3ac79ef309.zip
cpython-e4d6317c8725f9f341c6f2dd628e3b3ac79ef309.tar.gz
cpython-e4d6317c8725f9f341c6f2dd628e3b3ac79ef309.tar.bz2
Issue 7994: Make object.__format__() raise a PendingDeprecationWarning
if the format string is not empty. Manually merge r79596 and r84772 from 2.x. Also, apparently test_format() from test_builtin never made it into 3.x. I've added it as well. It tests the basic format() infrastructure.
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;