title: How to check if a PyObject is a String or Unicode for a Python C Extension
body: <p>In Python(2), the idiomatic way to check if a variable is of <code>str</code> or <code>unicode</code> type is </p>
  
  <pre><code>isinstance(var, basestr)
  </code></pre>
  
  <p>In the <a href="https://docs.python.org/2/c-api/concrete.html" rel="nofollow noreferrer">Concrete Object Layer documentation</a>, I did not see anything resembling <code>basestr</code>.</p>
  
  <p>Currently I am validating variables like the following:</p>
  
  <pre><code>PyObject *key;
  //...
  if (!PyString_Check(key) &amp;&amp; !PyUnicode_Check(key)) {
      PyErr_SetString(PyExc_ValueError, "Key must be string");
      return NULL;
  }
  </code></pre>
  
  <p>Is there a more concise way to check if a <code>PyObject</code> is of type <code>str</code> or <code>unicode</code>?</p>