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

generc_type xxxx is already registered #439

Closed
kanaero opened this issue Oct 12, 2016 · 5 comments
Closed

generc_type xxxx is already registered #439

kanaero opened this issue Oct 12, 2016 · 5 comments

Comments

@kanaero
Copy link

kanaero commented Oct 12, 2016

Suppose in test_stl_binders.cpp we have two types mapping back to the same underlying c++ type in this case "unsigned int".

py::bind_vector<std::vector<unsigned int>>(global, "VectorInt");
py::bind_vector<std::vector<unsigned int>>(global, "AnotherVectorInt");

When importing the module, the error generic_type: type "AnotherVectorInt" is already registered! arises.

Are we disallowing type alias within python. Can we not refer to the same vector type using multiple python types ?

If we choose to keep the current behaviour of disallowing multiple aliases for the same underlying type we should improve the error message to say "generic_type: type "AnotherVectorInt" has underlying type "unsigned int" that is already registered.

@wjakob
Copy link
Member

wjakob commented Oct 12, 2016

You can use global.attr("AnotherVectorInt") = global.attr("VectorInt") to create an alias on the Python side. However, you can't register the type two times independently since it would cause various inconsistencies in Python-internal data structures.

@SanPen
Copy link

SanPen commented Jul 11, 2022

I'll add a comment because it might be useful for future viewers.

The generic type error might occur also if the same object is registered by two separated pybind11 modules.

In my case I have two libraries that both need to wrap the Tabulate library. Even if internally I wrap the tabulate library with different object types, the error still persists.

@kliegeois
Copy link

@SanPen I am facing the same issue; how have you resolved this?

@SanPen
Copy link

SanPen commented Dec 5, 2022

Hi! yes I solved it by adding py::module_local() to the class definition

example:

py::class_<Zone, Device, std::shared_ptr<Zone>>(m, "Zone", py::module_local())
.def(py::init<std::string,
                           std::string,
                           std::string,
                           uword>(),
                  py::arg("uuid"),
                  py::arg("secondary_id"),
                  py::arg("name"),
                  py::arg("time_steps"))
            .def_property("area", &Zone::getArea, &Zone::setArea, "Area object to which this zone belongs to. It may be null.")
            ;

This is somewhere in the docs and should be in every example!

@kliegeois
Copy link

Thanks a lot @SanPen !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants