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.

Author chris.jerdonek
Recipients chris.jerdonek, terry.reedy
Date 2012-11-14.04:32:17
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
This issue is to ensure that argparse.ArgumentParser() accepts objects that support the "in" operator for the "choices" argument to ArgumentParser.add_argument().

As observed by Terry in the comments to issue 16418:

the argparse module does not in general support "choices" values that support the "in" operator, even though the argparse documentation says it does:

"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 )

For example, passing a user-defined type that implements only self.__contains__() yields the following error message when calling ArgumentParser.parse_args():

File ".../Lib/", line 1293, in add_argument
  raise ValueError("length of metavar tuple does not match nargs")

(The error message also gives the wrong reason for failure.  The swallowed exception is "TypeError: '<class>' object is not iterable.")
Date User Action Args
2012-11-14 04:32:19chris.jerdoneksetrecipients: + chris.jerdonek, terry.reedy
2012-11-14 04:32:19chris.jerdoneksetmessageid: <>
2012-11-14 04:32:19chris.jerdoneklinkissue16468 messages
2012-11-14 04:32:17chris.jerdonekcreate