FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-28974: `object.__format__(x, '')` is now equivalent to `str(x)` by serhiy-storchaka · Pull Request #506 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .rst  (2) No extension  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 4 additions & 0 deletions Doc/reference/datamodel.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,10 @@ Basic customization
The __format__ method of ``object`` itself raises a :exc:`TypeError`
if passed any non-empty string.

.. versionchanged:: 3.7
``object.__format__(x, '')`` is now equivalent to ``str(x)`` rather
than ``format(str(self), '')``.


.. _richcmpfuncs:
.. method:: object.__lt__(self, other)
Expand Down
4 changes: 4 additions & 0 deletions Doc/whatsnew/3.7.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ Other Language Changes
a name are now supported.
(Contributed by Serhiy Storchaka in :issue:`30024`.)

* ``object.__format__(x, '')`` is now equivalent to ``str(x)`` rather than
``format(str(self), '')``.
(Contributed by Serhiy Storchaka in :issue:`28974`.)


New Modules
===========
Expand Down
3 changes: 3 additions & 0 deletions Misc/NEWS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ What's New in Python 3.7.0 alpha 1?
Core and Builtins
-----------------

- bpo-28974: ``object.__format__(x, '')`` is now equivalent to ``str(x)``
rather than ``format(str(self), '')``.

- bpo-30024: Circular imports involving absolute imports with binding
a submodule to a name are now supported.

Expand Down
10 changes: 1 addition & 9 deletions Objects/typeobject.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -4493,9 +4493,6 @@ static PyObject *
object___format___impl(PyObject *self, PyObject *format_spec)
/*[clinic end generated code: output=34897efb543a974b input=7c3b3bc53a6fb7fa]*/
{
PyObject *self_as_str = NULL;
PyObject *result = NULL;

/* Issue 7994: If we're converting to a string, we
should reject format specifications */
if (PyUnicode_GET_LENGTH(format_spec) > 0) {
Expand All @@ -4504,12 +4501,7 @@ object___format___impl(PyObject *self, PyObject *format_spec)
self->ob_type->tp_name);
return NULL;
}
self_as_str = PyObject_Str(self);
if (self_as_str != NULL) {
result = PyObject_Format(self_as_str, format_spec);
Py_DECREF(self_as_str);
}
return result;
return PyObject_Str(self);
}

/*[clinic input]
Expand Down

Back | FazBrowse Home | New Git URL