-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix enum value's __int__ returning non-int when underlying type is bool or of char type #1334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Is |
I see. It corresponds to the compile error which seems to tell me that |
Sorry for my foolishness of not getting your point and suspended this PR for one year long... I've updated the PR to keep pace with the master, and fixed it with a more robust mechanism, along with more tests, to solve both issues of char and bool types. My original post for context reference:
|
__int__
and __hash__
's TypeError when enum's underlying type is of char type
HI @Vigilans - looking through unfixed problems with propose solutions, do you think it would be possible to rebase this pull request for a new round of review? Sorry for the long delay on this! |
tests/test_enum.cpp
Outdated
std::is_same<py::enum_<ScopedChar32Enum>::Scalar, std::uint_least32_t>, | ||
std::is_same<py::enum_<ScopedChar16Enum>::Scalar, std::uint_least16_t> | ||
>::value, "char32_t, char16_t (and char8_t)'s size, signedness, and alignment is determined"); | ||
#if defined(PYBIND11_CPP20) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a nit: we should probably start testing the CPP20 soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your rebase and review! And sorry for my long delay on last comment since I didn't check github's email frequently at that time...
What should I do to help the testing of CPP20 in this pull request? As shown in detail::is_std_char_type
's implementation:
pybind11/include/pybind11/cast.h
Lines 111 to 119 in 031a700
template <typename CharT> using is_std_char_type = any_of< | |
std::is_same<CharT, char>, /* std::string */ | |
#if defined(PYBIND11_HAS_U8STRING) | |
std::is_same<CharT, char8_t>, /* std::u8string */ | |
#endif | |
std::is_same<CharT, char16_t>, /* std::u16string */ | |
std::is_same<CharT, char32_t>, /* std::u32string */ | |
std::is_same<CharT, wchar_t> /* std::wstring */ | |
>; |
Should I replace the PYBIND11_CPP20
macro with PYBIND11_HAS_U8STRING
in this test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What should I do to help the testing of CPP20 in this pull request?
The first step is on us (Aaron, Henry, me), we need to add a job to the CI.
Not sure if we should block this PR on that, or merge this PR first and then fix up as needed when establishing the CPP20 job. I'm fine either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks! Could you please leave a small comment "ready to merge!" when it is. (I see you made a series of small changes, therefore I'm not sure if you're still working on something.)
@rwgk Thanks for your patience! I'm working on satisfying the formatter and fixing test failure in some python 2.7 platforms ( |
@rwgk Seems some of the workflows need further approval. Personally I think it is ready to merge with:
|
CI all green! Thanks @Vigilans and all reviewers. Merging. |
…nt when underlying type is bool or of char type) (#3232) * Minor tweaks. * Restoring tests/pybind11_tests.h version from master, removing just the comment and empty line that was added in PR #3087; those were made obsolete by the pragma cleanup that concluded with PR #3186. * More-to-the-point test for Python 3.
Introduction
This PR solves the problem of enum value's
__int__
returning a non-int value when its underlying type is bool or of char type.Detail
This PR extends the
enum_
class with following type alias:Underlying
type: the actual underlying type of enum (The originalScalar
type);Scalar
type: the integer type with length and signedness equivalent to the underlying type.The enum should always use
Scalar
as the inner integer type when dealing with python side.So,
equivalent_integer
struct.Applicable issues
Fix #1331
Fix #1820
Fix osmcode/pyosmium#114
Suggested changelog entry:
Bug fix: enum value's `__int__` returning non-int when underlying type is bool or of char type. Fixes #1331, #1820.