[BUG]: Conflict when binding two classes with same name from different anonymous namespaces
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
Required prerequisites
- Make sure you've read the documentation. Your issue may be addressed there.
- Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
- Consider asking first in the Gitter chat room or in a Discussion.
Problem description
I have two separate C++ files, each of which defines a class with the same name in an anonymous namespace (thus "private" to that file) and then binds that class with pybind. Each of these files provides a different Python module name. Hence, in my mind, there should be no conflict: two separate modules, two separate files, two separate classes belonging to two separate anonymous namespaces.
However, when I import both modules, this happens upon importing the second one:
ImportError: generic_type: type "MyClass" is already registered!
Which makes it seem that pybind is getting confused and somehow mixes up these two classes because they have the same name, even though they're completely different C++ types.
Reproducible example code
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproducible example code in the linked gist and import both generated Python modules to confirm the registration conflict. Trace how pybind11 identifies and registers the two C++ classes, then verify that the modules can be imported together without treating the distinct anonymous-namespace types as the same type.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100