mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-23 13:45:10 +00:00
Merge branch 'pybind:master' into master
This commit is contained in:
commit
b53af6310c
1
.github/workflows/ci.yml
vendored
1
.github/workflows/ci.yml
vendored
@ -114,6 +114,7 @@ jobs:
|
||||
run: >
|
||||
cmake -S . -B .
|
||||
-DPYBIND11_WERROR=ON
|
||||
-DPYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION=ON
|
||||
-DPYBIND11_SIMPLE_GIL_MANAGEMENT=ON
|
||||
-DPYBIND11_NUMPY_1_ONLY=ON
|
||||
-DDOWNLOAD_CATCH=ON
|
||||
|
2
.github/workflows/configure.yml
vendored
2
.github/workflows/configure.yml
vendored
@ -35,7 +35,7 @@ jobs:
|
||||
|
||||
- runs-on: ubuntu-20.04
|
||||
arch: x64
|
||||
cmake: "3.27"
|
||||
cmake: "3.29"
|
||||
|
||||
- runs-on: macos-latest
|
||||
arch: x64
|
||||
|
2
.github/workflows/labeler.yml
vendored
2
.github/workflows/labeler.yml
vendored
@ -14,7 +14,7 @@ jobs:
|
||||
pull-requests: write
|
||||
steps:
|
||||
|
||||
- uses: actions/labeler@main
|
||||
- uses: actions/labeler@v4
|
||||
if: >
|
||||
github.event.pull_request.merged == true &&
|
||||
!startsWith(github.event.pull_request.title, 'chore(deps):') &&
|
||||
|
@ -12,13 +12,13 @@ endif()
|
||||
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
# The `cmake_minimum_required(VERSION 3.5...3.27)` syntax does not work with
|
||||
# The `cmake_minimum_required(VERSION 3.5...3.29)` syntax does not work with
|
||||
# some versions of VS that have a patched CMake 3.11. This forces us to emulate
|
||||
# the behavior using the following workaround:
|
||||
if(${CMAKE_VERSION} VERSION_LESS 3.27)
|
||||
if(${CMAKE_VERSION} VERSION_LESS 3.29)
|
||||
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
|
||||
else()
|
||||
cmake_policy(VERSION 3.27)
|
||||
cmake_policy(VERSION 3.29)
|
||||
endif()
|
||||
|
||||
if(_pybind11_cmp0148)
|
||||
@ -107,6 +107,8 @@ endif()
|
||||
option(PYBIND11_INSTALL "Install pybind11 header files?" ${PYBIND11_MASTER_PROJECT})
|
||||
option(PYBIND11_TEST "Build pybind11 test suite?" ${PYBIND11_MASTER_PROJECT})
|
||||
option(PYBIND11_NOPYTHON "Disable search for Python" OFF)
|
||||
option(PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION
|
||||
"To enforce that a handle_type_name<> specialization exists" OFF)
|
||||
option(PYBIND11_SIMPLE_GIL_MANAGEMENT
|
||||
"Use simpler GIL management logic that does not support disassociation" OFF)
|
||||
option(PYBIND11_NUMPY_1_ONLY
|
||||
@ -115,6 +117,9 @@ set(PYBIND11_INTERNALS_VERSION
|
||||
""
|
||||
CACHE STRING "Override the ABI version, may be used to enable the unstable ABI.")
|
||||
|
||||
if(PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION)
|
||||
add_compile_definitions(PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION)
|
||||
endif()
|
||||
if(PYBIND11_SIMPLE_GIL_MANAGEMENT)
|
||||
add_compile_definitions(PYBIND11_SIMPLE_GIL_MANAGEMENT)
|
||||
endif()
|
||||
|
@ -36,10 +36,10 @@ with everything stripped away that isn't relevant for binding
|
||||
generation. Without comments, the core header files only require ~4K
|
||||
lines of code and depend on Python (3.6+, or PyPy) and the C++
|
||||
standard library. This compact implementation was possible thanks to
|
||||
some of the new C++11 language features (specifically: tuples, lambda
|
||||
functions and variadic templates). Since its creation, this library has
|
||||
grown beyond Boost.Python in many ways, leading to dramatically simpler
|
||||
binding code in many common situations.
|
||||
some C++11 language features (specifically: tuples, lambda functions and
|
||||
variadic templates). Since its creation, this library has grown beyond
|
||||
Boost.Python in many ways, leading to dramatically simpler binding code in many
|
||||
common situations.
|
||||
|
||||
Tutorial and reference documentation is provided at
|
||||
`pybind11.readthedocs.io <https://pybind11.readthedocs.io/en/latest>`_.
|
||||
@ -71,6 +71,7 @@ pybind11 can map the following core C++ features to Python:
|
||||
- Internal references with correct reference counting
|
||||
- C++ classes with virtual (and pure virtual) methods can be extended
|
||||
in Python
|
||||
- Integrated NumPy support (NumPy 2 requires pybind11 2.12+)
|
||||
|
||||
Goodies
|
||||
-------
|
||||
|
@ -18,7 +18,7 @@ information, see :doc:`/compiling`.
|
||||
|
||||
.. code-block:: cmake
|
||||
|
||||
cmake_minimum_required(VERSION 3.5...3.27)
|
||||
cmake_minimum_required(VERSION 3.5...3.29)
|
||||
project(example)
|
||||
|
||||
find_package(pybind11 REQUIRED) # or `add_subdirectory(pybind11)`
|
||||
|
@ -15,9 +15,183 @@ IN DEVELOPMENT
|
||||
|
||||
Changes will be summarized here periodically.
|
||||
|
||||
Version 2.12.0 (March 27, 2025)
|
||||
-------------------------------
|
||||
|
||||
New Features:
|
||||
|
||||
* ``pybind11`` now supports compiling for
|
||||
`NumPy 2 <https://numpy.org/devdocs/numpy_2_0_migration_guide.html>`_. Most
|
||||
code shouldn't change (see :ref:`upgrade-guide-2.12` for details). However,
|
||||
if you experience issues you can define ``PYBIND11_NUMPY_1_ONLY`` to disable
|
||||
the new support for now, but this will be removed in the future.
|
||||
`#5050 <https://github.com/pybind/pybind11/pull/5050>`_
|
||||
|
||||
* ``pybind11/gil_safe_call_once.h`` was added (it needs to be included
|
||||
explicitly). The primary use case is GIL-safe initialization of C++
|
||||
``static`` variables.
|
||||
`#4877 <https://github.com/pybind/pybind11/pull/4877>`_
|
||||
|
||||
* Support move-only iterators in ``py::make_iterator``,
|
||||
``py::make_key_iterator``, ``py::make_value_iterator``.
|
||||
`#4834 <https://github.com/pybind/pybind11/pull/4834>`_
|
||||
|
||||
* Two simple ``py::set_error()`` functions were added and the documentation was
|
||||
updated accordingly. In particular, ``py::exception<>::operator()`` was
|
||||
deprecated (use one of the new functions instead). The documentation for
|
||||
``py::exception<>`` was further updated to not suggest code that may result
|
||||
in undefined behavior.
|
||||
`#4772 <https://github.com/pybind/pybind11/pull/4772>`_
|
||||
|
||||
Bug fixes:
|
||||
|
||||
* Removes potential for Undefined Behavior during process teardown.
|
||||
`#4897 <https://github.com/pybind/pybind11/pull/4897>`_
|
||||
|
||||
* Improve compatibility with the nvcc compiler (especially CUDA 12.1/12.2).
|
||||
`#4893 <https://github.com/pybind/pybind11/pull/4893>`_
|
||||
|
||||
* ``pybind11/numpy.h`` now imports NumPy's ``multiarray`` and ``_internal``
|
||||
submodules with paths depending on the installed version of NumPy (for
|
||||
compatibility with NumPy 2).
|
||||
`#4857 <https://github.com/pybind/pybind11/pull/4857>`_
|
||||
|
||||
* Builtins collections names in docstrings are now consistently rendered in
|
||||
lowercase (list, set, dict, tuple), in accordance with PEP 585.
|
||||
`#4833 <https://github.com/pybind/pybind11/pull/4833>`_
|
||||
|
||||
* Added ``py::typing::Iterator<T>``, ``py::typing::Iterable<T>``.
|
||||
`#4832 <https://github.com/pybind/pybind11/pull/4832>`_
|
||||
|
||||
* Render ``py::function`` as ``Callable`` in docstring.
|
||||
`#4829 <https://github.com/pybind/pybind11/pull/4829>`_
|
||||
|
||||
* Also bump ``PYBIND11_INTERNALS_VERSION`` for MSVC, which unlocks two new
|
||||
features without creating additional incompatibilities.
|
||||
`#4819 <https://github.com/pybind/pybind11/pull/4819>`_
|
||||
|
||||
* Guard against crashes/corruptions caused by modules built with different MSVC
|
||||
versions.
|
||||
`#4779 <https://github.com/pybind/pybind11/pull/4779>`_
|
||||
|
||||
* A long-standing bug in the handling of Python multiple inheritance was fixed.
|
||||
See PR #4762 for the rather complex details.
|
||||
`#4762 <https://github.com/pybind/pybind11/pull/4762>`_
|
||||
|
||||
* Fix ``bind_map`` with ``using`` declarations.
|
||||
`#4952 <https://github.com/pybind/pybind11/pull/4952>`_
|
||||
|
||||
* Qualify ``py::detail::concat`` usage to avoid ADL selecting one from
|
||||
somewhere else, such as modernjson's concat.
|
||||
`#4955 <https://github.com/pybind/pybind11/pull/4955>`_
|
||||
|
||||
* Use new PyCode API on Python 3.12+.
|
||||
`#4916 <https://github.com/pybind/pybind11/pull/4916>`_
|
||||
|
||||
* Minor cleanup from warnings reported by Clazy.
|
||||
`#4988 <https://github.com/pybind/pybind11/pull/4988>`_
|
||||
|
||||
* Remove typing and duplicate ``class_`` for ``KeysView``/``ValuesView``/``ItemsView``.
|
||||
`#4985 <https://github.com/pybind/pybind11/pull/4985>`_
|
||||
|
||||
* Use ``PyObject_VisitManagedDict()`` and ``PyObject_ClearManagedDict()`` on Python 3.13 and newer.
|
||||
`#4973 <https://github.com/pybind/pybind11/pull/4973>`_
|
||||
|
||||
* Update ``make_static_property_type()`` to make it compatible with Python 3.13.
|
||||
`#4971 <https://github.com/pybind/pybind11/pull/4971>`_
|
||||
|
||||
.. fix(types)
|
||||
|
||||
* Render typed iterators for ``make_iterator``, ``make_key_iterator``,
|
||||
``make_value_iterator``.
|
||||
`#4876 <https://github.com/pybind/pybind11/pull/4876>`_
|
||||
|
||||
* Add several missing type name specializations.
|
||||
`#5073 <https://github.com/pybind/pybind11/pull/5073>`_
|
||||
|
||||
* Change docstring render for ``py::buffer``, ``py::sequence`` and
|
||||
``py::handle`` (to ``Buffer``, ``Sequence``, ``Any``).
|
||||
`#4831 <https://github.com/pybind/pybind11/pull/4831>`_
|
||||
|
||||
* Fixed ``base_enum.__str__`` docstring.
|
||||
`#4827 <https://github.com/pybind/pybind11/pull/4827>`_
|
||||
|
||||
* Enforce single line docstring signatures.
|
||||
`#4735 <https://github.com/pybind/pybind11/pull/4735>`_
|
||||
|
||||
* Special 'typed' wrappers now available in ``typing.h`` to annotate tuple, dict,
|
||||
list, set, and function.
|
||||
`#4259 <https://github.com/pybind/pybind11/pull/4259>`_
|
||||
|
||||
* Create ``handle_type_name`` specialization to type-hint variable length tuples.
|
||||
`#5051 <https://github.com/pybind/pybind11/pull/5051>`_
|
||||
|
||||
.. fix(build)
|
||||
|
||||
* Setting ``PYBIND11_FINDPYTHON`` to OFF will force the old FindPythonLibs mechanism to be used.
|
||||
`#5042 <https://github.com/pybind/pybind11/pull/5042>`_
|
||||
|
||||
* Skip empty ``PYBIND11_PYTHON_EXECUTABLE_LAST`` for the first cmake run.
|
||||
`#4856 <https://github.com/pybind/pybind11/pull/4856>`_
|
||||
|
||||
* Fix FindPython mode exports & avoid ``pkg_resources`` if
|
||||
``importlib.metadata`` available.
|
||||
`#4941 <https://github.com/pybind/pybind11/pull/4941>`_
|
||||
|
||||
* ``Python_ADDITIONAL_VERSIONS`` (classic search) now includes 3.12.
|
||||
`#4909 <https://github.com/pybind/pybind11/pull/4909>`_
|
||||
|
||||
* ``pybind11.pc`` is now relocatable by default as long as install destinations
|
||||
are not absolute paths.
|
||||
`#4830 <https://github.com/pybind/pybind11/pull/4830>`_
|
||||
|
||||
* Correctly detect CMake FindPython removal when used as a subdirectory.
|
||||
`#4806 <https://github.com/pybind/pybind11/pull/4806>`_
|
||||
|
||||
* Don't require the libs component on CMake 3.18+ when using
|
||||
PYBIND11_FINDPYTHON (fixes manylinux builds).
|
||||
`#4805 <https://github.com/pybind/pybind11/pull/4805>`_
|
||||
|
||||
* ``pybind11_strip`` is no longer automatically applied when
|
||||
``CMAKE_BUILD_TYPE`` is unset.
|
||||
`#4780 <https://github.com/pybind/pybind11/pull/4780>`_
|
||||
|
||||
* Support ``DEBUG_POSFIX`` correctly for debug builds.
|
||||
`#4761 <https://github.com/pybind/pybind11/pull/4761>`_
|
||||
|
||||
* Hardcode lto/thin lto for Emscripten cross-compiles.
|
||||
`#4642 <https://github.com/pybind/pybind11/pull/4642>`_
|
||||
|
||||
* Upgrade maximum supported CMake version to 3.27 to fix CMP0148 warnings.
|
||||
`#4786 <https://github.com/pybind/pybind11/pull/4786>`_
|
||||
|
||||
Documentation:
|
||||
|
||||
* Small fix to grammar in ``functions.rst``.
|
||||
`#4791 <https://github.com/pybind/pybind11/pull/4791>`_
|
||||
|
||||
* Remove upper bound in example pyproject.toml for setuptools.
|
||||
`#4774 <https://github.com/pybind/pybind11/pull/4774>`_
|
||||
|
||||
CI:
|
||||
|
||||
* CI: Update NVHPC to 23.5 and Ubuntu 20.04.
|
||||
`#4764 <https://github.com/pybind/pybind11/pull/4764>`_
|
||||
|
||||
* Test on PyPy 3.10.
|
||||
`#4714 <https://github.com/pybind/pybind11/pull/4714>`_
|
||||
|
||||
Other:
|
||||
|
||||
* Use Ruff formatter instead of Black.
|
||||
`#4912 <https://github.com/pybind/pybind11/pull/4912>`_
|
||||
|
||||
* An ``assert()`` was added to help Coverty avoid generating a false positive.
|
||||
`#4817 <https://github.com/pybind/pybind11/pull/4817>`_
|
||||
|
||||
|
||||
Version 2.11.1 (July 17, 2023)
|
||||
-----------------------------
|
||||
------------------------------
|
||||
|
||||
Changes:
|
||||
|
||||
@ -32,7 +206,7 @@ Changes:
|
||||
|
||||
|
||||
Version 2.11.0 (July 14, 2023)
|
||||
-----------------------------
|
||||
------------------------------
|
||||
|
||||
New features:
|
||||
|
||||
|
@ -241,7 +241,7 @@ extension module can be created with just a few lines of code:
|
||||
|
||||
.. code-block:: cmake
|
||||
|
||||
cmake_minimum_required(VERSION 3.5...3.27)
|
||||
cmake_minimum_required(VERSION 3.5...3.29)
|
||||
project(example LANGUAGES CXX)
|
||||
|
||||
add_subdirectory(pybind11)
|
||||
@ -498,7 +498,7 @@ You can use these targets to build complex applications. For example, the
|
||||
|
||||
.. code-block:: cmake
|
||||
|
||||
cmake_minimum_required(VERSION 3.5...3.27)
|
||||
cmake_minimum_required(VERSION 3.5...3.29)
|
||||
project(example LANGUAGES CXX)
|
||||
|
||||
find_package(pybind11 REQUIRED) # or add_subdirectory(pybind11)
|
||||
@ -556,7 +556,7 @@ information about usage in C++, see :doc:`/advanced/embedding`.
|
||||
|
||||
.. code-block:: cmake
|
||||
|
||||
cmake_minimum_required(VERSION 3.5...3.27)
|
||||
cmake_minimum_required(VERSION 3.5...3.29)
|
||||
project(example LANGUAGES CXX)
|
||||
|
||||
find_package(pybind11 REQUIRED) # or add_subdirectory(pybind11)
|
||||
|
@ -36,19 +36,19 @@ If you don't have nox, you should either use ``pipx run nox`` instead, or use
|
||||
|
||||
- Run ``nox -s tests_packaging`` to ensure this was done correctly.
|
||||
|
||||
- Ensure that all the information in ``setup.cfg`` is up-to-date, like
|
||||
- Ensure that all the information in ``setup.cfg`` is up-to-date, like
|
||||
supported Python versions.
|
||||
|
||||
- Add release date in ``docs/changelog.rst`` and integrate the output of
|
||||
``nox -s make_changelog``.
|
||||
- Add release date in ``docs/changelog.rst`` and integrate the output of
|
||||
``nox -s make_changelog``.
|
||||
|
||||
- Note that the ``make_changelog`` command inspects
|
||||
`needs changelog <https://github.com/pybind/pybind11/pulls?q=is%3Apr+is%3Aclosed+label%3A%22needs+changelog%22>`_.
|
||||
- Note that the ``nox -s make_changelog`` command inspects
|
||||
`needs changelog <https://github.com/pybind/pybind11/pulls?q=is%3Apr+is%3Aclosed+label%3A%22needs+changelog%22>`_.
|
||||
|
||||
- Manually clear the ``needs changelog`` labels using the GitHub web
|
||||
interface (very easy: start by clicking the link above).
|
||||
- Manually clear the ``needs changelog`` labels using the GitHub web
|
||||
interface (very easy: start by clicking the link above).
|
||||
|
||||
- ``git add`` and ``git commit``, ``git push``. **Ensure CI passes**. (If it
|
||||
- ``git add`` and ``git commit``, ``git push``. **Ensure CI passes**. (If it
|
||||
fails due to a known flake issue, either ignore or restart CI.)
|
||||
|
||||
- Add a release branch if this is a new MINOR version, or update the existing
|
||||
|
@ -8,6 +8,34 @@ to a new version. But it goes into more detail. This includes things like
|
||||
deprecated APIs and their replacements, build system changes, general code
|
||||
modernization and other useful information.
|
||||
|
||||
.. _upgrade-guide-2.12:
|
||||
|
||||
v2.12
|
||||
=====
|
||||
|
||||
NumPy support has been upgraded to support the 2.x series too. The two relevant
|
||||
changes are that:
|
||||
|
||||
* ``dtype.flags()`` is now a ``uint64`` and ``dtype.alignment()`` an
|
||||
``ssize_t`` (and NumPy may return an larger than integer value for
|
||||
``itemsize()`` in NumPy 2.x).
|
||||
|
||||
* The long deprecated NumPy function ``PyArray_GetArrayParamsFromObject``
|
||||
function is not available anymore.
|
||||
|
||||
Due to NumPy changes, you may experience difficulties updating to NumPy 2.
|
||||
Please see the [NumPy 2 migration guide](https://numpy.org/devdocs/numpy_2_0_migration_guide.html) for details.
|
||||
For example, a more direct change could be that the default integer ``"int_"``
|
||||
(and ``"uint"``) is now ``ssize_t`` and not ``long`` (affects 64bit windows).
|
||||
|
||||
If you want to only support NumPy 1.x for now and are having problems due to
|
||||
the two internal changes listed above, you can define
|
||||
``PYBIND11_NUMPY_1_ONLY`` to disable the new support for now. Make sure you
|
||||
define this on all pybind11 compile units, since it could be a source of ODR
|
||||
violations if used inconsistently. This option will be removed in the future,
|
||||
so adapting your code is highly recommended.
|
||||
|
||||
|
||||
.. _upgrade-guide-2.11:
|
||||
|
||||
v2.11
|
||||
|
@ -672,8 +672,9 @@ public:
|
||||
return cast(*src, policy, parent);
|
||||
}
|
||||
|
||||
static constexpr auto name
|
||||
= const_name("tuple[") + concat(make_caster<Ts>::name...) + const_name("]");
|
||||
static constexpr auto name = const_name("tuple[")
|
||||
+ ::pybind11::detail::concat(make_caster<Ts>::name...)
|
||||
+ const_name("]");
|
||||
|
||||
template <typename T>
|
||||
using cast_op_type = type;
|
||||
@ -881,10 +882,53 @@ struct is_holder_type
|
||||
template <typename base, typename deleter>
|
||||
struct is_holder_type<base, std::unique_ptr<base, deleter>> : std::true_type {};
|
||||
|
||||
#ifdef PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION // See PR #4888
|
||||
|
||||
// This leads to compilation errors if a specialization is missing.
|
||||
template <typename T>
|
||||
struct handle_type_name;
|
||||
|
||||
#else
|
||||
|
||||
template <typename T>
|
||||
struct handle_type_name {
|
||||
static constexpr auto name = const_name<T>();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
template <>
|
||||
struct handle_type_name<object> {
|
||||
static constexpr auto name = const_name("object");
|
||||
};
|
||||
template <>
|
||||
struct handle_type_name<list> {
|
||||
static constexpr auto name = const_name("list");
|
||||
};
|
||||
template <>
|
||||
struct handle_type_name<dict> {
|
||||
static constexpr auto name = const_name("dict");
|
||||
};
|
||||
template <>
|
||||
struct handle_type_name<anyset> {
|
||||
static constexpr auto name = const_name("Union[set, frozenset]");
|
||||
};
|
||||
template <>
|
||||
struct handle_type_name<set> {
|
||||
static constexpr auto name = const_name("set");
|
||||
};
|
||||
template <>
|
||||
struct handle_type_name<frozenset> {
|
||||
static constexpr auto name = const_name("frozenset");
|
||||
};
|
||||
template <>
|
||||
struct handle_type_name<str> {
|
||||
static constexpr auto name = const_name("str");
|
||||
};
|
||||
template <>
|
||||
struct handle_type_name<tuple> {
|
||||
static constexpr auto name = const_name("tuple");
|
||||
};
|
||||
template <>
|
||||
struct handle_type_name<bool_> {
|
||||
static constexpr auto name = const_name("bool");
|
||||
@ -930,6 +974,34 @@ struct handle_type_name<sequence> {
|
||||
static constexpr auto name = const_name("Sequence");
|
||||
};
|
||||
template <>
|
||||
struct handle_type_name<bytearray> {
|
||||
static constexpr auto name = const_name("bytearray");
|
||||
};
|
||||
template <>
|
||||
struct handle_type_name<memoryview> {
|
||||
static constexpr auto name = const_name("memoryview");
|
||||
};
|
||||
template <>
|
||||
struct handle_type_name<slice> {
|
||||
static constexpr auto name = const_name("slice");
|
||||
};
|
||||
template <>
|
||||
struct handle_type_name<type> {
|
||||
static constexpr auto name = const_name("type");
|
||||
};
|
||||
template <>
|
||||
struct handle_type_name<capsule> {
|
||||
static constexpr auto name = const_name("capsule");
|
||||
};
|
||||
template <>
|
||||
struct handle_type_name<ellipsis> {
|
||||
static constexpr auto name = const_name("ellipsis");
|
||||
};
|
||||
template <>
|
||||
struct handle_type_name<weakref> {
|
||||
static constexpr auto name = const_name("weakref");
|
||||
};
|
||||
template <>
|
||||
struct handle_type_name<args> {
|
||||
static constexpr auto name = const_name("*args");
|
||||
};
|
||||
@ -937,6 +1009,30 @@ template <>
|
||||
struct handle_type_name<kwargs> {
|
||||
static constexpr auto name = const_name("**kwargs");
|
||||
};
|
||||
template <>
|
||||
struct handle_type_name<obj_attr_accessor> {
|
||||
static constexpr auto name = const_name<obj_attr_accessor>();
|
||||
};
|
||||
template <>
|
||||
struct handle_type_name<str_attr_accessor> {
|
||||
static constexpr auto name = const_name<str_attr_accessor>();
|
||||
};
|
||||
template <>
|
||||
struct handle_type_name<item_accessor> {
|
||||
static constexpr auto name = const_name<item_accessor>();
|
||||
};
|
||||
template <>
|
||||
struct handle_type_name<sequence_accessor> {
|
||||
static constexpr auto name = const_name<sequence_accessor>();
|
||||
};
|
||||
template <>
|
||||
struct handle_type_name<list_accessor> {
|
||||
static constexpr auto name = const_name<list_accessor>();
|
||||
};
|
||||
template <>
|
||||
struct handle_type_name<tuple_accessor> {
|
||||
static constexpr auto name = const_name<tuple_accessor>();
|
||||
};
|
||||
|
||||
template <typename type>
|
||||
struct pyobject_caster {
|
||||
@ -1474,7 +1570,8 @@ public:
|
||||
static_assert(args_pos == -1 || args_pos == constexpr_first<argument_is_args, Args...>(),
|
||||
"py::args cannot be specified more than once");
|
||||
|
||||
static constexpr auto arg_names = concat(type_descr(make_caster<Args>::name)...);
|
||||
static constexpr auto arg_names
|
||||
= ::pybind11::detail::concat(type_descr(make_caster<Args>::name)...);
|
||||
|
||||
bool load_args(function_call &call) { return load_impl_sequence(call, indices{}); }
|
||||
|
||||
|
@ -10,12 +10,12 @@
|
||||
#pragma once
|
||||
|
||||
#define PYBIND11_VERSION_MAJOR 2
|
||||
#define PYBIND11_VERSION_MINOR 12
|
||||
#define PYBIND11_VERSION_MINOR 13
|
||||
#define PYBIND11_VERSION_PATCH 0.dev1
|
||||
|
||||
// Similar to Python's convention: https://docs.python.org/3/c-api/apiabiversion.html
|
||||
// Additional convention: 0xD = dev
|
||||
#define PYBIND11_VERSION_HEX 0x020C00D1
|
||||
#define PYBIND11_VERSION_HEX 0x020D00D1
|
||||
|
||||
// Define some generic pybind11 helper macros for warning management.
|
||||
//
|
||||
|
@ -1201,13 +1201,17 @@ protected:
|
||||
static Constructor make_move_constructor(...) { return nullptr; }
|
||||
};
|
||||
|
||||
inline std::string quote_cpp_type_name(const std::string &cpp_type_name) {
|
||||
return cpp_type_name; // No-op for now. See PR #4888
|
||||
}
|
||||
|
||||
PYBIND11_NOINLINE std::string type_info_description(const std::type_info &ti) {
|
||||
if (auto *type_data = get_type_info(ti)) {
|
||||
handle th((PyObject *) type_data->type);
|
||||
return th.attr("__module__").cast<std::string>() + '.'
|
||||
+ th.attr("__qualname__").cast<std::string>();
|
||||
}
|
||||
return clean_type_id(ti.name());
|
||||
return quote_cpp_type_name(clean_type_id(ti.name()));
|
||||
}
|
||||
|
||||
PYBIND11_NAMESPACE_END(detail)
|
||||
|
@ -70,7 +70,7 @@ struct eigen_tensor_helper<Eigen::Tensor<Scalar_, NumIndices_, Options_, IndexTy
|
||||
|
||||
template <size_t... Is>
|
||||
struct helper<index_sequence<Is...>> {
|
||||
static constexpr auto value = concat(const_name(((void) Is, "?"))...);
|
||||
static constexpr auto value = ::pybind11::detail::concat(const_name(((void) Is, "?"))...);
|
||||
};
|
||||
|
||||
static constexpr auto dimensions_descriptor
|
||||
@ -104,7 +104,8 @@ struct eigen_tensor_helper<
|
||||
return get_shape() == shape;
|
||||
}
|
||||
|
||||
static constexpr auto dimensions_descriptor = concat(const_name<Indices>()...);
|
||||
static constexpr auto dimensions_descriptor
|
||||
= ::pybind11::detail::concat(const_name<Indices>()...);
|
||||
|
||||
template <typename... Args>
|
||||
static Type *alloc(Args &&...args) {
|
||||
|
@ -128,7 +128,8 @@ public:
|
||||
}
|
||||
|
||||
PYBIND11_TYPE_CASTER(type,
|
||||
const_name("Callable[[") + concat(make_caster<Args>::name...)
|
||||
const_name("Callable[[")
|
||||
+ ::pybind11::detail::concat(make_caster<Args>::name...)
|
||||
+ const_name("], ") + make_caster<retval_type>::name
|
||||
+ const_name("]"));
|
||||
};
|
||||
|
@ -46,6 +46,7 @@ PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
||||
|
||||
PYBIND11_WARNING_DISABLE_MSVC(4127)
|
||||
|
||||
class dtype; // Forward declaration
|
||||
class array; // Forward declaration
|
||||
|
||||
template <typename>
|
||||
@ -53,6 +54,11 @@ struct numpy_scalar; // Forward declaration
|
||||
|
||||
PYBIND11_NAMESPACE_BEGIN(detail)
|
||||
|
||||
template <>
|
||||
struct handle_type_name<dtype> {
|
||||
static constexpr auto name = const_name("numpy.dtype");
|
||||
};
|
||||
|
||||
template <>
|
||||
struct handle_type_name<array> {
|
||||
static constexpr auto name = const_name("numpy.ndarray");
|
||||
@ -538,7 +544,7 @@ struct array_info<std::array<T, N>> {
|
||||
}
|
||||
|
||||
static constexpr auto extents = const_name<array_info<T>::is_array>(
|
||||
concat(const_name<N>(), array_info<T>::extents), const_name<N>());
|
||||
::pybind11::detail::concat(const_name<N>(), array_info<T>::extents), const_name<N>());
|
||||
};
|
||||
// For numpy we have special handling for arrays of characters, so we don't include
|
||||
// the size in the array extents.
|
||||
|
@ -492,9 +492,7 @@ protected:
|
||||
signature += rec->scope.attr("__module__").cast<std::string>() + "."
|
||||
+ rec->scope.attr("__qualname__").cast<std::string>();
|
||||
} else {
|
||||
std::string tname(t->name());
|
||||
detail::clean_type_id(tname);
|
||||
signature += tname;
|
||||
signature += detail::quote_cpp_type_name(detail::clean_type_id(t->name()));
|
||||
}
|
||||
} else {
|
||||
signature += c;
|
||||
@ -1192,6 +1190,15 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
PYBIND11_NAMESPACE_BEGIN(detail)
|
||||
|
||||
template <>
|
||||
struct handle_type_name<cpp_function> {
|
||||
static constexpr auto name = const_name("Callable");
|
||||
};
|
||||
|
||||
PYBIND11_NAMESPACE_END(detail)
|
||||
|
||||
/// Wrapper for Python extension modules
|
||||
class module_ : public object {
|
||||
public:
|
||||
@ -1319,6 +1326,15 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
PYBIND11_NAMESPACE_BEGIN(detail)
|
||||
|
||||
template <>
|
||||
struct handle_type_name<module_> {
|
||||
static constexpr auto name = const_name("module");
|
||||
};
|
||||
|
||||
PYBIND11_NAMESPACE_END(detail)
|
||||
|
||||
// When inside a namespace (or anywhere as long as it's not the first item on a line),
|
||||
// C++20 allows "module" to be used. This is provided for backward compatibility, and for
|
||||
// simplicity, if someone wants to use py::module for example, that is perfectly safe.
|
||||
@ -2611,6 +2627,11 @@ public:
|
||||
|
||||
PYBIND11_NAMESPACE_BEGIN(detail)
|
||||
|
||||
template <>
|
||||
struct handle_type_name<exception<void>> {
|
||||
static constexpr auto name = const_name("Exception");
|
||||
};
|
||||
|
||||
// Helper function for register_exception and register_local_exception
|
||||
template <typename CppException>
|
||||
exception<CppException> &
|
||||
|
@ -59,6 +59,7 @@ struct sequence_item;
|
||||
struct list_item;
|
||||
struct tuple_item;
|
||||
} // namespace accessor_policies
|
||||
// PLEASE KEEP handle_type_name SPECIALIZATIONS IN SYNC.
|
||||
using obj_attr_accessor = accessor<accessor_policies::obj_attr>;
|
||||
using str_attr_accessor = accessor<accessor_policies::str_attr>;
|
||||
using item_accessor = accessor<accessor_policies::generic_item>;
|
||||
|
@ -421,7 +421,8 @@ struct variant_caster<V<Ts...>> {
|
||||
|
||||
using Type = V<Ts...>;
|
||||
PYBIND11_TYPE_CASTER(Type,
|
||||
const_name("Union[") + detail::concat(make_caster<Ts>::name...)
|
||||
const_name("Union[")
|
||||
+ ::pybind11::detail::concat(make_caster<Ts>::name...)
|
||||
+ const_name("]"));
|
||||
};
|
||||
|
||||
|
@ -69,8 +69,9 @@ PYBIND11_NAMESPACE_BEGIN(detail)
|
||||
|
||||
template <typename... Types>
|
||||
struct handle_type_name<typing::Tuple<Types...>> {
|
||||
static constexpr auto name
|
||||
= const_name("tuple[") + concat(make_caster<Types>::name...) + const_name("]");
|
||||
static constexpr auto name = const_name("tuple[")
|
||||
+ ::pybind11::detail::concat(make_caster<Types>::name...)
|
||||
+ const_name("]");
|
||||
};
|
||||
|
||||
template <>
|
||||
@ -115,9 +116,9 @@ struct handle_type_name<typing::Iterator<T>> {
|
||||
template <typename Return, typename... Args>
|
||||
struct handle_type_name<typing::Callable<Return(Args...)>> {
|
||||
using retval_type = conditional_t<std::is_same<Return, void>::value, void_type, Return>;
|
||||
static constexpr auto name = const_name("Callable[[") + concat(make_caster<Args>::name...)
|
||||
+ const_name("], ") + make_caster<retval_type>::name
|
||||
+ const_name("]");
|
||||
static constexpr auto name
|
||||
= const_name("Callable[[") + ::pybind11::detail::concat(make_caster<Args>::name...)
|
||||
+ const_name("], ") + make_caster<retval_type>::name + const_name("]");
|
||||
};
|
||||
|
||||
PYBIND11_NAMESPACE_END(detail)
|
||||
|
@ -8,5 +8,5 @@ def _to_int(s: str) -> Union[int, str]:
|
||||
return s
|
||||
|
||||
|
||||
__version__ = "2.12.0.dev1"
|
||||
__version__ = "2.13.0.dev1"
|
||||
version_info = tuple(_to_int(s) for s in __version__.split("."))
|
||||
|
@ -7,13 +7,13 @@
|
||||
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
# The `cmake_minimum_required(VERSION 3.5...3.27)` syntax does not work with
|
||||
# The `cmake_minimum_required(VERSION 3.5...3.29)` syntax does not work with
|
||||
# some versions of VS that have a patched CMake 3.11. This forces us to emulate
|
||||
# the behavior using the following workaround:
|
||||
if(${CMAKE_VERSION} VERSION_LESS 3.27)
|
||||
if(${CMAKE_VERSION} VERSION_LESS 3.29)
|
||||
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
|
||||
else()
|
||||
cmake_policy(VERSION 3.27)
|
||||
cmake_policy(VERSION 3.29)
|
||||
endif()
|
||||
|
||||
# Filter out items; print an optional message if any items filtered. This ignores extensions.
|
||||
|
@ -1,12 +1,12 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
# The `cmake_minimum_required(VERSION 3.5...3.27)` syntax does not work with
|
||||
# The `cmake_minimum_required(VERSION 3.5...3.29)` syntax does not work with
|
||||
# some versions of VS that have a patched CMake 3.11. This forces us to emulate
|
||||
# the behavior using the following workaround:
|
||||
if(${CMAKE_VERSION} VERSION_LESS 3.27)
|
||||
if(${CMAKE_VERSION} VERSION_LESS 3.29)
|
||||
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
|
||||
else()
|
||||
cmake_policy(VERSION 3.27)
|
||||
cmake_policy(VERSION 3.29)
|
||||
endif()
|
||||
|
||||
project(test_installed_embed CXX)
|
||||
|
@ -1,13 +1,13 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
project(test_installed_module CXX)
|
||||
|
||||
# The `cmake_minimum_required(VERSION 3.5...3.27)` syntax does not work with
|
||||
# The `cmake_minimum_required(VERSION 3.5...3.29)` syntax does not work with
|
||||
# some versions of VS that have a patched CMake 3.11. This forces us to emulate
|
||||
# the behavior using the following workaround:
|
||||
if(${CMAKE_VERSION} VERSION_LESS 3.27)
|
||||
if(${CMAKE_VERSION} VERSION_LESS 3.29)
|
||||
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
|
||||
else()
|
||||
cmake_policy(VERSION 3.27)
|
||||
cmake_policy(VERSION 3.29)
|
||||
endif()
|
||||
|
||||
project(test_installed_function CXX)
|
||||
|
@ -1,12 +1,12 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
# The `cmake_minimum_required(VERSION 3.5...3.27)` syntax does not work with
|
||||
# The `cmake_minimum_required(VERSION 3.5...3.29)` syntax does not work with
|
||||
# some versions of VS that have a patched CMake 3.11. This forces us to emulate
|
||||
# the behavior using the following workaround:
|
||||
if(${CMAKE_VERSION} VERSION_LESS 3.27)
|
||||
if(${CMAKE_VERSION} VERSION_LESS 3.29)
|
||||
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
|
||||
else()
|
||||
cmake_policy(VERSION 3.27)
|
||||
cmake_policy(VERSION 3.29)
|
||||
endif()
|
||||
|
||||
project(test_installed_target CXX)
|
||||
|
@ -1,12 +1,12 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
# The `cmake_minimum_required(VERSION 3.5...3.27)` syntax does not work with
|
||||
# The `cmake_minimum_required(VERSION 3.5...3.29)` syntax does not work with
|
||||
# some versions of VS that have a patched CMake 3.11. This forces us to emulate
|
||||
# the behavior using the following workaround:
|
||||
if(${CMAKE_VERSION} VERSION_LESS 3.27)
|
||||
if(${CMAKE_VERSION} VERSION_LESS 3.29)
|
||||
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
|
||||
else()
|
||||
cmake_policy(VERSION 3.27)
|
||||
cmake_policy(VERSION 3.29)
|
||||
endif()
|
||||
|
||||
project(test_subdirectory_embed CXX)
|
||||
|
@ -1,12 +1,12 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
# The `cmake_minimum_required(VERSION 3.5...3.27)` syntax does not work with
|
||||
# The `cmake_minimum_required(VERSION 3.5...3.29)` syntax does not work with
|
||||
# some versions of VS that have a patched CMake 3.11. This forces us to emulate
|
||||
# the behavior using the following workaround:
|
||||
if(${CMAKE_VERSION} VERSION_LESS 3.27)
|
||||
if(${CMAKE_VERSION} VERSION_LESS 3.29)
|
||||
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
|
||||
else()
|
||||
cmake_policy(VERSION 3.27)
|
||||
cmake_policy(VERSION 3.29)
|
||||
endif()
|
||||
|
||||
project(test_subdirectory_function CXX)
|
||||
|
@ -1,12 +1,12 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
# The `cmake_minimum_required(VERSION 3.5...3.27)` syntax does not work with
|
||||
# The `cmake_minimum_required(VERSION 3.5...3.29)` syntax does not work with
|
||||
# some versions of VS that have a patched CMake 3.11. This forces us to emulate
|
||||
# the behavior using the following workaround:
|
||||
if(${CMAKE_VERSION} VERSION_LESS 3.27)
|
||||
if(${CMAKE_VERSION} VERSION_LESS 3.29)
|
||||
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
|
||||
else()
|
||||
cmake_policy(VERSION 3.27)
|
||||
cmake_policy(VERSION 3.29)
|
||||
endif()
|
||||
|
||||
project(test_subdirectory_target CXX)
|
||||
|
@ -134,6 +134,16 @@ struct type_caster<other_lib::MyType> : public other_lib::my_caster {};
|
||||
} // namespace detail
|
||||
} // namespace PYBIND11_NAMESPACE
|
||||
|
||||
// This simply is required to compile
|
||||
namespace ADL_issue {
|
||||
template <typename OutStringType = std::string, typename... Args>
|
||||
OutStringType concat(Args &&...) {
|
||||
return OutStringType();
|
||||
}
|
||||
|
||||
struct test {};
|
||||
} // namespace ADL_issue
|
||||
|
||||
TEST_SUBMODULE(custom_type_casters, m) {
|
||||
// test_custom_type_casters
|
||||
|
||||
@ -206,4 +216,6 @@ TEST_SUBMODULE(custom_type_casters, m) {
|
||||
py::return_value_policy::reference);
|
||||
|
||||
m.def("other_lib_type", [](other_lib::MyType x) { return x; });
|
||||
|
||||
m.def("_adl_issue", [](const ADL_issue::test &) {});
|
||||
}
|
||||
|
@ -382,4 +382,7 @@ TEST_SUBMODULE(exceptions, m) {
|
||||
// function returns None instead of int, should give a useful error message
|
||||
fn().cast<int>();
|
||||
});
|
||||
|
||||
// m.def("pass_exception_void", [](const py::exception<void>&) {}); // Does not compile.
|
||||
m.def("return_exception_void", []() { return py::exception<void>(); });
|
||||
}
|
||||
|
@ -424,3 +424,9 @@ def test_fn_cast_int_exception():
|
||||
assert str(excinfo.value).startswith(
|
||||
"Unable to cast Python instance of type <class 'NoneType'> to C++ type"
|
||||
)
|
||||
|
||||
|
||||
def test_return_exception_void():
|
||||
with pytest.raises(TypeError) as excinfo:
|
||||
m.return_exception_void()
|
||||
assert "Exception" in str(excinfo.value)
|
||||
|
@ -41,6 +41,15 @@ class float_ : public py::object {
|
||||
};
|
||||
} // namespace external
|
||||
|
||||
namespace pybind11 {
|
||||
namespace detail {
|
||||
template <>
|
||||
struct handle_type_name<external::float_> {
|
||||
static constexpr auto name = const_name("float");
|
||||
};
|
||||
} // namespace detail
|
||||
} // namespace pybind11
|
||||
|
||||
namespace implicit_conversion_from_0_to_handle {
|
||||
// Uncomment to trigger compiler error. Note: Before PR #4008 this used to compile successfully.
|
||||
// void expected_to_trigger_compiler_error() { py::handle(0); }
|
||||
|
@ -121,7 +121,7 @@ def test_set(capture, doc):
|
||||
assert m.anyset_contains({"foo"}, "foo")
|
||||
|
||||
assert doc(m.get_set) == "get_set() -> set"
|
||||
assert doc(m.print_anyset) == "print_anyset(arg0: anyset) -> None"
|
||||
assert doc(m.print_anyset) == "print_anyset(arg0: Union[set, frozenset]) -> None"
|
||||
|
||||
|
||||
def test_frozenset(capture, doc):
|
||||
|
@ -67,9 +67,11 @@ for issue in issues:
|
||||
for cat, msgs in cats.items():
|
||||
if msgs:
|
||||
desc = cats_descr[cat]
|
||||
print(f"[bold]{desc}:\n" if desc else "")
|
||||
print(f"[bold]{desc}:" if desc else f".. {cat}")
|
||||
print()
|
||||
for msg in msgs:
|
||||
print(Syntax(msg, "rst", theme="ansi_light", word_wrap=True))
|
||||
print()
|
||||
print()
|
||||
|
||||
if missing:
|
||||
|
Loading…
Reference in New Issue
Block a user