title: Argparse: how can I suppress the list of choices for "invalid choice" error?
body: <p>How can I suppress or customize the argparse error message when a user passes in an argument outside of the specified choices?</p>
  <p>I'm writing a script that requires the user to pass in a number (int) when they execute the program, which I've defined using the <code>choices</code> argument.  I understand how to use the <code>metavar</code> argument to customize the <code>--help</code> text, but when the user passes in a value outside the range, the error field dumps every possible value from the range - not good for a large range!</p>
  <p>Here's the code for an example script:</p>
  <pre><code>import argparse
  
  parser = argparse.ArgumentParser()
  parser.add_argument(
      &quot;--ID&quot;,
      type=int,
      choices=range(1, 10),
      required=True,
      help=&quot;My helpful help text.&quot;,
      metavar=&quot;&quot;,
  )
  args = parser.parse_args()
  </code></pre>
  <p>And here's the output:</p>
  <pre><code>$ python3 foo.py --ID 12
  usage: foo.py [-h] --ID 
  foo.py: error: argument --ID: invalid choice: 12 (choose from 1, 2, 3, 4, 5, 6, 7, 8, 9)
  </code></pre>
  <p>In my actual script, I'd have <code>choices=range(1,1000000)</code>.  This would not lead to fun error messages if the user enters a number outside that range as they'd be presented with a dump of a million (minus 1) numbers to choose from!</p>
  <p>How can I get the error message to read as something more friendly like:</p>
  <pre><code>$ python3 foo.py --ID 12
      usage: foo.py [-h] --ID 
      foo.py: error: argument --ID: invalid choice: 12 (choose from {1, 9})
  </code></pre>