Issue 28974: Make default format be equivalent to str (original) (raw)

Issue28974

Created on 2016-12-14 21:52 by serhiy.storchaka, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
simpler-object-__format__.patch serhiy.storchaka,2016-12-14 21:52 review
Pull Requests
URL Status Linked Edit
PR 506 merged serhiy.storchaka,2017-03-06 09:53
Messages (4)
msg283220 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-12-14 21:52
Originally PEP 3101 defined the default __format__ implementation, object.__format__ as def __format__(self, format_spec): return format(str(self), format_spec) After few changes (, ) it now looks as def __format__(self, format_spec): assert format_spec == '' return format(str(self), '') Proposed patch makes it yet simpler: def __format__(self, format_spec): assert format_spec == '' return str(self) This is equivalent to the previous form except obscure case when str() returns not exact str, but strict subclass with overridden __format__. The benefit of this change is simpler semantical model of the default implementation. See the start of the discussion in and the discussion on Python-Dev: https://mail.python.org/pipermail/python-dev/2016-October/146765.html.
msg293605 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-05-13 08:36
What are your thoughts about this Eric?
msg293607 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2017-05-13 09:08
I'm okay with this change.
msg293609 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-05-13 09:40
New changeset 7e19dbc92ec06a987eaae72f7cdfd32006aa4960 by Serhiy Storchaka in branch 'master': bpo-28974: `object.__format__(x, '')` is now equivalent to `str(x)` (#506) https://github.com/python/cpython/commit/7e19dbc92ec06a987eaae72f7cdfd32006aa4960
History
Date User Action Args
2022-04-11 14:58:40 admin set github: 73160
2017-05-13 09:41:23 serhiy.storchaka set status: open -> closedresolution: fixedstage: patch review -> resolved
2017-05-13 09:40:54 serhiy.storchaka set messages: +
2017-05-13 09:08:03 eric.smith set messages: +
2017-05-13 08:36:34 serhiy.storchaka set messages: +
2017-03-06 09:57:34 rhettinger set nosy: + rhettinger
2017-03-06 09:53:17 serhiy.storchaka set pull_requests: + <pull%5Frequest415>
2016-12-14 21:52:10 serhiy.storchaka create