Skip to content

fix(native_enum): name the enum and member on a duplicate member - #6239

Open
kroplabeskidu wants to merge 1 commit into
pybind:masterfrom
kroplabeskidu:fix-native-enum-duplicate-member
Open

kroplabeskidu wants to merge 1 commit into
pybind:masterfrom
kroplabeskidu:fix-native-enum-duplicate-member

Conversation

@kroplabeskidu

Copy link
Copy Markdown

Description

Fixes #5853. Calling .value() twice with the same name on a py::native_enum fails inside enum.Enum(...) with a message that names neither the enum nor the binding:

TypeError: 'dup' already defined as 0

During module init this ends up as ImportError: initialization failed, which makes the duplicate hard to find. finalize() now checks for duplicates first and uses the same format as the other native_enum errors:

pybind11::native_enum<...>("fake_native_enum_duplicate_value_name").value("dup"): an object with that name is already defined

The check runs once in finalize() using a set, so it doesn't make .value() quadratic for large enums.

Suggested changelog entry:

  • py::native_enum now names the enum and member when a member name is registered twice.

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

[BUG]: Misleading errors on duplicate enum key registration

1 participant