Message254065
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. |
|
Date |
User |
Action |
Args |
2015-11-04 16:54:16 | paul.j3 | set | recipients:
+ paul.j3, barry, rhettinger, bethard, desbma |
2015-11-04 16:54:16 | paul.j3 | set | messageid: <1446656056.09.0.638655481151.issue25061@psf.upfronthosting.co.za> |
2015-11-04 16:54:16 | paul.j3 | link | issue25061 messages |
2015-11-04 16:54:15 | paul.j3 | create | |
|