From 2e35470cffc47903dd47b7e68c7acf4302fd7057 Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Wed, 26 Jun 2024 15:46:46 -0400 Subject: [PATCH 1/3] fix: use manual padding of instance_map_shard (#5200) * Use manual padding of instance_map_shard. The alignas(64) specifier requires aligned allocation, which is not available on macOS when targeting versions before 10.14. * Add 'see #5200' * Update include/pybind11/detail/internals.h * Update include/pybind11/detail/internals.h --------- Co-authored-by: Henry Schreiner --- include/pybind11/detail/internals.h | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/include/pybind11/detail/internals.h b/include/pybind11/detail/internals.h index 92a851602d..e61c1687fc 100644 --- a/include/pybind11/detail/internals.h +++ b/include/pybind11/detail/internals.h @@ -148,18 +148,14 @@ struct override_hash { using instance_map = std::unordered_multimap; -// ignore: structure was padded due to alignment specifier -PYBIND11_WARNING_PUSH -PYBIND11_WARNING_DISABLE_MSVC(4324) - // Instance map shards are used to reduce mutex contention in free-threaded Python. -struct alignas(64) instance_map_shard { +struct instance_map_shard { std::mutex mutex; instance_map registered_instances; + // alignas(64) would be better, but causes compile errors in macOS before 10.14 (see #5200) + char padding[64 - (sizeof(std::mutex) + sizeof(instance_map)) % 64]; }; -PYBIND11_WARNING_POP - /// Internal data structure used to track registered instances and types. /// Whenever binary incompatible changes are made to this structure, /// `PYBIND11_INTERNALS_VERSION` must be incremented. From 4bd538a40a45803b24f95ef4fb3de5d773e2d426 Mon Sep 17 00:00:00 2001 From: Michael Carlstrom Date: Wed, 26 Jun 2024 16:34:06 -0400 Subject: [PATCH 2/3] feat(types): add support for Typing.Callable Special Case (#5202) * Add special case * linty --- include/pybind11/typing.h | 8 ++++++++ tests/test_pytypes.cpp | 1 + tests/test_pytypes.py | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/include/pybind11/typing.h b/include/pybind11/typing.h index cf70b739ed..1442cdc7f1 100644 --- a/include/pybind11/typing.h +++ b/include/pybind11/typing.h @@ -177,6 +177,14 @@ struct handle_type_name> { + const_name("], ") + make_caster::name + const_name("]"); }; +template +struct handle_type_name> { + // PEP 484 specifies this syntax for defining only return types of callables + using retval_type = conditional_t::value, void_type, Return>; + static constexpr auto name + = const_name("Callable[..., ") + make_caster::name + const_name("]"); +}; + template struct handle_type_name> { static constexpr auto name = const_name("type[") + make_caster::name + const_name("]"); diff --git a/tests/test_pytypes.cpp b/tests/test_pytypes.cpp index 6b347894b0..7c30978cea 100644 --- a/tests/test_pytypes.cpp +++ b/tests/test_pytypes.cpp @@ -865,6 +865,7 @@ TEST_SUBMODULE(pytypes, m) { m.def("annotate_fn", [](const py::typing::Callable, py::str)> &) {}); + m.def("annotate_fn_only_return", [](const py::typing::Callable &) {}); m.def("annotate_type", [](const py::typing::Type &t) -> py::type { return t; }); m.def("annotate_union", diff --git a/tests/test_pytypes.py b/tests/test_pytypes.py index 92a3a36bf4..30931e0b9a 100644 --- a/tests/test_pytypes.py +++ b/tests/test_pytypes.py @@ -959,6 +959,13 @@ def test_fn_annotations(doc): ) +def test_fn_return_only(doc): + assert ( + doc(m.annotate_fn_only_return) + == "annotate_fn_only_return(arg0: Callable[..., int]) -> None" + ) + + def test_type_annotation(doc): assert doc(m.annotate_type) == "annotate_type(arg0: type[int]) -> type" From 57287b578d58af016cd571f6eacee19300d37f2d Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Wed, 26 Jun 2024 18:14:17 -0400 Subject: [PATCH 3/3] docs: prepare for 2.13.1 (#5203) Signed-off-by: Henry Schreiner --- docs/changelog.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 7135e65311..ab6c713c16 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -15,6 +15,20 @@ IN DEVELOPMENT Changes will be summarized here periodically. +Version 2.13.1 (June 26, 2024) +------------------------------ + +New Features: + +* Add support for ``Typing.Callable[..., T]``. + `#5202 `_ + +Bug fixes: + +* Avoid aligned allocation in free-threaded build in order to support macOS + versions before 10.14. + `#5200 `_ + Version 2.13.0 (June 25, 2024) ------------------------------