classification
Title: argparse kwarg 'choices' documentation
Type: behavior Stage: resolved
Components: Documentation Versions: Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: argparse only supports iterable choices
View: 16468
Assigned To: docs@python Nosy List: docs@python, r.david.murray
Priority: normal Keywords:

Created on 2012-12-16 13:53 by wim.glenn, last changed 2013-01-16 07:58 by wim.glenn. This issue is now closed.

Messages (2)
msg177599 - (view) Author: wim glenn (wim.glenn) * Date: 2012-12-16 13:53
Any object that supports the in operator can be passed as the choices value, so dict objects, set objects, custom containers, etc. are all supported.  (from  http://docs.python.org/dev/library/argparse.html#choices )

Actual behaviour is contradicted by the docs - it seems the container must additionally be iterable.  When using a custom container, argparse b0rks on trying to iterate through choices.  Using a metavar prevents this, but it still breaks on cases where the element is not in the container.  

More details here:  
http://stackoverflow.com/questions/13833566/python-argparse-choices-from-an-infinite-set
msg177602 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-12-16 14:21
This is a duplicate of issue issue 16468, which may get closed with either a bug fix or a doc fix, depending on the outcome of the overall discussion.
History
Date User Action Args
2013-01-16 07:58:27wim.glennsetnosy: - wim.glenn
2012-12-16 14:21:37r.david.murraysetstatus: open -> closed

superseder: argparse only supports iterable choices
nosy: + r.david.murray

messages: + msg177602
type: enhancement -> behavior
resolution: duplicate
stage: resolved
2012-12-16 13:53:55wim.glenncreate