This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: select()'s documentation claims only sequences are accepted, but it allows all iterables
Type: behavior Stage: resolved
Components: Documentation, Library (Lib) Versions: Python 3.10, Python 3.9, Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Ido Michael, brandtbucher, corona10, docs@python, jstasiak, miss-islington, serhiy.storchaka, taleinat, vstinner
Priority: normal Keywords: patch

Created on 2019-10-24 11:08 by jstasiak, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 16832 merged jstasiak, 2019-10-24 11:08
PR 20372 merged miss-islington, 2020-05-25 07:04
PR 20424 merged taleinat, 2020-05-26 12:16
PR 20426 merged taleinat, 2020-05-26 12:20
Messages (10)
msg355325 - (view) Author: Jakub Stasiak (jstasiak) * Date: 2019-10-24 11:08
Excerpt from the documentation:

"""This is a straightforward interface to the Unix select() system call. The first three arguments are sequences of ‘waitable objects’: either integers representing file descriptors or objects with a parameterless method named fileno() returning such an integer:"""

In reality it accepts for example dictionary key views (that's how I discovered it) due to its internal usage of PySequence_Fast, which (from https://docs.python.org/3/c-api/sequence.html#c.PySequence_Fast):

"""Return the sequence or iterable o as an object usable by the other PySequence_Fast* family of functions. If the object is not a sequence or iterable, raises TypeError with m as the message text. Returns NULL on failure."""

I made a pull request to document this behavior in select (https://github.com/python/cpython/pull/16832) but it was recommended that I create this issue because the solution may not be obvious here.
msg366633 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2020-04-16 21:51
It seems that select() does indeed support arbitrary iterables through the use of PySequence_Fast().

The commit where this was introduced, by Brett Cannon from 2003 (62dba4c2775adfb5a5a97ca012a3ab00c4e28597), doesn't seems to have intended this though: "select.select() now accepts a sequence (as defined by PySequence_Fast()) for its first three arguments."

However, regardless of whether this is intentional, it appears that this has been this way for a very long time. So it seems to me that we should document this behavior, as suggested here, since any change to this would be an unacceptable backwards-incompatibility.
msg367281 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2020-04-25 20:11
It seems pretty clear to me that we should simply update the docs as suggested.

If nobody chimes in about this within a week, I intend to merge the PR (GH-16832) with the small fixes I've suggested there.
msg369841 - (view) Author: Ido Michael (Ido Michael) * Date: 2020-05-24 22:48
Hey Tal, I see this issue is pending and pretty much done, what else there's to fix here?
msg369852 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2020-05-25 07:03
New changeset 372ee27d4958302dac7ad6a8711f6fd04771b2e6 by Jakub Stasiak in branch 'master':
bpo-38580: Document that select() accepts iterables, not just sequences (GH-16832)
https://github.com/python/cpython/commit/372ee27d4958302dac7ad6a8711f6fd04771b2e6
msg369853 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2020-05-25 07:04
Nothing further is required; I've merged the PR. Thanks!
msg369977 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2020-05-26 12:59
New changeset 3f215f35bdb9d666f5a692fc60f800da1bb1e4a9 by Tal Einat in branch '3.7':
[3.7] bpo-38580: Document that select() accepts iterables, not just sequences (GH-16832)
https://github.com/python/cpython/commit/3f215f35bdb9d666f5a692fc60f800da1bb1e4a9
msg369978 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2020-05-26 12:59
New changeset e3e800f3d28881cc9de38cd9bcbcf8fbdea238a6 by Tal Einat in branch '3.8':
[3.8] bpo-38580: Document that select() accepts iterables, not just sequences (GH-16832)
https://github.com/python/cpython/commit/e3e800f3d28881cc9de38cd9bcbcf8fbdea238a6
msg369980 - (view) Author: miss-islington (miss-islington) Date: 2020-05-26 13:38
New changeset 500cd89ecce97750a1af32d4097d9945b7296bac by Miss Islington (bot) in branch '3.9':
bpo-38580: Document that select() accepts iterables, not just sequences (GH-16832)
https://github.com/python/cpython/commit/500cd89ecce97750a1af32d4097d9945b7296bac
msg369981 - (view) Author: Jakub Stasiak (jstasiak) * Date: 2020-05-26 13:42
Cheers for backporting this, Tal, you beat me to it!
History
Date User Action Args
2022-04-11 14:59:22adminsetgithub: 82761
2020-05-26 13:42:13jstasiaksetmessages: + msg369981
2020-05-26 13:38:25miss-islingtonsetmessages: + msg369980
2020-05-26 12:59:35taleinatsetmessages: + msg369978
2020-05-26 12:59:30taleinatsetmessages: + msg369977
2020-05-26 12:20:15taleinatsetpull_requests: + pull_request19684
2020-05-26 12:16:01taleinatsetpull_requests: + pull_request19682
2020-05-25 07:04:58taleinatsetstatus: open -> closed
versions: + Python 3.10
messages: + msg369853

resolution: fixed
stage: patch review -> resolved
2020-05-25 07:04:10miss-islingtonsetkeywords: + patch
nosy: + miss-islington

pull_requests: + pull_request19635
stage: patch review
2020-05-25 07:03:55taleinatsetmessages: + msg369852
2020-05-24 22:48:57Ido Michaelsetnosy: + Ido Michael
messages: + msg369841
2020-04-25 20:11:25taleinatsetmessages: + msg367281
2020-04-16 21:51:17taleinatsetnosy: + taleinat, docs@python
messages: + msg366633

assignee: docs@python
components: + Documentation
2020-01-25 13:38:12cheryl.sabellasetversions: - Python 3.5, Python 3.6
2019-10-25 20:26:21brandtbuchersetnosy: + brandtbucher
2019-10-24 11:12:06corona10setnosy: + vstinner, serhiy.storchaka
2019-10-24 11:08:46jstasiakcreate