Using the click package: Making an option be a choice of `int`
<p>I'm trying to make a <code>click.option</code> be a choice between the numbers <code>0</code>, <code>1</code> and <code>2</code>. I tried this: </p>

<pre><code>@click.Option('--verbosity', default=1, type=click.Choice([0, 1, 2]))
def f():
    # ...
    pass
</code></pre>

<p>But I get the exception <code>TypeError: sequence item 0: expected str instance, int found</code>. I guess <code>click</code> expects only strings in <code>click.Choice</code>. Any way to get it to accept ints? I know I can convert to int manually after it's received, but if there's an idiomatic way to receive an <code>int</code> choice, that'll be better.</p>

<p>You can use <code>IntRange(min=0, max=2)</code>:</p>

<blockquote>
  <p><code>class click.IntRange(min=None, max=None, clamp=False)</code>  </p>
  
  <p>A parameter
  that works similar to click.INT but restricts the value to fit into a
  range. The default behavior is to fail if the value falls outside the
  range, but it can also be silently clamped between the two edges.</p>
</blockquote>

<p><a href="http://click.pocoo.org/5/api/#click.IntRange" rel="nofollow">From the docs.</a></p>

python click