Changes extracted from pybind11k commit f8128f0b0d712c210d7d4470a50acc88dc4604ea (PR #30005)

This commit is contained in:
Ralf W. Grosse-Kunstleve 2024-07-31 13:41:34 -07:00
parent 48f25275c4
commit edf03ccd34
5 changed files with 15 additions and 1 deletions

View File

@ -153,6 +153,7 @@ set(PYBIND11_HEADERS
include/pybind11/detail/dynamic_raw_ptr_cast_if_possible.h include/pybind11/detail/dynamic_raw_ptr_cast_if_possible.h
include/pybind11/detail/init.h include/pybind11/detail/init.h
include/pybind11/detail/internals.h include/pybind11/detail/internals.h
include/pybind11/detail/native_enum_data.h
include/pybind11/detail/smart_holder_poc.h include/pybind11/detail/smart_holder_poc.h
include/pybind11/detail/type_caster_base.h include/pybind11/detail/type_caster_base.h
include/pybind11/detail/typeid.h include/pybind11/detail/typeid.h
@ -175,6 +176,7 @@ set(PYBIND11_HEADERS
include/pybind11/gil_safe_call_once.h include/pybind11/gil_safe_call_once.h
include/pybind11/iostream.h include/pybind11/iostream.h
include/pybind11/functional.h include/pybind11/functional.h
include/pybind11/native_enum.h
include/pybind11/numpy.h include/pybind11/numpy.h
include/pybind11/operators.h include/pybind11/operators.h
include/pybind11/pybind11.h include/pybind11/pybind11.h

View File

@ -553,3 +553,8 @@ The ``name`` property returns the name of the enum value as a unicode string.
.. warning:: .. warning::
Contrary to Python customs, enum values from the wrappers should not be compared using ``is``, but with ``==`` (see `#1177 <https://github.com/pybind/pybind11/issues/1177>`_ for background). Contrary to Python customs, enum values from the wrappers should not be compared using ``is``, but with ``==`` (see `#1177 <https://github.com/pybind/pybind11/issues/1177>`_ for background).
.. note::
``py::native_enum`` was added as an alternative to ``py::enum_``
with http://github.com/pybind/pybind11/pull/9999

View File

@ -48,6 +48,9 @@ PYBIND11_NAMESPACE_BEGIN(detail)
class args_proxy; class args_proxy;
bool isinstance_generic(handle obj, const std::type_info &tp); bool isinstance_generic(handle obj, const std::type_info &tp);
template <typename T>
bool isinstance_native_enum(handle obj, const std::type_info &tp);
// Accessor forward declarations // Accessor forward declarations
template <typename Policy> template <typename Policy>
class accessor; class accessor;
@ -845,7 +848,8 @@ bool isinstance(handle obj) {
template <typename T, detail::enable_if_t<!std::is_base_of<object, T>::value, int> = 0> template <typename T, detail::enable_if_t<!std::is_base_of<object, T>::value, int> = 0>
bool isinstance(handle obj) { bool isinstance(handle obj) {
return detail::isinstance_generic(obj, typeid(T)); return detail::isinstance_native_enum<T>(obj, typeid(T))
|| detail::isinstance_generic(obj, typeid(T));
} }
template <> template <>

View File

@ -162,6 +162,7 @@ set(PYBIND11_TEST_FILES
test_methods_and_attributes test_methods_and_attributes
test_modules test_modules
test_multiple_inheritance test_multiple_inheritance
test_native_enum
test_numpy_array test_numpy_array
test_numpy_dtypes test_numpy_dtypes
test_numpy_vectorize test_numpy_vectorize

View File

@ -39,6 +39,7 @@ main_headers = {
"include/pybind11/gil.h", "include/pybind11/gil.h",
"include/pybind11/gil_safe_call_once.h", "include/pybind11/gil_safe_call_once.h",
"include/pybind11/iostream.h", "include/pybind11/iostream.h",
"include/pybind11/native_enum.h",
"include/pybind11/numpy.h", "include/pybind11/numpy.h",
"include/pybind11/operators.h", "include/pybind11/operators.h",
"include/pybind11/options.h", "include/pybind11/options.h",
@ -59,6 +60,7 @@ detail_headers = {
"include/pybind11/detail/dynamic_raw_ptr_cast_if_possible.h", "include/pybind11/detail/dynamic_raw_ptr_cast_if_possible.h",
"include/pybind11/detail/init.h", "include/pybind11/detail/init.h",
"include/pybind11/detail/internals.h", "include/pybind11/detail/internals.h",
"include/pybind11/detail/native_enum_data.h",
"include/pybind11/detail/smart_holder_poc.h", "include/pybind11/detail/smart_holder_poc.h",
"include/pybind11/detail/type_caster_base.h", "include/pybind11/detail/type_caster_base.h",
"include/pybind11/detail/typeid.h", "include/pybind11/detail/typeid.h",