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: Documentation claims that PySequence_Fast returns a tuple, when it actually returns a list.
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, eric.araujo, josh.r, larry, python-dev, rhettinger, serhiy.storchaka, sfllaw
Priority: normal Keywords: patch

Created on 2012-11-03 15:18 by sfllaw, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
16395.patch sfllaw, 2012-11-03 15:32
Messages (8)
msg174633 - (view) Author: Simon Law (sfllaw) * Date: 2012-11-03 15:18
The documentation in Python 2.7, 3.2, and 3.3 claim that:

PyObject* PySequence_Fast(PyObject *o, const char *m)
Return value: New reference.
Returns the sequence o as a tuple, unless it is already a tuple or list, in which case o is returned...

Unfortunately, the code does this in Objects/abstract.c:

    v = PySequence_List(it);

And the header file in Include/abstract.h matches the documentation:

     PyAPI_FUNC(PyObject *) PySequence_Fast(PyObject *o, const char* m);
       /*
     Returns the sequence, o, as a tuple, unless it's already a
     tuple or list.
       */
msg174636 - (view) Author: Simon Law (sfllaw) * Date: 2012-11-03 15:32
It looks like this was caught in the 3.3 branch, but only fixed it in the comment:

changeset:   75448:d8f68195210e
user:        Larry Hastings <larry@hastings.org>
date:        Mon Mar 05 22:59:13 2012 -0800
summary:     Fix a comment: PySequence_Fast() creates a list, not a tuple.

The included patch applies cleanly to Python 2.7 and 3.2. When applying to 3.3, include the failure in Objects/abstract.c because the same change has already been made.
msg174637 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2012-11-03 15:34
Larry, any objection to backporting this?
msg174654 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-11-03 17:55
PySequence_Tuple() was changed to PySequence_List() in the changeset 4714aff4bf75 in 2004.  Are there any measurements which show PySequence_List() faster than PySequence_Tuple() on modern Python?  I don't see any references in 4714aff4bf75 description.
msg215728 - (view) Author: Josh Rosenberg (josh.r) * (Python triager) Date: 2014-04-08 04:38
Any news on this? I was about to open a bug of my own for this, since the docs and code are still out of sync.
msg215729 - (view) Author: Josh Rosenberg (josh.r) * (Python triager) Date: 2014-04-08 04:40
As far as performance goes, presumably the length hinting API reduces the number of cases in which we're working with completely unsized iterables, right?
msg215761 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2014-04-08 14:40
I have no objections to someone backporting this.
msg215763 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-04-08 14:49
New changeset b2187b82a658 by Benjamin Peterson in branch '3.4':
PySequence_Fast generally returns a list not a tuple (closes #16395)
http://hg.python.org/cpython/rev/b2187b82a658

New changeset b235db467cd5 by Benjamin Peterson in branch '2.7':
PySequence_Fast generally returns a list not a tuple (closes #16395)
http://hg.python.org/cpython/rev/b235db467cd5

New changeset c833c35aa13a by Benjamin Peterson in branch 'default':
merge 3.4 (#16395)
http://hg.python.org/cpython/rev/c833c35aa13a
History
Date User Action Args
2022-04-11 14:57:38adminsetgithub: 60599
2014-04-08 14:49:17python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg215763

resolution: fixed
stage: patch review -> resolved
2014-04-08 14:40:45larrysetmessages: + msg215761
2014-04-08 04:40:19josh.rsetmessages: + msg215729
2014-04-08 04:38:22josh.rsetnosy: + josh.r
messages: + msg215728
2012-11-03 17:55:21serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg174654
2012-11-03 15:34:18eric.araujosetassignee: docs@python
components: + Documentation, - Interpreter Core
versions: - Python 3.3
nosy: + docs@python, eric.araujo, larry

messages: + msg174637
stage: patch review
2012-11-03 15:32:43sfllawsetfiles: + 16395.patch
keywords: + patch
messages: + msg174636
2012-11-03 15:25:14eric.araujosetnosy: + rhettinger
2012-11-03 15:18:21sfllawcreate