From e0f9e77466b667553d8e623c06bdfa7252012efe Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Thu, 27 Jun 2024 22:26:09 -0400 Subject: [PATCH 1/6] fix(cmake): remove extra = in flto assignment (#5207) --- tools/pybind11Common.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/pybind11Common.cmake b/tools/pybind11Common.cmake index d8e18e67bf..8467b45d2c 100644 --- a/tools/pybind11Common.cmake +++ b/tools/pybind11Common.cmake @@ -335,7 +335,7 @@ function(_pybind11_generate_lto target prefer_thin_lto) set(PYBIND11_LTO_LINKER_FLAGS "-flto${thin}${linker_append}") elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") _pybind11_return_if_cxx_and_linker_flags_work( - HAS_FLTO_THIN "-flto${thin}${cxx_append}" "-flto=${thin}${linker_append}" + HAS_FLTO_THIN "-flto${thin}${cxx_append}" "-flto${thin}${linker_append}" PYBIND11_LTO_CXX_FLAGS PYBIND11_LTO_LINKER_FLAGS) endif() if(NOT HAS_FLTO_THIN) From 08f946a431db92544c95c921ba844a620580ee83 Mon Sep 17 00:00:00 2001 From: Michael Carlstrom Date: Fri, 28 Jun 2024 01:20:28 -0400 Subject: [PATCH 2/6] fix: add guard for GCC <10.3 on C++20 (#5205) * Update CI * update define guard * style: pre-commit fixes * updated define guard * style: pre-commit fixes * update guard * testing new guards * update guards * surely this time * style: pre-commit fixes * Define PYBIND11_TYPING_H_HAS_STRING_LITERAL to avoid repeating a complex expression. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Ralf W. Grosse-Kunstleve --- .github/workflows/ci.yml | 2 ++ include/pybind11/typing.h | 7 +++++-- tests/test_pytypes.cpp | 8 ++++---- tests/test_pytypes.py | 4 ++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3054d842a1..041e0dfb3f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -501,7 +501,9 @@ jobs: - { gcc: 7, std: 17 } - { gcc: 8, std: 14 } - { gcc: 8, std: 17 } + - { gcc: 9, std: 20 } - { gcc: 10, std: 17 } + - { gcc: 10, std: 20 } - { gcc: 11, std: 20 } - { gcc: 12, std: 20 } - { gcc: 13, std: 20 } diff --git a/include/pybind11/typing.h b/include/pybind11/typing.h index 1442cdc7f1..c8ba18d499 100644 --- a/include/pybind11/typing.h +++ b/include/pybind11/typing.h @@ -98,7 +98,10 @@ class Never : public none { using none::none; }; -#if defined(__cpp_nontype_template_parameter_class) +#if defined(__cpp_nontype_template_parameter_class) \ + && (/* See #5201 */ !defined(__GNUC__) \ + || (__GNUC__ > 10 || (__GNUC__ == 10 && __GNUC_MINOR__ >= 3))) +# define PYBIND11_TYPING_H_HAS_STRING_LITERAL template struct StringLiteral { constexpr StringLiteral(const char (&str)[N]) { std::copy_n(str, N, name); } @@ -222,7 +225,7 @@ struct handle_type_name { static constexpr auto name = const_name("Never"); }; -#if defined(__cpp_nontype_template_parameter_class) +#if defined(PYBIND11_TYPING_H_HAS_STRING_LITERAL) template struct handle_type_name> { static constexpr auto name = const_name("Literal[") diff --git a/tests/test_pytypes.cpp b/tests/test_pytypes.cpp index 7c30978cea..ecb44939aa 100644 --- a/tests/test_pytypes.cpp +++ b/tests/test_pytypes.cpp @@ -109,7 +109,7 @@ void m_defs(py::module_ &m) { } // namespace handle_from_move_only_type_with_operator_PyObject -#if defined(__cpp_nontype_template_parameter_class) +#if defined(PYBIND11_TYPING_H_HAS_STRING_LITERAL) namespace literals { enum Color { RED = 0, BLUE = 1 }; @@ -905,7 +905,7 @@ TEST_SUBMODULE(pytypes, m) { m.def("annotate_optional_to_object", [](py::typing::Optional &o) -> py::object { return o; }); -#if defined(__cpp_nontype_template_parameter_class) +#if defined(PYBIND11_TYPING_H_HAS_STRING_LITERAL) py::enum_(m, "Color") .value("RED", literals::Color::RED) .value("BLUE", literals::Color::BLUE); @@ -919,8 +919,8 @@ TEST_SUBMODULE(pytypes, m) { m.def("annotate_listT_to_T", [](const py::typing::List &l) -> typevar::TypeVarT { return l[0]; }); m.def("annotate_object_to_T", [](const py::object &o) -> typevar::TypeVarT { return o; }); - m.attr("if_defined__cpp_nontype_template_parameter_class") = true; + m.attr("defined_PYBIND11_TYPING_H_HAS_STRING_LITERAL") = true; #else - m.attr("if_defined__cpp_nontype_template_parameter_class") = false; + m.attr("defined_PYBIND11_TYPING_H_HAS_STRING_LITERAL") = false; #endif } diff --git a/tests/test_pytypes.py b/tests/test_pytypes.py index 30931e0b9a..218092b434 100644 --- a/tests/test_pytypes.py +++ b/tests/test_pytypes.py @@ -1025,7 +1025,7 @@ def test_optional_object_annotations(doc): @pytest.mark.skipif( - not m.if_defined__cpp_nontype_template_parameter_class, + not m.defined_PYBIND11_TYPING_H_HAS_STRING_LITERAL, reason="C++20 feature not available.", ) def test_literal(doc): @@ -1036,7 +1036,7 @@ def test_literal(doc): @pytest.mark.skipif( - not m.if_defined__cpp_nontype_template_parameter_class, + not m.defined_PYBIND11_TYPING_H_HAS_STRING_LITERAL, reason="C++20 feature not available.", ) def test_typevar(doc): From 51c2aa16de5b50fe4be6a0016d6090d4a831899e Mon Sep 17 00:00:00 2001 From: wenqing Date: Fri, 28 Jun 2024 16:12:32 +0200 Subject: [PATCH 3/6] Fixed a compilation error with gcc 14 (#5208) --- include/pybind11/typing.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/pybind11/typing.h b/include/pybind11/typing.h index c8ba18d499..b0feb9464a 100644 --- a/include/pybind11/typing.h +++ b/include/pybind11/typing.h @@ -14,6 +14,8 @@ #include "cast.h" #include "pytypes.h" +#include + PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(typing) From d805e9967fbdd1b7cc68c95c960f401321449087 Mon Sep 17 00:00:00 2001 From: Michael Carlstrom Date: Sun, 30 Jun 2024 12:52:37 -0400 Subject: [PATCH 4/6] feat(types) Adds special Case for empty C++ tuple type annotation (#5214) * add special case and unit test * add newline --- include/pybind11/cast.h | 7 +++++++ tests/test_builtin_casters.py | 2 ++ 2 files changed, 9 insertions(+) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 624b8ebaca..e41ad2abfa 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -740,6 +740,13 @@ class type_caster> : public tuple_caster {} template class type_caster> : public tuple_caster {}; +template <> +class type_caster> : public tuple_caster { +public: + // PEP 484 specifies this syntax for an empty tuple + static constexpr auto name = const_name("tuple[()]"); +}; + /// Helper class which abstracts away certain actions. Users can provide specializations for /// custom holders, but it's only necessary if the type has a non-standard interface. template diff --git a/tests/test_builtin_casters.py b/tests/test_builtin_casters.py index 9aa5926e9c..b37aacff1f 100644 --- a/tests/test_builtin_casters.py +++ b/tests/test_builtin_casters.py @@ -368,6 +368,8 @@ def test_tuple(doc): """ ) + assert doc(m.empty_tuple) == """empty_tuple() -> tuple[()]""" + assert m.rvalue_pair() == ("rvalue", "rvalue") assert m.lvalue_pair() == ("lvalue", "lvalue") assert m.rvalue_tuple() == ("rvalue", "rvalue", "rvalue") From d78446cc2be43e437ec69fc5b14e4ab29730efd4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 30 Jun 2024 23:32:03 -0400 Subject: [PATCH 5/6] chore(deps): bump actions/attest-build-provenance in the actions group (#5216) Bumps the actions group with 1 update: [actions/attest-build-provenance](https://github.com/actions/attest-build-provenance). Updates `actions/attest-build-provenance` from 1.1.2 to 1.3.2 - [Release notes](https://github.com/actions/attest-build-provenance/releases) - [Changelog](https://github.com/actions/attest-build-provenance/blob/main/RELEASE.md) - [Commits](https://github.com/actions/attest-build-provenance/compare/173725a1209d09b31f9d30a3890cf2757ebbff0d...bdd51370e0416ac948727f861e03c2f05d32d78e) --- updated-dependencies: - dependency-name: actions/attest-build-provenance dependency-type: direct:production update-type: version-update:semver-minor dependency-group: actions ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/pip.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pip.yml b/.github/workflows/pip.yml index a054ce6952..fb9c62ca22 100644 --- a/.github/workflows/pip.yml +++ b/.github/workflows/pip.yml @@ -102,7 +102,7 @@ jobs: - uses: actions/download-artifact@v4 - name: Generate artifact attestation for sdist and wheel - uses: actions/attest-build-provenance@173725a1209d09b31f9d30a3890cf2757ebbff0d # v1.1.2 + uses: actions/attest-build-provenance@bdd51370e0416ac948727f861e03c2f05d32d78e # v1.3.2 with: subject-path: "*/pybind11*" From 64c886d41b61385058aabd2b4eb153441d7e103e Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Mon, 1 Jul 2024 20:27:45 -0700 Subject: [PATCH 6/6] Tracking ci.yml changes from master. --- .github/workflows/ci_sh_def.yml | 2 ++ .github/workflows/ci_sh_def.yml.patch | 36 +++++++++++++-------------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci_sh_def.yml b/.github/workflows/ci_sh_def.yml index 92b43b6634..fd11911db5 100644 --- a/.github/workflows/ci_sh_def.yml +++ b/.github/workflows/ci_sh_def.yml @@ -520,7 +520,9 @@ jobs: - { gcc: 7, std: 17 } - { gcc: 8, std: 14 } - { gcc: 8, std: 17 } + - { gcc: 9, std: 20 } - { gcc: 10, std: 17 } + - { gcc: 10, std: 20 } - { gcc: 11, std: 20 } - { gcc: 12, std: 20 } - { gcc: 13, std: 20 } diff --git a/.github/workflows/ci_sh_def.yml.patch b/.github/workflows/ci_sh_def.yml.patch index 439763ece7..e6f5e57f68 100644 --- a/.github/workflows/ci_sh_def.yml.patch +++ b/.github/workflows/ci_sh_def.yml.patch @@ -1,5 +1,5 @@ ---- ci.yml 2024-06-21 22:56:01.205982412 -0700 -+++ ci_sh_def.yml 2024-06-21 22:57:45.189902320 -0700 +--- ci.yml 2024-07-01 20:26:45.034547517 -0700 ++++ ci_sh_def.yml 2024-07-01 20:27:32.110506039 -0700 @@ -1,4 +1,16 @@ -name: CI +# PLEASE KEEP THIS GROUP OF FILES IN SYNC AT ALL TIMES: @@ -93,7 +93,7 @@ -DPYBIND11_TEST_FILTER="test_smart_ptr.cpp" - name: Build -@@ -529,6 +547,7 @@ +@@ -531,6 +549,7 @@ -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -DCMAKE_CXX_STANDARD=${{ matrix.std }} @@ -101,7 +101,7 @@ -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") - name: Build -@@ -551,6 +570,7 @@ +@@ -553,6 +572,7 @@ -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -DCMAKE_CXX_STANDARD=${{ matrix.std }} @@ -109,7 +109,7 @@ -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") "-DPYBIND11_TEST_OVERRIDE=test_call_policies.cpp;test_gil_scoped.cpp;test_thread.cpp" -@@ -600,6 +620,7 @@ +@@ -602,6 +622,7 @@ -DDOWNLOAD_CATCH=ON \ -DDOWNLOAD_EIGEN=OFF \ -DCMAKE_CXX_STANDARD=11 \ @@ -117,7 +117,7 @@ -DCMAKE_CXX_COMPILER=$(which icpc) \ -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") -@@ -632,6 +653,7 @@ +@@ -634,6 +655,7 @@ -DDOWNLOAD_CATCH=ON \ -DDOWNLOAD_EIGEN=OFF \ -DCMAKE_CXX_STANDARD=17 \ @@ -125,7 +125,7 @@ -DCMAKE_CXX_COMPILER=$(which icpc) \ -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") -@@ -703,6 +725,7 @@ +@@ -705,6 +727,7 @@ -DDOWNLOAD_CATCH=ON -DDOWNLOAD_EIGEN=ON -DCMAKE_CXX_STANDARD=11 @@ -133,7 +133,7 @@ -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") - name: Build -@@ -753,6 +776,7 @@ +@@ -755,6 +778,7 @@ cmake ../pybind11-tests -DDOWNLOAD_CATCH=ON -DPYBIND11_WERROR=ON @@ -141,7 +141,7 @@ -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") working-directory: /build-tests -@@ -856,6 +880,7 @@ +@@ -858,6 +882,7 @@ -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -DDOWNLOAD_EIGEN=ON @@ -149,7 +149,7 @@ ${{ matrix.args }} - name: Build C++11 run: cmake --build build -j 2 -@@ -910,6 +935,7 @@ +@@ -912,6 +937,7 @@ -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -DDOWNLOAD_EIGEN=ON @@ -157,7 +157,7 @@ ${{ matrix.args }} - name: Build C++11 run: cmake --build build --config Debug -j 2 -@@ -952,6 +978,7 @@ +@@ -954,6 +980,7 @@ -DDOWNLOAD_CATCH=ON -DDOWNLOAD_EIGEN=ON -DCMAKE_CXX_STANDARD=20 @@ -165,7 +165,7 @@ - name: Build C++20 run: cmake --build build -j 2 -@@ -972,6 +999,7 @@ +@@ -974,6 +1001,7 @@ -DDOWNLOAD_CATCH=ON -DDOWNLOAD_EIGEN=ON -DCMAKE_CXX_STANDARD=20 @@ -173,7 +173,7 @@ "-DPYBIND11_TEST_OVERRIDE=test_call_policies.cpp;test_gil_scoped.cpp;test_thread.cpp" - name: Build C++20 - Exercise cmake -DPYBIND11_TEST_OVERRIDE -@@ -1024,6 +1052,7 @@ +@@ -1026,6 +1054,7 @@ run: >- cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=11 -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -DPYTHON_EXECUTABLE=$(python -c "import sys; print(sys.executable)") @@ -181,7 +181,7 @@ -S . -B build - name: Build C++11 -@@ -1045,6 +1074,7 @@ +@@ -1047,6 +1076,7 @@ run: >- cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=14 -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -DPYTHON_EXECUTABLE=$(python -c "import sys; print(sys.executable)") @@ -189,7 +189,7 @@ -S . -B build2 - name: Build C++14 -@@ -1066,6 +1096,7 @@ +@@ -1068,6 +1098,7 @@ run: >- cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=17 -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -DPYTHON_EXECUTABLE=$(python -c "import sys; print(sys.executable)") @@ -197,7 +197,7 @@ -S . -B build3 - name: Build C++17 -@@ -1133,6 +1164,7 @@ +@@ -1135,6 +1166,7 @@ -DDOWNLOAD_EIGEN=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_STANDARD=17 @@ -205,7 +205,7 @@ - name: Build run: cmake --build . -j 2 -@@ -1198,6 +1230,7 @@ +@@ -1200,6 +1232,7 @@ -DDOWNLOAD_EIGEN=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_STANDARD=17 @@ -213,7 +213,7 @@ -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") - name: Build -@@ -1221,6 +1254,7 @@ +@@ -1223,6 +1256,7 @@ -DDOWNLOAD_EIGEN=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_STANDARD=17