bpo-28974: object.__format__(x, '')
is now equivalent to str(x)
(… · python/cpython@7e19dbc (original) (raw)
4 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1282,6 +1282,10 @@ Basic customization | ||
1282 | 1282 | The __format__ method of ``object`` itself raises a :exc:`TypeError` |
1283 | 1283 | if passed any non-empty string. |
1284 | 1284 | |
1285 | + .. versionchanged:: 3.7 | |
1286 | + ``object.__format__(x, '')`` is now equivalent to ``str(x)`` rather | |
1287 | + than ``format(str(self), '')``. | |
1288 | + | |
1285 | 1289 | |
1286 | 1290 | .. _richcmpfuncs: |
1287 | 1291 | .. method:: object.__lt__(self, other) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -89,6 +89,10 @@ Other Language Changes | ||
89 | 89 | a name are now supported. |
90 | 90 | (Contributed by Serhiy Storchaka in :issue:`30024`.) |
91 | 91 | |
92 | +* ``object.__format__(x, '')`` is now equivalent to ``str(x)`` rather than | |
93 | + ``format(str(self), '')``. | |
94 | + (Contributed by Serhiy Storchaka in :issue:`28974`.) | |
95 | + | |
92 | 96 | |
93 | 97 | New Modules |
94 | 98 | =========== |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -10,6 +10,9 @@ What's New in Python 3.7.0 alpha 1? | ||
10 | 10 | Core and Builtins |
11 | 11 | ----------------- |
12 | 12 | |
13 | +- bpo-28974: ``object.__format__(x, '')`` is now equivalent to ``str(x)`` | |
14 | + rather than ``format(str(self), '')``. | |
15 | + | |
13 | 16 | - bpo-30024: Circular imports involving absolute imports with binding |
14 | 17 | a submodule to a name are now supported. |
15 | 18 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -4493,9 +4493,6 @@ static PyObject * | ||
4493 | 4493 | object___format___impl(PyObject *self, PyObject *format_spec) |
4494 | 4494 | /*[clinic end generated code: output=34897efb543a974b input=7c3b3bc53a6fb7fa]*/ |
4495 | 4495 | { |
4496 | -PyObject *self_as_str = NULL; | |
4497 | -PyObject *result = NULL; | |
4498 | - | |
4499 | 4496 | /* Issue 7994: If we're converting to a string, we |
4500 | 4497 | should reject format specifications */ |
4501 | 4498 | if (PyUnicode_GET_LENGTH(format_spec) > 0) { |
@@ -4504,12 +4501,7 @@ object___format___impl(PyObject *self, PyObject *format_spec) | ||
4504 | 4501 | self->ob_type->tp_name); |
4505 | 4502 | return NULL; |
4506 | 4503 | } |
4507 | -self_as_str = PyObject_Str(self); | |
4508 | -if (self_as_str != NULL) { | |
4509 | -result = PyObject_Format(self_as_str, format_spec); | |
4510 | -Py_DECREF(self_as_str); | |
4511 | - } | |
4512 | -return result; | |
4504 | +return PyObject_Str(self); | |
4513 | 4505 | } |
4514 | 4506 | |
4515 | 4507 | /*[clinic input] |