[BUG]: Misleading errors on duplicate enum key registration
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.
What version (or hash if on master) of pybind11 are you using?
3.0.1
Problem description
I added duplicate enum keys by accident:
py::native_enum<StandardIconType>(m, "StandardIconType", "enum.IntEnum")
.value("TitleBarMenuButton", TitleBarMenuButton)
.value("TitleBarMenuButton", TitleBarMenuButton)
…
Now i get lots of warnings like:
15:36:31 [warn:albert.python] ImportError: initialization failed
At:
/Users/manuel/Library/Application Support/albert/python/plugins/color/__init__.py(17): <module>
<frozen importlib._bootstrap>(488): _call_with_frames_removed
<frozen importlib._bootstrap_external>(1026): exec_module
15:36:31 [debg:albert] Plugin python.color unloaded. ImportError: initialization failed
At:
/Users/manuel/Library/Application Support/albert/python/plugins/color/__init__.py(17): <module>
<frozen importlib._bootstrap>(488): _call_with_frames_removed
<frozen importlib._bootstrap_external>(1026): exec_module
15:36:32 [warn:albert.python] ImportError: generic_type: type "PluginInstance" is already registered!
At:
/Users/manuel/Library/Application Support/albert/python/plugins/firefox/__init__.py(9): <module>
<frozen importlib._bootstrap>(488): _call_with_frames_removed
<frozen importlib._bootstrap_external>(1026): exec_module
15:36:32 [debg:albert] Plugin python.firefox unloaded. ImportError: generic_type: type "PluginInstance" is already registered!
At:
/Users/manuel/Library/Application Support/albert/python/plugins/firefox/__init__.py(9): <module>
<frozen importlib._bootstrap>(488): _call_with_frames_removed
<frozen importlib._bootstrap_external>(1026): exec_module
15:36:32 [warn:albert.python] ImportError: generic_type: type "MatchConfig" is already registered!
At:
/Users/manuel/Library/Application Support/albert/python/plugins/jetbrains_projects/__init__.py(43): <module>
<frozen importlib._bootstrap>(488): _call_with_frames_removed
<frozen importlib._bootstrap_external>(1026): exec_module
15:36:32 [debg:albert] Plugin python.jetbrains_projects unloaded. ImportError: generic_type: type "MatchConfig" is already registered!
At:
/Users/manuel/Library/Application Support/albert/python/plugins/jetbrains_projects/__init__.py(43): <module>
<frozen importlib._bootstrap>(488): _call_with_frames_removed
<frozen importlib._bootstrap_external>(1026): exec_module
Basically for each import of the embedded module I get weird is already registered! errros for types that are not part of the actual problem. It took me quite a while to find the actual problem statement (the duplicate enum above).
I would be useful if the errord could indicate the actually duplicate registration of the enum key instead of random other symbols.
Reproducible example code
See above
Is this a regression? Put the last known working version here if it is.
Not a regression
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 by reproducing the duplicate .value("TitleBarMenuButton", ...) registration in py::native_enum and trace the registration path that reports the later generic_type errors. Check how duplicate enum keys are validated and how the resulting exception propagates during embedded-module imports. Done means the reported error identifies the duplicate enum key rather than unrelated already-registered types.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100