From ec73bdaf1fab4f89d0de679e7cc0f4e2b63b20a1 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Thu, 21 Mar 2024 02:27:58 -0400 Subject: [PATCH 1/3] ci: skipping test for Windows Clang failure (#5062) * ci: trying things for Windows Clang failure Signed-off-by: Henry Schreiner * WIP: try using older clang Signed-off-by: Henry Schreiner * tests: skip broken test Signed-off-by: Henry Schreiner * tests: try to skip test in tests Signed-off-by: Henry Schreiner * fix(tests): Prefer __version__ over MSVC Signed-off-by: Henry Schreiner * chore: avoid warning on Clang Signed-off-by: Henry Schreiner * Update tests/test_exceptions.py * Update tests/test_exceptions.py --------- Signed-off-by: Henry Schreiner --- include/pybind11/detail/internals.h | 11 ++++++++--- tests/CMakeLists.txt | 6 +++++- tests/pybind11_tests.cpp | 6 +++--- tests/test_exceptions.py | 7 ++++++- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/include/pybind11/detail/internals.h b/include/pybind11/detail/internals.h index ab399016e..c1047e4a0 100644 --- a/include/pybind11/detail/internals.h +++ b/include/pybind11/detail/internals.h @@ -67,9 +67,14 @@ inline PyObject *make_object_base_type(PyTypeObject *metaclass); // `Py_LIMITED_API` anyway. # if PYBIND11_INTERNALS_VERSION > 4 # define PYBIND11_TLS_KEY_REF Py_tss_t & -# if defined(__GNUC__) && !defined(__INTEL_COMPILER) -// Clang on macOS warns due to `Py_tss_NEEDS_INIT` not specifying an initializer -// for every field. +# if defined(__clang__) +# define PYBIND11_TLS_KEY_INIT(var) \ + _Pragma("clang diagnostic push") /**/ \ + _Pragma("clang diagnostic ignored \"-Wmissing-field-initializers\"") /**/ \ + Py_tss_t var \ + = Py_tss_NEEDS_INIT; \ + _Pragma("clang diagnostic pop") +# elif defined(__GNUC__) && !defined(__INTEL_COMPILER) # define PYBIND11_TLS_KEY_INIT(var) \ _Pragma("GCC diagnostic push") /**/ \ _Pragma("GCC diagnostic ignored \"-Wmissing-field-initializers\"") /**/ \ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6ad729aae..e347a2e5c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -520,11 +520,15 @@ set(PYBIND11_TEST_PREFIX_COMMAND "" CACHE STRING "Put this before pytest, use for checkers and such") +set(PYBIND11_PYTEST_ARGS + "" + CACHE STRING "Extra arguments for pytest") + # A single command to compile and run the tests add_custom_target( pytest COMMAND ${PYBIND11_TEST_PREFIX_COMMAND} ${PYTHON_EXECUTABLE} -m pytest - ${PYBIND11_ABS_PYTEST_FILES} + ${PYBIND11_ABS_PYTEST_FILES} ${PYBIND11_PYTEST_ARGS} DEPENDS ${test_targets} WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" USES_TERMINAL) diff --git a/tests/pybind11_tests.cpp b/tests/pybind11_tests.cpp index 624034648..4578e4b7f 100644 --- a/tests/pybind11_tests.cpp +++ b/tests/pybind11_tests.cpp @@ -80,10 +80,10 @@ PYBIND11_MODULE(pybind11_tests, m) { // Intentionally kept minimal to not create a maintenance chore // ("just enough" to be conclusive). -#if defined(_MSC_FULL_VER) - m.attr("compiler_info") = "MSVC " PYBIND11_TOSTRING(_MSC_FULL_VER); -#elif defined(__VERSION__) +#if defined(__VERSION__) m.attr("compiler_info") = __VERSION__; +#elif defined(_MSC_FULL_VER) + m.attr("compiler_info") = "MSVC " PYBIND11_TOSTRING(_MSC_FULL_VER); #else m.attr("compiler_info") = py::none(); #endif diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py index 5d8e6292a..6752285ac 100644 --- a/tests/test_exceptions.py +++ b/tests/test_exceptions.py @@ -4,7 +4,7 @@ import pytest import env import pybind11_cross_module_tests as cm -import pybind11_tests # noqa: F401 +import pybind11_tests from pybind11_tests import exceptions as m @@ -248,6 +248,11 @@ def test_nested_throws(capture): assert str(excinfo.value) == "this is a helper-defined translated exception" +# TODO: Investigate this crash, see pybind/pybind11#5062 for background +@pytest.mark.skipif( + sys.platform.startswith("win32") and "Clang" in pybind11_tests.compiler_info, + reason="Started segfaulting February 2024", +) def test_throw_nested_exception(): with pytest.raises(RuntimeError) as excinfo: m.throw_nested_exception() From ddb8b67a8aa8198ec8a028fb28f6870e44e7a467 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Thu, 21 Mar 2024 03:23:57 -0400 Subject: [PATCH 2/3] fix(cmake): allow forcing old FindPython (#5042) --- tools/pybind11Common.cmake | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/pybind11Common.cmake b/tools/pybind11Common.cmake index 50b15e11b..57721aeb1 100644 --- a/tools/pybind11Common.cmake +++ b/tools/pybind11Common.cmake @@ -173,12 +173,16 @@ endif() # Check to see which Python mode we are in, new, old, or no python if(PYBIND11_NOPYTHON) set(_pybind11_nopython ON) + # We won't use new FindPython if PYBIND11_FINDPYTHON is defined and falselike + # Otherwise, we use if FindPythonLibs is missing or if FindPython was already used elseif( - _pybind11_missing_old_python STREQUAL "NEW" - OR PYBIND11_FINDPYTHON - OR Python_FOUND - OR Python2_FOUND - OR Python3_FOUND) + (NOT DEFINED PYBIND11_FINDPYTHON OR PYBIND11_FINDPYTHON) + AND (_pybind11_missing_old_python STREQUAL "NEW" + OR PYBIND11_FINDPYTHON + OR Python_FOUND + OR Python3_FOUND + )) + # New mode include("${CMAKE_CURRENT_LIST_DIR}/pybind11NewTools.cmake") From 65370f330ea9349bd9e996028b4cb7adfde37660 Mon Sep 17 00:00:00 2001 From: Jason Watson Date: Thu, 21 Mar 2024 08:24:19 +0100 Subject: [PATCH 3/3] Create handle_type_name specialization to type-hint variable length tuples (#5051) --- include/pybind11/typing.h | 7 +++++++ tests/test_pytypes.cpp | 2 ++ tests/test_pytypes.py | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/include/pybind11/typing.h b/include/pybind11/typing.h index b7b1a4e54..0ee329d85 100644 --- a/include/pybind11/typing.h +++ b/include/pybind11/typing.h @@ -79,6 +79,13 @@ struct handle_type_name> { static constexpr auto name = const_name("tuple[()]"); }; +template +struct handle_type_name> { + // PEP 484 specifies this syntax for a variable-length tuple + static constexpr auto name + = const_name("tuple[") + make_caster::name + const_name(", ...]"); +}; + template struct handle_type_name> { static constexpr auto name = const_name("dict[") + make_caster::name + const_name(", ") diff --git a/tests/test_pytypes.cpp b/tests/test_pytypes.cpp index 0cd480ebb..e840eb61f 100644 --- a/tests/test_pytypes.cpp +++ b/tests/test_pytypes.cpp @@ -825,6 +825,8 @@ TEST_SUBMODULE(pytypes, m) { m.def("annotate_tuple_float_str", [](const py::typing::Tuple &) {}); m.def("annotate_tuple_empty", [](const py::typing::Tuple<> &) {}); + m.def("annotate_tuple_variable_length", + [](const py::typing::Tuple &) {}); m.def("annotate_dict_str_int", [](const py::typing::Dict &) {}); m.def("annotate_list_int", [](const py::typing::List &) {}); m.def("annotate_set_str", [](const py::typing::Set &) {}); diff --git a/tests/test_pytypes.py b/tests/test_pytypes.py index 2b2027316..cfb144523 100644 --- a/tests/test_pytypes.py +++ b/tests/test_pytypes.py @@ -911,6 +911,13 @@ def test_tuple_empty_annotations(doc): ) +def test_tuple_variable_length_annotations(doc): + assert ( + doc(m.annotate_tuple_variable_length) + == "annotate_tuple_variable_length(arg0: tuple[float, ...]) -> None" + ) + + def test_dict_annotations(doc): assert ( doc(m.annotate_dict_str_int)