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: doc: Explicitly mention use of 'enum.Enum' as a valid container for 'choices' argument of 'argparse.ArgumentParser.add_argument'
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, miss-islington, rhettinger, vincent-ferotin
Priority: normal Keywords: patch

Created on 2020-06-18 14:02 by vincent-ferotin, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 20964 merged vincent-ferotin, 2020-06-18 14:22
PR 21527 merged miss-islington, 2020-07-17 22:53
Messages (7)
msg371812 - (view) Author: Vincent Férotin (vincent-ferotin) * Date: 2020-06-18 14:02
It is currently not obvious, reading :mod:`argparse` documentation, that :meth:`argparse.ArgumentParser.add_argument` could accept as 'choices' parameter an :class:`enum.Enum`.
However, it seems (at least to me) that this 'choices' parameter [1] is the perfect candidat of enums usage (see [2]).

So I suggest here to explicitly mention and illustrate such usage in current Python documentation. As far I as could test, such usage works at least with Python 3.5, 3.7, and 3.8.

A small patch on 'master' branches is in progress, and should shortly be available as a GitHub pull-request.

[1] https://docs.python.org/3/library/argparse.html#choices
[2] PEP 435: https://www.python.org/dev/peps/pep-0435/#motivation
msg371935 - (view) Author: miss-islington (miss-islington) Date: 2020-06-20 12:55
New changeset 344c2a75c1c13de781962a3f80552e66a4c89024 by Vincent Férotin in branch 'master':
bpo-41024: doc: Explicitly mention use of 'enum.Enum' as a valid container for '… (GH-20964)
https://github.com/python/cpython/commit/344c2a75c1c13de781962a3f80552e66a4c89024
msg373834 - (view) Author: Vincent Férotin (vincent-ferotin) * Date: 2020-07-17 15:16
Explicitly add Raymond Hettinger to nosy list, as he reviewed the corresponding PR.
msg373835 - (view) Author: Vincent Férotin (vincent-ferotin) * Date: 2020-07-17 15:23
Unless I am mistaken, merged pull-request was not backported from master to other potential branches (3.5 -> 3.9 included). There was a message from GitHub 'miss-islington' bot (https://github.com/python/cpython/pull/20964#issuecomment-646991186) saying, if I understand correctly, to manually cherry-pick merged commit to other branches. Am I correct?
And if so, is there some automatic process for this cherry-picking to re-run, or do someone have to do it manually?
msg373860 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2020-07-17 22:55
The backport failed for 3.9.  I'll trigger it again.

Don't see a need to go back to older versions.  This is a minor informational note, not a bug.
msg373862 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2020-07-17 23:43
New changeset 760552ceb8c5f5ca4f1bf13f47543b42b25e0b83 by Miss Islington (bot) in branch '3.9':
bpo-41024: doc: Explicitly mention use of 'enum.Enum' as a valid container for '… (GH-20964) (GH-21527)
https://github.com/python/cpython/commit/760552ceb8c5f5ca4f1bf13f47543b42b25e0b83
msg373863 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2020-07-17 23:44
Thanks for the PR.
History
Date User Action Args
2022-04-11 14:59:32adminsetgithub: 85196
2020-07-17 23:44:23rhettingersetstatus: open -> closed
resolution: fixed
messages: + msg373863

stage: patch review -> resolved
2020-07-17 23:43:06rhettingersetmessages: + msg373862
2020-07-17 22:55:11rhettingersetmessages: + msg373860
versions: - Python 3.5, Python 3.6, Python 3.7, Python 3.8
2020-07-17 22:53:24miss-islingtonsetstatus: pending -> open
pull_requests: + pull_request20663
2020-07-17 15:23:42vincent-ferotinsetstatus: open -> pending

messages: + msg373835
2020-07-17 15:16:56vincent-ferotinsetnosy: + rhettinger
messages: + msg373834
2020-06-20 12:55:09miss-islingtonsetnosy: + miss-islington
messages: + msg371935
2020-06-18 14:22:54vincent-ferotinsetkeywords: + patch
stage: patch review
pull_requests: + pull_request20142
2020-06-18 14:02:27vincent-ferotincreate