File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed
Misc/NEWS.d/next/Documentation Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -1017,7 +1017,15 @@ User defined functions can be used as well:
10171017
10181018The :func: `bool ` function is not recommended as a type converter. All it does
10191019is convert empty strings to ``False `` and non-empty strings to ``True ``.
1020- This is usually not what is desired.
1020+ This is usually not what is desired::
1021+
1022+ >>> parser = argparse.ArgumentParser()
1023+ >>> _ = parser.add_argument('--verbose', type=bool)
1024+ >>> parser.parse_args(['--verbose', 'False'])
1025+ Namespace(verbose=True)
1026+
1027+ See :class: `BooleanOptionalAction ` or ``action='store_true' `` for common
1028+ alternatives.
10211029
10221030In general, the ``type `` keyword is a convenience that should only be used for
10231031simple conversions that can only raise one of the three supported exceptions.
Original file line number Diff line number Diff line change 1+ Expand :mod: `argparse ` documentation for ``type=bool `` with a demonstration
2+ of the surprising behavior and pointers to common alternatives.
You can’t perform that action at this time.
0 commit comments