Repository navigation
Conversation
Adding two values with the same name to a native_enum used to fail only in finalize(), with a TypeError from the enum module that does not name the enum. Check for duplicates in value() and fail with a message that names the enum and the value, like the other native_enum errors.
Use the same make_tuple() conversion as before for the member name, so that a malformed UTF-8 name still raises UnicodeDecodeError on GraalPy.
Author
|
Closing this — on reflection the change is too minor to be worth your review time. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #5853.
Calling
.value()twice with the same name on apy::native_enumis accepted, and the error only shows up infinalize(), whereenum.Enum(...)raisesTypeError: 'x' already defined as 0. The message does not say which enum is affected, and for a module it ends up chained underImportError: initialization failed, which is what the reporter saw (they had to bisect their bindings to find the duplicate).native_enum::value()now checks the names added so far and fails right away with a message in the same format as the existing native_enum errors:Since it is a
std::runtime_error, a failure during module init is reported directly asImportError: <that message>.Added
test_native_enum_duplicate_value_name. Without the change it fails with theTypeErrorfrom the enum module. The full test suite passes locally (macOS arm64, Python 3.13, Debug).Suggested changelog entry:
py::native_enum::value()now reports a duplicate member name with a clear error message instead of failing later infinalize()with aTypeErrorfrom theenummodule.