Skip to content

Commit bec6ea1

Browse files
Rephrase and add success case
1 parent e710509 commit bec6ea1

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Doc/library/argparse.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,12 +1021,11 @@ necessary type-checking and type conversions to be performed.
10211021
If the type_ keyword is used with the default_ keyword, the type converter
10221022
is only applied if the default is a string.
10231023

1024-
The argument to ``type`` can be any callable that accepts a single string.
1024+
The argument to ``type`` can be a callable that accepts a single string or
1025+
the name of a registered type (see :meth:`~ArgumentParser.register`)
10251026
If the function raises :exc:`ArgumentTypeError`, :exc:`TypeError`, or
10261027
:exc:`ValueError`, the exception is caught and a nicely formatted error
1027-
message is displayed. Other exception types are not handled. You can also
1028-
customize how the type is displayed in error messages by registering it with
1029-
the parser using :meth:`~ArgumentParser.register`.
1028+
message is displayed. Other exception types are not handled.
10301029

10311030
Common built-in types and functions can be used as type converters:
10321031

@@ -2188,6 +2187,8 @@ Registering custom types or actions
21882187
>>> parser.register('type', 'hexadecimal integer', lambda s: int(s, 16))
21892188
>>> parser.add_argument('--foo', type='hexadecimal integer')
21902189
_StoreAction(option_strings=['--foo'], dest='foo', nargs=None, const=None, default=None, type='hexadecimal integer', choices=None, required=False, help=None, metavar=None, deprecated=False)
2190+
>>> parser.parse_args(['--foo', '0xFA'])
2191+
Namespace(foo=250)
21912192
>>> parser.parse_args(['--foo', '1.2'])
21922193
usage: PROG [-h] [--foo FOO]
21932194
PROG: error: argument --foo: invalid 'hexadecimal integer' value: '1.2'

0 commit comments

Comments
 (0)