title: Cython - Checking types of objects
body: <p>How can I check the types of python objects within cython?</p>
  
  <p>My Cython extension <code>E</code> compiles to <code>E.pyd</code> within a module <code>M</code>.</p>
  
  <p>I am trying to check the type of a python parameter in <code>class A</code> of Cython extension <code>E</code>.</p>
  
  <pre><code>cdef class A:
      def foo(self, bar):
          if bar is A:
              print("ok")
          else
              print("invalid")
  </code></pre>
  
  <p>The trouble is when I go and use the extension from python, </p>
  
  <pre><code>from M import E
  a = A()
  b = A()
  a.foo(b)
  </code></pre>
  
  <p>bar is not A, but rather <code>M.E.A</code> when I use <code>type(b)</code> from Python</p>
  
  <p>I have tried <code>if bar is M.E.A:</code> from within Cython but the compiler complains <code>undeclared name not builtin: M</code>, since Cython doesn't know about the module.</p>