8000 gh-96526: Clarify format and __format__ docstrings (gh-96648) · python/cpython@07b8e85 · GitHub
[go: up one dir, main page]

Skip to content

Commit 07b8e85

Browse files
authored
gh-96526: Clarify format and __format__ docstrings (gh-96648)
1 parent 0ea8b92 commit 07b8e85

File tree

6 files changed

+29
-16
lines changed

6 files changed

+29
-16
lines changed

Objects/clinic/longobject.c.h

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Objects/clinic/typeobject.c.h

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Objects/longobject.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5528,11 +5528,13 @@ int.__format__
55285528
55295529
format_spec: unicode
55305530
/
5531+
5532+
Convert to a string according to format_spec.
55315533
[clinic start generated code]*/
55325534

55335535
static PyObject *
55345536
int___format___impl(PyObject *self, PyObject *format_spec)
5535-
/*[clinic end generated code: output=b4929dee9ae18689 input=e31944a9b3e428b7]*/
5537+
/*[clinic end generated code: output=b4929dee9ae18689 input=d5e1254a47e8d1dc]*/
55365538
{
55375539
_PyUnicodeWriter writer;
55385540
int ret;

Objects/typeobject.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5824,11 +5824,13 @@ object.__format__
58245824
/
58255825
58265826
Default object formatter.
5827+
5828+
Return str(self) if format_spec is empty. Raise TypeError otherwise.
58275829
[clinic start generated code]*/
58285830

58295831
static PyObject *
58305832
object___format___impl(PyObject *self, PyObject *format_spec)
5831-
/*[clinic end generated code: output=34897efb543a974b input=7c3b3bc53a6fb7fa]*/
5833+
/*[clinic end generated code: output=34897efb543a974b input=b94d8feb006689ea]*/
58325834
{
58335835
/* Issue 7994: If we're converting to a string, we
58345836
should reject format specifications */

Python/bltinmodule.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -677,16 +677,19 @@ format as builtin_format
677677
format_spec: unicode(c_default="NULL") = ''
678678
/
679679
680-
Return value.__format__(format_spec)
680+
Return type(value).__format__(value, format_spec)
681681
682-
format_spec defaults to the empty string.
683-
See the Format Specification Mini-Language section of help('FORMATTING') for
684-
details.
682+
Many built-in types implement format_spec according to the
683+
Format Specification Mini-language. See help('FORMATTING').
684+
685+
If type(value) does not supply a method named __format__
686+
and format_spec is empty, then str(value) is returned.
687+
See also help('SPECIALMETHODS').
685688
[clinic start generated code]*/
686689

687690
static PyObject *
688691
builtin_format_impl(PyObject *module, PyObject *value, PyObject *format_spec)
689-
/*[clinic end generated code: output=2f40bdfa4954b077 input=88339c93ea522b33]*/
692+
/*[clinic end generated code: output=2f40bdfa4954b077 input=45ef3934b86d5624]*/
690693
{
691694
return PyObject_Format(value, format_spec);
692695
}

Python/clinic/bltinmodule.c.h

Lines changed: 8 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0