From f0271431235acac48679bc231f867e20f0eb8f1b Mon Sep 17 00:00:00 2001 From: Tony Flury Date: Wed, 7 Mar 2018 09:22:14 +0000 Subject: [PATCH 1/2] bpo-33006 - Correct filter doc string to clarify 2nd argument can be an iterable. --- .../2018-03-07-09-10-42.bpo-33006.Bzx3LA.rst | 2 ++ Python/bltinmodule.c | 13 ++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2018-03-07-09-10-42.bpo-33006.Bzx3LA.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-03-07-09-10-42.bpo-33006.Bzx3LA.rst b/Misc/NEWS.d/next/Core and Builtins/2018-03-07-09-10-42.bpo-33006.Bzx3LA.rst new file mode 100644 index 000000000000000..0bcc0a4b987dc1d --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2018-03-07-09-10-42.bpo-33006.Bzx3LA.rst @@ -0,0 +1,2 @@ +Clarified Doc string for builtin filter function. 2nd Argument can be any +iterable. Patch by Tony Flury diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 9ce3b275eab2efb..1e4c13f78a56472 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -351,11 +351,14 @@ builtin_filter(PyObject *self, PyObject *args) } PyDoc_STRVAR(filter_doc, -"filter(function or None, sequence) -> list, tuple, or string\n" -"\n" -"Return those items of sequence for which function(item) is true. If\n" -"function is None, return the items that are true. If sequence is a tuple\n" -"or string, return the same type, else return a list."); +"filter(function or None, iterable) -> list, string or tuple\n\ +\n\ +Construct a list from those elements of iterable for which function returns\n\ +true. iterable may be either a sequence, a container which supports\n\ +iteration, or an iterator. If iterable is a string or a tuple, the result\n\ +also has that type; otherwise it is always a list. If function is None, the\n\ +identity function is assumed, that is, all elements of iterable that are\n\ +false are removed."); static PyObject * builtin_format(PyObject *self, PyObject *args) From c2c0c894b4472b2134737834d123c6c7e786eb55 Mon Sep 17 00:00:00 2001 From: Tony Flury Date: Mon, 30 Apr 2018 23:34:20 +0100 Subject: [PATCH 2/2] Changes as per Pull request review - reduced length of document string. --- Python/bltinmodule.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 1e4c13f78a56472..cfe9832f1bb5b1e 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -353,12 +353,10 @@ builtin_filter(PyObject *self, PyObject *args) PyDoc_STRVAR(filter_doc, "filter(function or None, iterable) -> list, string or tuple\n\ \n\ -Construct a list from those elements of iterable for which function returns\n\ -true. iterable may be either a sequence, a container which supports\n\ -iteration, or an iterator. If iterable is a string or a tuple, the result\n\ -also has that type; otherwise it is always a list. If function is None, the\n\ -identity function is assumed, that is, all elements of iterable that are\n\ -false are removed."); +Return a sequence yielding those items of iterable for which function(item)\n\ +is true. If function is None, return the items that are true.\n\ +If iterable is a string or a tuple, the result also has that type; otherwise\n\ +it is always a list."); static PyObject * builtin_format(PyObject *self, PyObject *args)