The type() function doesn't consider inheritance, so type(MockContact) == dict evaluates to False. To handle inheritance properly you need to use isinstance().

From my understanding of Python idioms, it is generally preferred to test whether an object can be used in the way you want rather than explicitly testing the type. This is what he _is_dict() function above does. Having said that, just testing for the keys() function isn't quite good enough. What I should be doing is testing if item[item.keys()[0]] works, since it tells me that the object both has keys and that they can be used to access items as expected. This handles the case where an object behaves like a dict but isn't derived from any of the built-in dict classes.

Having said that though, I don't think we need to be concerned about handling pseudo-dict objects here so I'll just replace instances of this function with isinstance() since it does what we need and doesn't require paragraphs of explanation :).