File tree Expand file tree Collapse file tree 2 files changed +10
-7
lines changed Expand file tree Collapse file tree 2 files changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,8 @@ Unreleased
18
18
line values are given. :issue: `1903 `
19
19
- Flag options guess their type from ``flag_value `` if given, like
20
20
regular options do from ``default ``. :issue: `1886 `
21
+ - Added documentation that custom parameter types may be passed
22
+ already valid values in addition to strings. :issue: `1898 `
21
23
22
24
23
25
Version 8.0.0
Original file line number Diff line number Diff line change @@ -118,19 +118,15 @@ integers.
118
118
name = " integer"
119
119
120
120
def convert (self , value , param , ctx ):
121
+ if isinstance (value, int ):
122
+ return value
123
+
121
124
try :
122
125
if value[:2 ].lower() == " 0x" :
123
126
return int (value[2 :], 16 )
124
127
elif value[:1 ] == " 0" :
125
128
return int (value, 8 )
126
129
return int (value, 10 )
127
- except TypeError :
128
- self .fail(
129
- " expected string for int() conversion, got "
130
- f " { value!r } of type { type (value).__name__ } " ,
131
- param,
132
- ctx,
133
- )
134
130
except ValueError :
135
131
self .fail(f " { value!r } is not a valid integer " , param, ctx)
136
132
@@ -140,3 +136,8 @@ The :attr:`~ParamType.name` attribute is optional and is used for
140
136
documentation. Call :meth: `~ParamType.fail ` if conversion fails. The
141
137
``param `` and ``ctx `` arguments may be ``None `` in some cases such as
142
138
prompts.
139
+
140
+ Values from user input or the command line will be strings, but default
141
+ values and Python arguments may already be the correct type. The custom
142
+ type should check at the top if the value is already valid and pass it
143
+ through to support those cases.
You can’t perform that action at this time.
0 commit comments