Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++: classes in classes, cimport not consistent #3074

gerion0 opened this issue Aug 9, 2019 · 1 comment


Copy link

commented Aug 9, 2019

Consider this minimal example:


#pragma once

#include <iostream>

struct Foobar {
        struct LongName {
                void foo() {
                        std::cout << "foo" << std::endl;

        static LongName get() {
                return Foobar::LongName();



#cython: language_level=3

cdef extern from "foo.h":
    cdef cppclass Foobar:
        cppclass LongName:
            void foo()

        LongName get()


from foo cimport Foobar

def my_func():
    cdef Foobar.LongName bla
    bla = Foobar.get()

This works so far. However, this does not work:


cimport foo

def my_func():
    cdef foo.Foobar.LongName bla
    bla = foo.Foobar.get()


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()

While this works:


from foo cimport Foobar

ctypedef Foobar.LongName LongName

def my_func():
    cdef LongName bla
    bla = Foobar.get()

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)?


This comment has been minimized.

Copy link

commented Aug 14, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.