Consider this minimal example:
foo.h
#pragma once
#include <iostream>
struct Foobar {
struct LongName {
void foo() {
std::cout << "foo" << std::endl;
}
};
static LongName get() {
return Foobar::LongName();
}
};
foo.pxd
#cython: language_level=3
cdef extern from "foo.h":
cdef cppclass Foobar:
cppclass LongName:
void foo()
@staticmethod
LongName get()
foo.pyx
from foo cimport Foobar
def my_func():
cdef Foobar.LongName bla
bla = Foobar.get()
bla.foo()
This works so far. However, this does not work:
foo1.pyx
cimport foo
def my_func():
cdef foo.Foobar.LongName bla
bla = foo.Foobar.get()
bla.foo()
foo2.pyx
from foo cimport Foobar
from foo cimport Foobar.LongName as LongName
# alternative, also not working:
# from foo.Foobar cimport LongName as LongName
def my_func():
cdef LongName bla
bla = Foobar.get()
bla.foo()
While this works:
foo3.pyx
from foo cimport Foobar
ctypedef Foobar.LongName LongName
def my_func():
cdef LongName bla
bla = Foobar.get()
bla.foo()
For me, this feels like C++ class in C++ class is not consistent. Is it possible to support also the long nested name (foo.Foobar.LongName)?
A cimport from a class cannot work (only from modules, as in Python), but the other examples look reasonable to me. PR welcome to make them work.
Most helpful comment
A
cimportfrom a class cannot work (only from modules, as in Python), but the other examples look reasonable to me. PR welcome to make them work.