#!/usr/bin/env python import argparse def number_triple(string): fields = string.strip().split() if len(fields) != 3: print '"%s"' % string raise argparse.ArgumentTypeError('Need exactly 3 numbers') try: ret = (int(fields[0]), int(fields[1]), float(fields[2])) except ValueError: raise argparse.ArgumentTypeError('Need exactly 3 numbers') p = argparse.ArgumentParser(description='Reproduce argparse type bug') p.add_argument('-t', '--triple', metavar='N', nargs=3, type=number_triple) args = p.parse_args('-t 1 2 3'.split()) print args