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: argparse kwarg 'choices' documentation
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.7, Python 3.6, Python 3.5, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: argparse only supports iterable choices
View: 16468
Assigned To: docs@python Nosy List: BrenBarn, docs@python, r.david.murray
Priority: normal Keywords:

Created on 2012-12-16 13:53 by wim.glenn, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
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.
msg349913 - (view) Author: Brendan Barnwell (BrenBarn) Date: 2019-08-18 03:09
This issue has sat idle for six years.  Meanwhile, the docs are still incorrect, giving every user wrong information about how the module works.  Can we consider just changing the documentation instead of worrying about what the behavior should be or what the rationale is?
History
Date User Action Args
2022-04-11 14:57:39adminsetgithub: 60901
2019-08-18 03:09:58BrenBarnsetnosy: + BrenBarn

messages: + msg349913
versions: + Python 3.5, Python 3.6, Python 3.7
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