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: Typo in Mutable Sequence Types documentation.
Type: resource usage Stage:
Components: Documentation Versions: Python 3.6, Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: docs@python, eimista, eric.smith, rhettinger, yselivanov
Priority: normal Keywords:

Created on 2015-05-29 10:44 by eimista, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (6)
msg244365 - (view) Author: (eimista) Date: 2015-05-29 10:44
In section (https://docs.python.org/3.5/library/stdtypes.html#mutable-sequence-types) written "s.pop([i])". But this syntax doesn't work.
Maybe the correct notation will be "s.pop(i)"?
msg244369 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2015-05-29 11:56
It's trying to say that "i" is optional, as stated in the footnote. I agree it would be better written as "s.pop(i)", since square brackets are otherwise used in that section as indexing operators. But the footnote should stay, explaining what happens if you omit the parameter.
msg244379 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015-05-29 14:06
I think it should be changed to `pop(i=-1)`.
msg244381 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2015-05-29 14:42
s.pop(i=-1) doesn't actually work, but I guess it gets the point across.

For 2.7 it's even more confusing, since it includes:
s.index(x[, i[, j]])
and
s.sort([cmp[, key[, reverse]]])

I'd suggest not changing the 2.7 docs.
msg244545 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2015-05-31 16:49
There isn't much defense against an overly literal reading of the docs.  Both ``s.pop([i])`` and ``s.pop(i=-1)`` fail (the latter because pop doesn't take key word arguments and the docstring calls it "index".  Also, you would have to define *s* and *i*. 

FWIW, there is already a note to the effect, "The optional argument i defaults to -1, so that by default the last item is removed and returned."

The [optional_arg] notation is used in a number of places in the docs and docstrings.  It is also common with other languages as well and it is used in third-party Python references as well.  Eric's initial suggestion of ``s.pop(i)`` is simply wrong and would make the docs worse.

As a starting point, realize that the docs have worked well for a lot of people for a long time so there should be a reluctance to change them on a single misreading.

The tutorial also includes the same notation, (see https://docs.python.org/3/tutorial/datastructures.html#more-on-lists ) and as far as I can tell, this has never been an issue.

One other thought, the most common way to call pop() is without an argument (usually, if you use an argument, it is a performance bug).  We want to make sure the docs don't suggest otherwise.

Unless there is some strong objection, I recommend leaving the docs as-is.
msg244546 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2015-05-31 17:04
I don't feel particularly strongly about it. It's mildly more confusing in the 3.x docs than 2.7 because it's the only use in that section of an optional argument.

I disagree that s.pop(i) is wrong, since it agrees with the "Results" column. But I agree it's not an improvement and we shouldn't encourage it.
History
Date User Action Args
2022-04-11 14:58:17adminsetgithub: 68511
2015-05-31 23:11:35rhettingersetstatus: open -> closed
resolution: not a bug
2015-05-31 17:04:33eric.smithsetmessages: + msg244546
2015-05-31 16:49:53rhettingersetmessages: + msg244545
2015-05-31 15:49:46rhettingersetassignee: docs@python -> rhettinger

nosy: + rhettinger
2015-05-29 14:42:22eric.smithsetmessages: + msg244381
2015-05-29 14:06:05yselivanovsetnosy: + yselivanov
messages: + msg244379
2015-05-29 11:57:46eric.smithsetversions: - Python 3.2, Python 3.3
2015-05-29 11:56:33eric.smithsetnosy: + eric.smith
messages: + msg244369
2015-05-29 10:44:17eimistacreate