paul j3 added the comment:
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.
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue25061>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com