title: How to test if object is a mapping (supports **O usage)
body: <p>I need to test if objects read in from a file (and <code>eval</code>ed) with <code>ConfigParser</code> are mappings.</p>
  
  <p>Not entirely sure about the terminology here, but let me explain. Given that my object is called <code>O</code> it must support being used in the following manner:</p>
  
  <pre><code>def tester(**kwargs):
       print kwargs
  
  tester(**O)
  </code></pre>
  
  <p>If <code>O</code> was not supporting the ** this would result in a TypeError, e.g. <code>TypeError: test() argument after ** must be a mapping, not tuple</code>.</p>
  
  <p>It's a really simple scenario, but I need to know that <code>O</code> will work before using it and I need to be absolutely certain it won't fail. If I was testing <code>O</code> for being an iterable, I would use something like:</p>
  
  <pre><code>try:
     iter(O)
  except:
     O = tuple()
  </code></pre>
  
  <p>As discussed in <a href="https://stackoverflow.com/questions/1952464/in-python-how-do-i-determine-if-an-object-is-iterable/1952481#1952481">In Python, how do I determine if an object is iterable?</a> </p>
  
  <p>I can't find any parallel for mappings. As discussed in the same answer above, using <code>isinstance</code> and <code>collections</code> isn't an good solution.</p>
  
  <p>So do I have to make my tester-function above (without the print) as my own mapping-test when loading the objects like</p>
  
  <pre><code>try:
      tester(**O)
  except TypeError:
      O = {}
  </code></pre>
  
  <p>or does python have a built in way to test this like there is for iterables? It seems there should be one.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Actually the linked answer above never spoke against the isinstance method, should have read it better...</p>