Skip to content

[BUG]: Binding two maps with two different integer key types failues due to duplicate KeyViews #4529

Closed
@gatecat

Description

@gatecat

Required prerequisites

What version (or hash if on master) of pybind11 are you using?

3cc7e42

Problem description

The attached example code binds two map types: std::map<uint16_t, uint16_t> and std::map<uint32_t, uint16_t>.

With recent pybind11 this fails when importing with:

ImportError: generic_type: cannot initialize type "KeysView[int]": an object with that name is already defined

Looking at the relevant code:

if (!detail::get_type_info(typeid(KeysView))) {

checks whether a matching key typeid has been wrapped already; but in this case two different typeids have the same string name in pybind11.

This is breaking a project that happens to use this; if there's a workaround other than unifying the map key types that fixes things with recent pybind11 releases that would also be useful to know.

Thanks for your help!

Reproducible example code

#include <pybind11/pybind11.h>
#include <pybind11/stl_bind.h>
#include <map>

namespace py = pybind11;

PYBIND11_MODULE(python_example, m) {
    py::bind_map<std::map<uint16_t, uint16_t>>(m, "u16u16map");
    py::bind_map<std::map<uint32_t, uint16_t>>(m, "u32u16map");
}

Is this a regression? Put the last known working version here if it is.

Believe this was broken by 9db9880. 2.10.0 was known working.

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageNew bug, unverified

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions