diff --git a/docs/changelog.rst b/docs/changelog.rst index 7135e6531..ab6c713c1 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) ------------------------------ diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h index a83302f13..e37152a9a 100644 --- a/include/pybind11/detail/common.h +++ b/include/pybind11/detail/common.h @@ -11,11 +11,11 @@ #define PYBIND11_VERSION_MAJOR 2 #define PYBIND11_VERSION_MINOR 13 -#define PYBIND11_VERSION_PATCH 0 +#define PYBIND11_VERSION_PATCH 1 // Similar to Python's convention: https://docs.python.org/3/c-api/apiabiversion.html // Additional convention: 0xD = dev -#define PYBIND11_VERSION_HEX 0x020D0000 +#define PYBIND11_VERSION_HEX 0x020D0100 // Define some generic pybind11 helper macros for warning management. // diff --git a/include/pybind11/detail/internals.h b/include/pybind11/detail/internals.h index 92a851602..e61c1687f 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. diff --git a/include/pybind11/typing.h b/include/pybind11/typing.h index cf70b739e..1442cdc7f 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/pybind11/_version.py b/pybind11/_version.py index 5795f4406..18b72c07c 100644 --- a/pybind11/_version.py +++ b/pybind11/_version.py @@ -8,5 +8,5 @@ def _to_int(s: str) -> int | str: return s -__version__ = "2.13.0" +__version__ = "2.13.1" version_info = tuple(_to_int(s) for s in __version__.split(".")) diff --git a/tests/test_pytypes.cpp b/tests/test_pytypes.cpp index 6b347894b..7c30978ce 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 92a3a36bf..30931e0b9 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"