Skip to content

Commit fb4c618

Browse files
committed
Merge branch 'master' into sh_merge_master
2 parents 39fbe46 + 895e657 commit fb4c618

File tree

10 files changed

+308
-12
lines changed

10 files changed

+308
-12
lines changed

.github/workflows/pip.yml

+10-6
Original file line numberDiff line numberDiff line change
@@ -92,23 +92,27 @@ jobs:
9292
runs-on: ubuntu-latest
9393
if: github.event_name == 'release' && github.event.action == 'published'
9494
needs: [packaging]
95+
environment: pypi
96+
permissions:
97+
id-token: write
98+
attestations: write
99+
contents: read
95100

96101
steps:
97-
- uses: actions/setup-python@v5
98-
with:
99-
python-version: "3.x"
100-
101102
# Downloads all to directories matching the artifact names
102103
- uses: actions/download-artifact@v4
103104

105+
- name: Generate artifact attestation for sdist and wheel
106+
uses: actions/attest-build-provenance@173725a1209d09b31f9d30a3890cf2757ebbff0d # v1.1.2
107+
with:
108+
subject-path: "*/pybind11*"
109+
104110
- name: Publish standard package
105111
uses: pypa/gh-action-pypi-publish@release/v1
106112
with:
107-
password: ${{ secrets.pypi_password }}
108113
packages-dir: standard/
109114

110115
- name: Publish global package
111116
uses: pypa/gh-action-pypi-publish@release/v1
112117
with:
113-
password: ${{ secrets.pypi_password_global }}
114118
packages-dir: global/

docs/changelog.rst

+101
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,107 @@ IN DEVELOPMENT
1515

1616
Changes will be summarized here periodically.
1717

18+
Version 2.13.0 (June 25, 2024)
19+
------------------------------
20+
21+
New Features:
22+
23+
* Support free-threaded CPython (3.13t). Add ``py::mod_gil_not_used()`` tag to
24+
indicate if a module supports running with the GIL disabled.
25+
`#5148 <https://github.com/pybind/pybind11/pull/5148>`_
26+
27+
* Support for Python 3.6 was removed. (Official end-of-life: 2021-12-23).
28+
`#5177 <https://github.com/pybind/pybind11/pull/5177>`_
29+
30+
* ``py::list`` gained a ``.clear()`` method.
31+
`#5153 <https://github.com/pybind/pybind11/pull/5153>`_
32+
33+
34+
.. feat(types)
35+
36+
* Support for ``Union``, ``Optional``, ``type[T]``, ``typing.TypeGuard``,
37+
``typing.TypeIs``, ``typing.Never``, ``typing.NoReturn`` and
38+
``typing.Literal`` was added to ``pybind11/typing.h``.
39+
`#5166 <https://github.com/pybind/pybind11/pull/5166>`_
40+
`#5165 <https://github.com/pybind/pybind11/pull/5165>`_
41+
`#5194 <https://github.com/pybind/pybind11/pull/5194>`_
42+
`#5193 <https://github.com/pybind/pybind11/pull/5193>`_
43+
`#5192 <https://github.com/pybind/pybind11/pull/5192>`_
44+
45+
46+
.. feat(cmake)
47+
48+
* In CMake, if ``PYBIND11_USE_CROSSCOMPILING`` is enabled, then
49+
``CMAKE_CROSSCOMPILING`` will be respected and will keep pybind11 from
50+
accessing the interpreter during configuration. Several CMake variables will
51+
be required in this case, but can be deduced from the environment variable
52+
``SETUPTOOLS_EXT_SUFFIX``. The default (currently ``OFF``) may be changed in
53+
the future.
54+
`#5083 <https://github.com/pybind/pybind11/pull/5083>`_
55+
56+
57+
Bug fixes:
58+
59+
* A refcount bug (leading to heap-use-after-free) involving trampoline
60+
functions with ``PyObject *`` return type was fixed.
61+
`#5156 <https://github.com/pybind/pybind11/pull/5156>`_
62+
63+
* Return ``py::ssize_t`` from ``.ref_count()`` instead of ``int``.
64+
`#5139 <https://github.com/pybind/pybind11/pull/5139>`_
65+
66+
* A subtle bug involving C++ types with unusual ``operator&`` overrides
67+
was fixed.
68+
`#5189 <https://github.com/pybind/pybind11/pull/5189>`_
69+
70+
* Support Python 3.13 with minor fix, add to CI.
71+
`#5127 <https://github.com/pybind/pybind11/pull/5127>`_
72+
73+
74+
.. fix(cmake)
75+
76+
* Fix mistake affecting old cmake and old boost.
77+
`#5149 <https://github.com/pybind/pybind11/pull/5149>`_
78+
79+
80+
Documentation:
81+
82+
* Build docs updated to feature scikit-build-core and meson-python, and updated
83+
setuptools instructions.
84+
`#5168 <https://github.com/pybind/pybind11/pull/5168>`_
85+
86+
87+
Tests:
88+
89+
* Avoid immortal objects in tests.
90+
`#5150 <https://github.com/pybind/pybind11/pull/5150>`_
91+
92+
93+
CI:
94+
95+
* Compile against Python 3.13t in CI.
96+
97+
* Use ``macos-13`` (Intel) for CI jobs for now (will drop Python 3.7 soon).
98+
`#5109 <https://github.com/pybind/pybind11/pull/5109>`_
99+
100+
* Releases now have artifact attestations, visible at
101+
https://github.com/pybind/pybind11/attestations.
102+
`#5196 <https://github.com/pybind/pybind11/pull/5196>`_
103+
104+
Other:
105+
106+
* Some cleanup in preparation for 3.13 support.
107+
`#5137 <https://github.com/pybind/pybind11/pull/5137>`_
108+
109+
* Avoid a warning by ensuring an iterator end check is included in release mode.
110+
`#5129 <https://github.com/pybind/pybind11/pull/5129>`_
111+
112+
* Bump max cmake to 3.29.
113+
`#5075 <https://github.com/pybind/pybind11/pull/5075>`_
114+
115+
* Update docs and noxfile.
116+
`#5071 <https://github.com/pybind/pybind11/pull/5071>`_
117+
118+
18119
Version 2.12.0 (March 27, 2024)
19120
-------------------------------
20121

include/pybind11/detail/common.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
#pragma once
1111

1212
#define PYBIND11_VERSION_MAJOR 2
13-
#define PYBIND11_VERSION_MINOR 13
13+
#define PYBIND11_VERSION_MINOR 14
1414
#define PYBIND11_VERSION_PATCH 0.dev1
1515

1616
// Similar to Python's convention: https://docs.python.org/3/c-api/apiabiversion.html
1717
// Additional convention: 0xD = dev
18-
#define PYBIND11_VERSION_HEX 0x020D00D1
18+
#define PYBIND11_VERSION_HEX 0x020E00D1
1919

2020
// Define some generic pybind11 helper macros for warning management.
2121
//

include/pybind11/typing.h

+74
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,55 @@ class Type : public type {
7070

7171
template <typename... Types>
7272
class Union : public object {
73+
PYBIND11_OBJECT_DEFAULT(Union, object, PyObject_Type)
7374
using object::object;
7475
};
7576

7677
template <typename T>
7778
class Optional : public object {
79+
PYBIND11_OBJECT_DEFAULT(Optional, object, PyObject_Type)
7880
using object::object;
7981
};
8082

83+
template <typename T>
84+
class TypeGuard : public bool_ {
85+
using bool_::bool_;
86+
};
87+
88+
template <typename T>
89+
class TypeIs : public bool_ {
90+
using bool_::bool_;
91+
};
92+
93+
class NoReturn : public none {
94+
using none::none;
95+
};
96+
97+
class Never : public none {
98+
using none::none;
99+
};
100+
101+
#if defined(__cpp_nontype_template_parameter_class)
102+
template <size_t N>
103+
struct StringLiteral {
104+
constexpr StringLiteral(const char (&str)[N]) { std::copy_n(str, N, name); }
105+
char name[N];
106+
};
107+
108+
template <StringLiteral... StrLits>
109+
class Literal : public object {
110+
PYBIND11_OBJECT_DEFAULT(Literal, object, PyObject_Type)
111+
};
112+
113+
// Example syntax for creating a TypeVar.
114+
// typedef typing::TypeVar<"T"> TypeVarT;
115+
template <StringLiteral>
116+
class TypeVar : public object {
117+
PYBIND11_OBJECT_DEFAULT(TypeVar, object, PyObject_Type)
118+
using object::object;
119+
};
120+
#endif
121+
81122
PYBIND11_NAMESPACE_END(typing)
82123

83124
PYBIND11_NAMESPACE_BEGIN(detail)
@@ -153,5 +194,38 @@ struct handle_type_name<typing::Optional<T>> {
153194
static constexpr auto name = const_name("Optional[") + make_caster<T>::name + const_name("]");
154195
};
155196

197+
template <typename T>
198+
struct handle_type_name<typing::TypeGuard<T>> {
199+
static constexpr auto name = const_name("TypeGuard[") + make_caster<T>::name + const_name("]");
200+
};
201+
202+
template <typename T>
203+
struct handle_type_name<typing::TypeIs<T>> {
204+
static constexpr auto name = const_name("TypeIs[") + make_caster<T>::name + const_name("]");
205+
};
206+
207+
template <>
208+
struct handle_type_name<typing::NoReturn> {
209+
static constexpr auto name = const_name("NoReturn");
210+
};
211+
212+
template <>
213+
struct handle_type_name<typing::Never> {
214+
static constexpr auto name = const_name("Never");
215+
};
216+
217+
#if defined(__cpp_nontype_template_parameter_class)
218+
template <typing::StringLiteral... Literals>
219+
struct handle_type_name<typing::Literal<Literals...>> {
220+
static constexpr auto name = const_name("Literal[")
221+
+ pybind11::detail::concat(const_name(Literals.name)...)
222+
+ const_name("]");
223+
};
224+
template <typing::StringLiteral StrLit>
225+
struct handle_type_name<typing::TypeVar<StrLit>> {
226+
static constexpr auto name = const_name(StrLit.name);
227+
};
228+
#endif
229+
156230
PYBIND11_NAMESPACE_END(detail)
157231
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

noxfile.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def tests_packaging(session: nox.Session) -> None:
4545
Run the packaging tests.
4646
"""
4747

48-
session.install("-r", "tests/requirements.txt")
48+
session.install("-r", "tests/requirements.txt", "pip")
4949
session.run("pytest", "tests/extra_python_package", *session.posargs)
5050

5151

pybind11/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ def _to_int(s: str) -> int | str:
88
return s
99

1010

11-
__version__ = "2.13.0.dev1"
11+
__version__ = "2.14.0.dev1"
1212
version_info = tuple(_to_int(s) for s in __version__.split("."))

setup.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ classifiers =
2020
Programming Language :: Python :: 3.10
2121
Programming Language :: Python :: 3.11
2222
Programming Language :: Python :: 3.12
23+
Programming Language :: Python :: 3.13
2324
License :: OSI Approved :: BSD License
2425
Programming Language :: Python :: Implementation :: PyPy
2526
Programming Language :: Python :: Implementation :: CPython

tests/test_pytypes.cpp

+56-1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,26 @@ void m_defs(py::module_ &m) {
109109

110110
} // namespace handle_from_move_only_type_with_operator_PyObject
111111

112+
#if defined(__cpp_nontype_template_parameter_class)
113+
namespace literals {
114+
enum Color { RED = 0, BLUE = 1 };
115+
116+
typedef py::typing::Literal<"26",
117+
"0x1A",
118+
"\"hello world\"",
119+
"b\"hello world\"",
120+
"u\"hello world\"",
121+
"True",
122+
"Color.RED",
123+
"None">
124+
LiteralFoo;
125+
} // namespace literals
126+
namespace typevar {
127+
typedef py::typing::TypeVar<"T"> TypeVarT;
128+
typedef py::typing::TypeVar<"V"> TypeVarV;
129+
} // namespace typevar
130+
#endif
131+
112132
TEST_SUBMODULE(pytypes, m) {
113133
m.def("obj_class_name", [](py::handle obj) { return py::detail::obj_class_name(obj.ptr()); });
114134

@@ -844,7 +864,8 @@ TEST_SUBMODULE(pytypes, m) {
844864
m.def("annotate_iterator_int", [](const py::typing::Iterator<int> &) {});
845865
m.def("annotate_fn",
846866
[](const py::typing::Callable<int(py::typing::List<py::str>, py::str)> &) {});
847-
m.def("annotate_type", [](const py::typing::Type<int> &) {});
867+
868+
m.def("annotate_type", [](const py::typing::Type<int> &t) -> py::type { return t; });
848869

849870
m.def("annotate_union",
850871
[](py::typing::List<py::typing::Union<py::str, py::int_, py::object>> l,
@@ -861,10 +882,44 @@ TEST_SUBMODULE(pytypes, m) {
861882
[](py::typing::List<py::typing::Union<py::str>> &l)
862883
-> py::typing::List<py::typing::Union<py::int_>> { return l; });
863884

885+
m.def("annotate_union_to_object",
886+
[](py::typing::Union<int, py::str> &o) -> py::object { return o; });
887+
864888
m.def("annotate_optional",
865889
[](py::list &list) -> py::typing::List<py::typing::Optional<py::str>> {
866890
list.append(py::str("hi"));
867891
list.append(py::none());
868892
return list;
869893
});
894+
895+
m.def("annotate_type_guard", [](py::object &o) -> py::typing::TypeGuard<py::str> {
896+
return py::isinstance<py::str>(o);
897+
});
898+
m.def("annotate_type_is",
899+
[](py::object &o) -> py::typing::TypeIs<py::str> { return py::isinstance<py::str>(o); });
900+
901+
m.def("annotate_no_return", []() -> py::typing::NoReturn { throw 0; });
902+
m.def("annotate_never", []() -> py::typing::Never { throw 0; });
903+
904+
m.def("annotate_optional_to_object",
905+
[](py::typing::Optional<int> &o) -> py::object { return o; });
906+
907+
#if defined(__cpp_nontype_template_parameter_class)
908+
py::enum_<literals::Color>(m, "Color")
909+
.value("RED", literals::Color::RED)
910+
.value("BLUE", literals::Color::BLUE);
911+
912+
m.def("annotate_literal", [](literals::LiteralFoo &o) -> py::object { return o; });
913+
m.def("annotate_generic_containers",
914+
[](const py::typing::List<typevar::TypeVarT> &l) -> py::typing::List<typevar::TypeVarV> {
915+
return l;
916+
});
917+
918+
m.def("annotate_listT_to_T",
919+
[](const py::typing::List<typevar::TypeVarT> &l) -> typevar::TypeVarT { return l[0]; });
920+
m.def("annotate_object_to_T", [](const py::object &o) -> typevar::TypeVarT { return o; });
921+
m.attr("if_defined__cpp_nontype_template_parameter_class") = true;
922+
#else
923+
m.attr("if_defined__cpp_nontype_template_parameter_class") = false;
924+
#endif
870925
}

0 commit comments

Comments
 (0)