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 paul.j3
Recipients barry, bethard, desbma, paul.j3, rhettinger
Date 2015-11-04.16:54:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1446656056.09.0.638655481151.issue25061@psf.upfronthosting.co.za>
In-reply-to
Content
The choice of 'type' for this parameter is occasionally confusing, because the connection to the Python 'type()' function or what we think of as 'native types' is only tangential.

A name like 'converter' or 'string_converter' would be more accurate (but I'm not advocating any change).  

There are lots of 'native' types (isn't everything 'first class' in Python?) that are not supported by 'argparse', simply because Python does not have functions that convert from string to that type.

For example:

   bool, list, tuple, dict, set

Technically `type=list` works, if you want `list('[1]') =>['[','i',']']`.  `type=json` is probably a better choice.

`type=int` works because there is a Python function, int(), that takes a string and returns an object of the same type name.  'argparse' does not do anything special to support it.

FileType is a nice example of how a factory class can be used as 'type' parameter, but shouldn't be confused with support for the 'file' 'native type'.

There's an on going tension between adding useful features and maintaining some level of simplicity and clarity in this module.
History
Date User Action Args
2015-11-04 16:54:16paul.j3setrecipients: + paul.j3, barry, rhettinger, bethard, desbma
2015-11-04 16:54:16paul.j3setmessageid: <1446656056.09.0.638655481151.issue25061@psf.upfronthosting.co.za>
2015-11-04 16:54:16paul.j3linkissue25061 messages
2015-11-04 16:54:15paul.j3create