From d58699c9ab9d20010b15aa38382ad517a8280179 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Fri, 24 Sep 2021 17:47:03 -0400 Subject: [PATCH 1/6] fix(cmake): reduce chance for variable collision (#3302) --- tools/pybind11NewTools.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/pybind11NewTools.cmake b/tools/pybind11NewTools.cmake index b93f9145e..0a7b84706 100644 --- a/tools/pybind11NewTools.cmake +++ b/tools/pybind11NewTools.cmake @@ -82,11 +82,11 @@ if(NOT DEFINED ${_Python}_EXECUTABLE) endif() -if(NOT ${_Python}_EXECUTABLE STREQUAL PYTHON_EXECUTABLE_LAST) +if(NOT ${_Python}_EXECUTABLE STREQUAL PYBIND11_PYTHON_EXECUTABLE_LAST) # Detect changes to the Python version/binary in subsequent CMake runs, and refresh config if needed unset(PYTHON_IS_DEBUG CACHE) unset(PYTHON_MODULE_EXTENSION CACHE) - set(PYTHON_EXECUTABLE_LAST + set(PYBIND11_PYTHON_EXECUTABLE_LAST "${${_Python}_EXECUTABLE}" CACHE INTERNAL "Python executable during the last CMake run") endif() From 6bce3bd72e8d0838cdb1586abd6d3cfb9c598a8f Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Fri, 24 Sep 2021 23:48:38 -0400 Subject: [PATCH 2/6] docs: update CHANGELOG (#3304) --- docs/changelog.rst | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 6bdf6a6e4..04e2714fc 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -38,21 +38,42 @@ New features: * Implemented ``reshape`` on arrays. `#984 `_ +* Enable defining custom ``__new__`` methods on classes by fixing bug + preventing overriding methods if they have non-pybind11 siblings. + `#3265 `_ + +* Add ``make_value_iterator()``, and fix ``make_key_iterator()`` to return + references instead of copies. + `#3293 `_ + +* ``pybind11::custom_type_setup`` was added, for customizing the + ``PyHeapTypeObject`` corresponding to a class, which may be useful for + enabling garbage collection support, among other things. + `#3287 `_ + + Changes: * Set ``__file__`` constant when running ``eval_file`` in an embedded interpreter. `#3233 `_ +* Python objects and (C++17) ``std::optional`` now accepted in ``py::slice`` + constructor. + `#1101 `_ + * The pybind11 proxy types ``str``, ``bytes``, ``bytearray``, ``tuple``, ``list`` now consistently support passing ``ssize_t`` values for sizes and indexes. Previously, only ``size_t`` was accepted in several interfaces. `#3219 `_ +* Avoid evaluating ``PYBIND11_TLS_REPLACE_VALUE`` arguments more than once. + `#3290 `_ Fixes: -* Bug fix: enum value's ``__int__`` returning non-int when underlying type is bool or of char type. +* Bug fix: enum value's ``__int__`` returning non-int when underlying type is + bool or of char type. `#1334 `_ * Fixes bug in setting error state in Capsule's pointer methods. @@ -61,7 +82,8 @@ Fixes: * A long-standing memory leak in ``py::cpp_function::initialize`` was fixed. `#3229 `_ -* Fixes thread safety for some ``pybind11::type_caster`` which require lifetime extension, such as for ``std::string_view``. +* Fixes thread safety for some ``pybind11::type_caster`` which require lifetime + extension, such as for ``std::string_view``. `#3237 `_ * Restore compatibility with gcc 4.8.4 as distributed by ubuntu-trusty, linuxmint-17. @@ -73,12 +95,26 @@ Build system improvements: * Fix regression in CMake Python package config: improper use of absolute path. `#3144 `_ +* Cached Python version information could become stale when CMake was re-run + with a different Python version. The build system now detects this and + updates this information. + `#3299 `_ + * Specified UTF8-encoding in setup.py calls of open(). `#3137 `_ +* Fix a harmless warning from CMake 3.21 with the classic Python discovery. + `#3220 `_ + Backend and tidying up: +* Reduced thread-local storage required for keeping alive temporary data for + type conversion to one key per ABI version, rather than one key per extension + module. This makes the total thread-local storage required by pybind11 2 + keys per ABI version. + `#3275 `_ + * Optimize NumPy array construction with additional moves. `#3183 `_ From 6be64304b7e5cd4792fcd25d031127b99ef474bc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 28 Sep 2021 10:09:08 -0400 Subject: [PATCH 3/6] [pre-commit.ci] pre-commit autoupdate (#3312) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/asottile/pyupgrade: v2.26.0 → v2.28.0](https://github.com/asottile/pyupgrade/compare/v2.26.0...v2.28.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4245641ba..05bfce851 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -33,7 +33,7 @@ repos: exclude: ^noxfile.py$ - repo: https://github.com/asottile/pyupgrade - rev: v2.26.0 + rev: v2.28.0 hooks: - id: pyupgrade From c9bbf8d2eed098f3c10ae461bab2c0f9541d38f7 Mon Sep 17 00:00:00 2001 From: Philipp Bucher Date: Tue, 28 Sep 2021 16:09:38 +0200 Subject: [PATCH 4/6] docs: fix minor typo (#3311) --- docs/compiling.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/compiling.rst b/docs/compiling.rst index 073851048..75608bd57 100644 --- a/docs/compiling.rst +++ b/docs/compiling.rst @@ -340,7 +340,7 @@ standard explicitly with set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ version selection") # or 11, 14, 17, 20 set(CMAKE_CXX_STANDARD_REQUIRED ON) # optional, ensure standard is supported - set(CMAKE_CXX_EXTENSIONS OFF) # optional, keep compiler extensionsn off + set(CMAKE_CXX_EXTENSIONS OFF) # optional, keep compiler extensions off The variables can also be set when calling CMake from the command line using the ``-D=`` flag. You can also manually set ``CXX_STANDARD`` From a1830d5e6e27cb4c40955399f3826736a59f5cd5 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Wed, 29 Sep 2021 06:18:58 -0400 Subject: [PATCH 5/6] docs: mention title conventions in PR template (#3313) --- .github/pull_request_template.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 97a6ff7dd..54b7f5100 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,3 +1,7 @@ + ## Description From b4e1ab8caa483350fbcfc7397b3b5cb33c49050f Mon Sep 17 00:00:00 2001 From: xaedes Date: Thu, 30 Sep 2021 20:45:06 +0200 Subject: [PATCH 6/6] Docs: Demonstrate non-enum internal types in example (#3314) * Docs: Demonstrate non-enum internal types in example Previously example only demonstrated internal enumeration type. To show that it works for other internal types the same way the example was updated with an additional struct Pet::Attributes type. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- docs/classes.rst | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/docs/classes.rst b/docs/classes.rst index a4463e417..13fa8b538 100644 --- a/docs/classes.rst +++ b/docs/classes.rst @@ -446,8 +446,7 @@ you can use ``py::detail::overload_cast_impl`` with an additional set of parenth Enumerations and internal types =============================== -Let's now suppose that the example class contains an internal enumeration type, -e.g.: +Let's now suppose that the example class contains internal types like enumerations, e.g.: .. code-block:: cpp @@ -457,10 +456,15 @@ e.g.: Cat }; + struct Attributes { + float age = 0; + }; + Pet(const std::string &name, Kind type) : name(name), type(type) { } std::string name; Kind type; + Attributes attr; }; The binding code for this example looks as follows: @@ -471,15 +475,21 @@ The binding code for this example looks as follows: pet.def(py::init()) .def_readwrite("name", &Pet::name) - .def_readwrite("type", &Pet::type); + .def_readwrite("type", &Pet::type) + .def_readwrite("attr", &Pet::attr); py::enum_(pet, "Kind") .value("Dog", Pet::Kind::Dog) .value("Cat", Pet::Kind::Cat) .export_values(); -To ensure that the ``Kind`` type is created within the scope of ``Pet``, the -``pet`` :class:`class_` instance must be supplied to the :class:`enum_`. + py::class_ attributes(pet, "Attributes") + .def(py::init<>()) + .def_readwrite("age", &Pet::Attributes::age); + + +To ensure that the nested types ``Kind`` and ``Attributes`` are created within the scope of ``Pet``, the +``pet`` :class:`class_` instance must be supplied to the :class:`enum_` and :class:`class_` constructor. The :func:`enum_::export_values` function exports the enum entries into the parent scope, which should be skipped for newer C++11-style strongly typed enums.