[docs] [issue14836] Add next(iter(o)) to set.pop, dict.popitem entries.

Raymond Hettinger report at bugs.python.org
Mon May 21 01:21:03 CEST 2012

Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:

I don't think it is a good idea to expand to the pop/popitem docs this way.  The text is not about what pop/popitem does, it is about what another hypothetical method might do.  The text would be a distractor from the focused description of what pop/popitem actually do.  Also, it would face discoverability problems (there is no reason to think that someone who wants a nonmutating getfirst() method would think to look in the docs for a mutating method).

Also, the text talks about a general purpose programming technique (how to get the first element out of *any* iterable without removing it).  That belongs in a tutorial entry or a summary of idioms.

FWIW, the "several requests for set.get" haven't been serious requests accompanied by valid use cases.  Instead, they have mostly been toy discussions about all the ways you could do it ("for x in s: break",  "next(iter(s))", "x=s.pop(); s.add(x)").   The absence of get() or pick() in other language's set implementations suggest that there isn't a real need here.

That said, I don't think there is much of a downside to adding a sentence to the set.pop() docs.   It would be a waste though to also put it in dict.pop() and dict.popitem() where the question never seems to arise and where the docs already have issues with trying to over describe what can be done.


Python tracker <report at bugs.python.org>

More information about the docs mailing list