Author jnothman
Recipients bethard, jnothman
Date 2012-11-21.03:28:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The argparse documentation states that "type= can take any callable that takes a single string argument and returns the converted value". The following is an exception:

    >>> import argparse
    >>> ap = argparse.ArgumentParser()
    >>> ap.add_argument('foo', type={}.get)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python3/", line 1294, in add_argument
        type_func = self._registry_get('type', action.type, action.type)
      File "/usr/lib/python3/", line 1236, in _registry_get
        return self._registries[registry_name].get(value, default)
    TypeError: unhashable type: 'dict'

Sadly, a method bound to an unhashable type is unhashable! (Of course, is trivial to use partial or lambda to make any function hashable.)

The offending line in _registry_get is intended to look up named types (or actions), so it perhaps only relevant for string type= and action= values, which could be handled explicitly instead of using dict.get(x, x) to handle both cases. Alternatively, the TypeError could be caught and default returned.
Date User Action Args
2012-11-21 03:28:28jnothmansetrecipients: + jnothman, bethard
2012-11-21 03:28:27jnothmansetmessageid: <>
2012-11-21 03:28:27jnothmanlinkissue16516 messages
2012-11-21 03:28:25jnothmancreate