Skip to content

Commit 08c83b8

Browse files
committed
Merge branch 'master' into sh_merge_master
2 parents fb4c618 + 57287b5 commit 08c83b8

File tree

5 files changed

+33
-7
lines changed

5 files changed

+33
-7
lines changed

docs/changelog.rst

+14
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ IN DEVELOPMENT
1515

1616
Changes will be summarized here periodically.
1717

18+
Version 2.13.1 (June 26, 2024)
19+
------------------------------
20+
21+
New Features:
22+
23+
* Add support for ``Typing.Callable[..., T]``.
24+
`#5202 <https://github.com/pybind/pybind11/pull/5202>`_
25+
26+
Bug fixes:
27+
28+
* Avoid aligned allocation in free-threaded build in order to support macOS
29+
versions before 10.14.
30+
`#5200 <https://github.com/pybind/pybind11/pull/5200>`_
31+
1832
Version 2.13.0 (June 25, 2024)
1933
------------------------------
2034

include/pybind11/detail/internals.h

+3-7
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,14 @@ struct override_hash {
149149

150150
using instance_map = std::unordered_multimap<const void *, instance *>;
151151

152-
// ignore: structure was padded due to alignment specifier
153-
PYBIND11_WARNING_PUSH
154-
PYBIND11_WARNING_DISABLE_MSVC(4324)
155-
156152
// Instance map shards are used to reduce mutex contention in free-threaded Python.
157-
struct alignas(64) instance_map_shard {
153+
struct instance_map_shard {
158154
std::mutex mutex;
159155
instance_map registered_instances;
156+
// alignas(64) would be better, but causes compile errors in macOS before 10.14 (see #5200)
157+
char padding[64 - (sizeof(std::mutex) + sizeof(instance_map)) % 64];
160158
};
161159

162-
PYBIND11_WARNING_POP
163-
164160
/// Internal data structure used to track registered instances and types.
165161
/// Whenever binary incompatible changes are made to this structure,
166162
/// `PYBIND11_INTERNALS_VERSION` must be incremented.

include/pybind11/typing.h

+8
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,14 @@ struct handle_type_name<typing::Callable<Return(Args...)>> {
177177
+ const_name("], ") + make_caster<retval_type>::name + const_name("]");
178178
};
179179

180+
template <typename Return>
181+
struct handle_type_name<typing::Callable<Return(ellipsis)>> {
182+
// PEP 484 specifies this syntax for defining only return types of callables
183+
using retval_type = conditional_t<std::is_same<Return, void>::value, void_type, Return>;
184+
static constexpr auto name
185+
= const_name("Callable[..., ") + make_caster<retval_type>::name + const_name("]");
186+
};
187+
180188
template <typename T>
181189
struct handle_type_name<typing::Type<T>> {
182190
static constexpr auto name = const_name("type[") + make_caster<T>::name + const_name("]");

tests/test_pytypes.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,7 @@ TEST_SUBMODULE(pytypes, m) {
865865
m.def("annotate_fn",
866866
[](const py::typing::Callable<int(py::typing::List<py::str>, py::str)> &) {});
867867

868+
m.def("annotate_fn_only_return", [](const py::typing::Callable<int(py::ellipsis)> &) {});
868869
m.def("annotate_type", [](const py::typing::Type<int> &t) -> py::type { return t; });
869870

870871
m.def("annotate_union",

tests/test_pytypes.py

+7
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,13 @@ def test_fn_annotations(doc):
959959
)
960960

961961

962+
def test_fn_return_only(doc):
963+
assert (
964+
doc(m.annotate_fn_only_return)
965+
== "annotate_fn_only_return(arg0: Callable[..., int]) -> None"
966+
)
967+
968+
962969
def test_type_annotation(doc):
963970
assert doc(m.annotate_type) == "annotate_type(arg0: type[int]) -> type"
964971

0 commit comments

Comments
 (0)