title: Pybind11: external type as return value
body: <p>With pybind11 I need to bind a function that returns an object type whose binding is already available from another extension module (also created with pybind11). I know this is generally possible since <a href="https://pybind11.readthedocs.io/en/stable/advanced/misc.html#partitioning-code-over-multiple-extension-modules" rel="nofollow noreferrer">the docs say so</a> and I've also managed to build a <a href="https://github.com/simleo/pybind11_examples/tree/master/multi_ext" rel="nofollow noreferrer">complete toy example where things work fine</a>. However, for some reason I don't understand, I cannot make it work If the external type is the <code>Tensor</code> type from <a href="https://github.com/deephealthproject/pyeddl" rel="nofollow noreferrer">https://github.com/deephealthproject/pyeddl</a>. I know that <code>-fvisibility=hidden</code> is not an issue because:</p>
  
  <ul>
  <li>it's also present in the toy example;</li>
  <li>I've also tried rebuilding pyeddl without it.</li>
  </ul>
  
  <p><code>src/dummy_bindings.cpp</code>:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;pybind11/pybind11.h&gt;
  #include &lt;eddl/tensor/tensor.h&gt;
  
  Tensor* mkTensor() {
      return new Tensor();
  }
  
  PYBIND11_MODULE(_foo, m) {
      m.def("mkTensor", &amp;mkTensor);
  }
  </code></pre>
  
  <p><code>setup.py</code>:</p>
  
  <pre class="lang-py prettyprint-override"><code>from distutils.core import setup, Extension
  import pybind11
  
  ext = Extension(
      "_foo",
      sources=["src/dummy_bindings.cpp"],
      include_dirs=[
          "src",
          pybind11.get_include(),
          pybind11.get_include(user=True)
      ],
      libraries=["eddl"],
  )
  
  setup(
      name="foo",
      ext_modules=[ext]
  )
  </code></pre>
  
  <p>Test python code:</p>
  
  <pre class="lang-py prettyprint-override"><code>import pyeddl._core
  import _foo
  
  print(pyeddl._core.Tensor)
  t = _foo.mkTensor()
  </code></pre>
  
  <p>This leads to:</p>
  
  <pre><code>&lt;class 'pyeddl._core.Tensor'&gt;
  Traceback (most recent call last):
    File "foo.py", line 5, in &lt;module&gt;
      t = _foo.mkTensor()
  TypeError: Unable to convert function return value to a Python type! The signature was
      () -&gt; Tensor
  </code></pre>
  
  <p>My understanding is that the <code>import pyeddl._core</code> should make the <code>Tensor</code> type visible at runtime and make the call to <code>mkTensor</code> work. At least, it does work in the toy example. However, I get the above error. I'm also the author of the pyeddl bindings, so I'm wondering if I'm doing something wrong there that prevents the type from being findable by other extensions. Or perhaps there is something more about the way pybind11 decides if a value can be converted to a Python type that I don't understand.</p>