File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -540,12 +540,13 @@ are always available. They are listed here in alphabetical order.
540540 A call to ``format(value, format_spec) `` is translated to
541541 ``type(value).__format__(format_spec) `` which bypasses the instance
542542 dictionary when searching for the value's :meth: `__format__ ` method. A
543- :exc: `TypeError ` exception is raised if the method is not found or if either
544- the *format_spec * or the return value are not strings.
543+ :exc: `TypeError ` exception is raised if the method search reaches
544+ :mod: `object ` and the *format_spec * is non-empty, or if either the
545+ *format_spec * or the return value are not strings.
545546
546- .. versionadded :: 3.4
547+ .. versionchanged :: 3.4
547548 ``object().__format__(format_spec) `` raises :exc: `TypeError `
548- if *format_spec * is not empty string.
549+ if *format_spec * is not an empty string.
549550
550551
551552.. _func-frozenset :
Original file line number Diff line number Diff line change @@ -1226,6 +1226,10 @@ Basic customization
12261226
12271227 The return value must be a string object.
12281228
1229+ .. versionchanged :: 3.4
1230+ The __format__ method of ``object `` itself raises a :exc: `TypeError `
1231+ if passed any non-empty string.
1232+
12291233
12301234.. _richcmpfuncs :
12311235.. method :: object.__lt__(self, other)
Original file line number Diff line number Diff line change @@ -1600,6 +1600,15 @@ removed:
16001600* :class: `inspect.Signature `: positional-only parameters are now required
16011601 to have a valid name.
16021602
1603+ * :meth: `object.__format__ ` no longer accepts non-empty format strings, it now
1604+ raises a :exc: `TypeError ` instead. Using a non-empty string has been
1605+ deprecated since Python 3.2. This change has been made to prevent a
1606+ situation where previously working (but incorrect) code would start failing
1607+ if an object gained a __format__ method, which means that your code may now
1608+ raise a :exc: `TypeError ` if you are using an ``'s' `` format code with objects
1609+ that do not have a __format__ method that handles it. See :issue: `7994 ` for
1610+ background.
1611+
16031612
16041613Code Cleanups
16051614-------------
You can’t perform that action at this time.
0 commit comments