mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-26 23:22:01 +00:00
Merge branch 'pybind:master' into master
This commit is contained in:
commit
f72d4c438f
2
.github/workflows/pip.yml
vendored
2
.github/workflows/pip.yml
vendored
@ -58,7 +58,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Prepare env
|
- name: Prepare env
|
||||||
run: |
|
run: |
|
||||||
python -m pip install -r tests/requirements.txt build twine!=5.1.0
|
python -m pip install -r tests/requirements.txt build twine
|
||||||
|
|
||||||
- name: Python Packaging tests
|
- name: Python Packaging tests
|
||||||
run: pytest tests/extra_python_package/
|
run: pytest tests/extra_python_package/
|
||||||
|
@ -15,6 +15,20 @@ IN DEVELOPMENT
|
|||||||
|
|
||||||
Changes will be summarized here periodically.
|
Changes will be summarized here periodically.
|
||||||
|
|
||||||
|
Version 2.13.1 (June 26, 2024)
|
||||||
|
------------------------------
|
||||||
|
|
||||||
|
New Features:
|
||||||
|
|
||||||
|
* Add support for ``Typing.Callable[..., T]``.
|
||||||
|
`#5202 <https://github.com/pybind/pybind11/pull/5202>`_
|
||||||
|
|
||||||
|
Bug fixes:
|
||||||
|
|
||||||
|
* Avoid aligned allocation in free-threaded build in order to support macOS
|
||||||
|
versions before 10.14.
|
||||||
|
`#5200 <https://github.com/pybind/pybind11/pull/5200>`_
|
||||||
|
|
||||||
Version 2.13.0 (June 25, 2024)
|
Version 2.13.0 (June 25, 2024)
|
||||||
------------------------------
|
------------------------------
|
||||||
|
|
||||||
@ -33,11 +47,15 @@ New Features:
|
|||||||
|
|
||||||
.. feat(types)
|
.. feat(types)
|
||||||
|
|
||||||
* Support for ``type[T]`` was added to pybind11/typing.h.
|
* Support for ``Union``, ``Optional``, ``type[T]``, ``typing.TypeGuard``,
|
||||||
|
``typing.TypeIs``, ``typing.Never``, ``typing.NoReturn`` and
|
||||||
|
``typing.Literal`` was added to ``pybind11/typing.h``.
|
||||||
`#5166 <https://github.com/pybind/pybind11/pull/5166>`_
|
`#5166 <https://github.com/pybind/pybind11/pull/5166>`_
|
||||||
|
|
||||||
* ``Union`` and ``Optional`` were added to ``pybind11/typing.h``.
|
|
||||||
`#5165 <https://github.com/pybind/pybind11/pull/5165>`_
|
`#5165 <https://github.com/pybind/pybind11/pull/5165>`_
|
||||||
|
`#5194 <https://github.com/pybind/pybind11/pull/5194>`_
|
||||||
|
`#5193 <https://github.com/pybind/pybind11/pull/5193>`_
|
||||||
|
`#5192 <https://github.com/pybind/pybind11/pull/5192>`_
|
||||||
|
|
||||||
|
|
||||||
.. feat(cmake)
|
.. feat(cmake)
|
||||||
|
|
||||||
@ -93,6 +111,9 @@ CI:
|
|||||||
* Use ``macos-13`` (Intel) for CI jobs for now (will drop Python 3.7 soon).
|
* Use ``macos-13`` (Intel) for CI jobs for now (will drop Python 3.7 soon).
|
||||||
`#5109 <https://github.com/pybind/pybind11/pull/5109>`_
|
`#5109 <https://github.com/pybind/pybind11/pull/5109>`_
|
||||||
|
|
||||||
|
* Releases now have artifact attestations, visible at
|
||||||
|
https://github.com/pybind/pybind11/attestations.
|
||||||
|
`#5196 <https://github.com/pybind/pybind11/pull/5196>`_
|
||||||
|
|
||||||
Other:
|
Other:
|
||||||
|
|
||||||
|
@ -10,12 +10,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define PYBIND11_VERSION_MAJOR 2
|
#define PYBIND11_VERSION_MAJOR 2
|
||||||
#define PYBIND11_VERSION_MINOR 13
|
#define PYBIND11_VERSION_MINOR 14
|
||||||
#define PYBIND11_VERSION_PATCH 0.dev1
|
#define PYBIND11_VERSION_PATCH 0.dev1
|
||||||
|
|
||||||
// Similar to Python's convention: https://docs.python.org/3/c-api/apiabiversion.html
|
// Similar to Python's convention: https://docs.python.org/3/c-api/apiabiversion.html
|
||||||
// Additional convention: 0xD = dev
|
// Additional convention: 0xD = dev
|
||||||
#define PYBIND11_VERSION_HEX 0x020D00D1
|
#define PYBIND11_VERSION_HEX 0x020E00D1
|
||||||
|
|
||||||
// Define some generic pybind11 helper macros for warning management.
|
// Define some generic pybind11 helper macros for warning management.
|
||||||
//
|
//
|
||||||
|
@ -148,18 +148,14 @@ struct override_hash {
|
|||||||
|
|
||||||
using instance_map = std::unordered_multimap<const void *, instance *>;
|
using instance_map = std::unordered_multimap<const void *, instance *>;
|
||||||
|
|
||||||
// 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.
|
// 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;
|
std::mutex mutex;
|
||||||
instance_map registered_instances;
|
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.
|
/// Internal data structure used to track registered instances and types.
|
||||||
/// Whenever binary incompatible changes are made to this structure,
|
/// Whenever binary incompatible changes are made to this structure,
|
||||||
/// `PYBIND11_INTERNALS_VERSION` must be incremented.
|
/// `PYBIND11_INTERNALS_VERSION` must be incremented.
|
||||||
|
@ -80,6 +80,16 @@ class Optional : public object {
|
|||||||
using object::object;
|
using object::object;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class TypeGuard : public bool_ {
|
||||||
|
using bool_::bool_;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class TypeIs : public bool_ {
|
||||||
|
using bool_::bool_;
|
||||||
|
};
|
||||||
|
|
||||||
class NoReturn : public none {
|
class NoReturn : public none {
|
||||||
using none::none;
|
using none::none;
|
||||||
};
|
};
|
||||||
@ -87,6 +97,7 @@ class NoReturn : public none {
|
|||||||
class Never : public none {
|
class Never : public none {
|
||||||
using none::none;
|
using none::none;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined(__cpp_nontype_template_parameter_class)
|
#if defined(__cpp_nontype_template_parameter_class)
|
||||||
template <size_t N>
|
template <size_t N>
|
||||||
struct StringLiteral {
|
struct StringLiteral {
|
||||||
@ -166,6 +177,14 @@ struct handle_type_name<typing::Callable<Return(Args...)>> {
|
|||||||
+ const_name("], ") + make_caster<retval_type>::name + const_name("]");
|
+ const_name("], ") + make_caster<retval_type>::name + const_name("]");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename Return>
|
||||||
|
struct handle_type_name<typing::Callable<Return(ellipsis)>> {
|
||||||
|
// PEP 484 specifies this syntax for defining only return types of callables
|
||||||
|
using retval_type = conditional_t<std::is_same<Return, void>::value, void_type, Return>;
|
||||||
|
static constexpr auto name
|
||||||
|
= const_name("Callable[..., ") + make_caster<retval_type>::name + const_name("]");
|
||||||
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct handle_type_name<typing::Type<T>> {
|
struct handle_type_name<typing::Type<T>> {
|
||||||
static constexpr auto name = const_name("type[") + make_caster<T>::name + const_name("]");
|
static constexpr auto name = const_name("type[") + make_caster<T>::name + const_name("]");
|
||||||
@ -183,6 +202,16 @@ struct handle_type_name<typing::Optional<T>> {
|
|||||||
static constexpr auto name = const_name("Optional[") + make_caster<T>::name + const_name("]");
|
static constexpr auto name = const_name("Optional[") + make_caster<T>::name + const_name("]");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct handle_type_name<typing::TypeGuard<T>> {
|
||||||
|
static constexpr auto name = const_name("TypeGuard[") + make_caster<T>::name + const_name("]");
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct handle_type_name<typing::TypeIs<T>> {
|
||||||
|
static constexpr auto name = const_name("TypeIs[") + make_caster<T>::name + const_name("]");
|
||||||
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct handle_type_name<typing::NoReturn> {
|
struct handle_type_name<typing::NoReturn> {
|
||||||
static constexpr auto name = const_name("NoReturn");
|
static constexpr auto name = const_name("NoReturn");
|
||||||
@ -192,6 +221,7 @@ template <>
|
|||||||
struct handle_type_name<typing::Never> {
|
struct handle_type_name<typing::Never> {
|
||||||
static constexpr auto name = const_name("Never");
|
static constexpr auto name = const_name("Never");
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined(__cpp_nontype_template_parameter_class)
|
#if defined(__cpp_nontype_template_parameter_class)
|
||||||
template <typing::StringLiteral... Literals>
|
template <typing::StringLiteral... Literals>
|
||||||
struct handle_type_name<typing::Literal<Literals...>> {
|
struct handle_type_name<typing::Literal<Literals...>> {
|
||||||
|
@ -45,7 +45,7 @@ def tests_packaging(session: nox.Session) -> None:
|
|||||||
Run the packaging tests.
|
Run the packaging tests.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
session.install("-r", "tests/requirements.txt")
|
session.install("-r", "tests/requirements.txt", "pip")
|
||||||
session.run("pytest", "tests/extra_python_package", *session.posargs)
|
session.run("pytest", "tests/extra_python_package", *session.posargs)
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,5 +8,5 @@ def _to_int(s: str) -> int | str:
|
|||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
__version__ = "2.13.0.dev1"
|
__version__ = "2.14.0.dev1"
|
||||||
version_info = tuple(_to_int(s) for s in __version__.split("."))
|
version_info = tuple(_to_int(s) for s in __version__.split("."))
|
||||||
|
@ -865,6 +865,7 @@ TEST_SUBMODULE(pytypes, m) {
|
|||||||
m.def("annotate_fn",
|
m.def("annotate_fn",
|
||||||
[](const py::typing::Callable<int(py::typing::List<py::str>, py::str)> &) {});
|
[](const py::typing::Callable<int(py::typing::List<py::str>, py::str)> &) {});
|
||||||
|
|
||||||
|
m.def("annotate_fn_only_return", [](const py::typing::Callable<int(py::ellipsis)> &) {});
|
||||||
m.def("annotate_type", [](const py::typing::Type<int> &t) -> py::type { return t; });
|
m.def("annotate_type", [](const py::typing::Type<int> &t) -> py::type { return t; });
|
||||||
|
|
||||||
m.def("annotate_union",
|
m.def("annotate_union",
|
||||||
@ -892,8 +893,15 @@ TEST_SUBMODULE(pytypes, m) {
|
|||||||
return list;
|
return list;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
m.def("annotate_type_guard", [](py::object &o) -> py::typing::TypeGuard<py::str> {
|
||||||
|
return py::isinstance<py::str>(o);
|
||||||
|
});
|
||||||
|
m.def("annotate_type_is",
|
||||||
|
[](py::object &o) -> py::typing::TypeIs<py::str> { return py::isinstance<py::str>(o); });
|
||||||
|
|
||||||
m.def("annotate_no_return", []() -> py::typing::NoReturn { throw 0; });
|
m.def("annotate_no_return", []() -> py::typing::NoReturn { throw 0; });
|
||||||
m.def("annotate_never", []() -> py::typing::Never { throw 0; });
|
m.def("annotate_never", []() -> py::typing::Never { throw 0; });
|
||||||
|
|
||||||
m.def("annotate_optional_to_object",
|
m.def("annotate_optional_to_object",
|
||||||
[](py::typing::Optional<int> &o) -> py::object { return o; });
|
[](py::typing::Optional<int> &o) -> py::object { return o; });
|
||||||
|
|
||||||
|
@ -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):
|
def test_type_annotation(doc):
|
||||||
assert doc(m.annotate_type) == "annotate_type(arg0: type[int]) -> type"
|
assert doc(m.annotate_type) == "annotate_type(arg0: type[int]) -> type"
|
||||||
|
|
||||||
@ -991,6 +998,17 @@ def test_optional_annotations(doc):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_type_guard_annotations(doc):
|
||||||
|
assert (
|
||||||
|
doc(m.annotate_type_guard)
|
||||||
|
== "annotate_type_guard(arg0: object) -> TypeGuard[str]"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_type_is_annotations(doc):
|
||||||
|
assert doc(m.annotate_type_is) == "annotate_type_is(arg0: object) -> TypeIs[str]"
|
||||||
|
|
||||||
|
|
||||||
def test_no_return_annotation(doc):
|
def test_no_return_annotation(doc):
|
||||||
assert doc(m.annotate_no_return) == "annotate_no_return() -> NoReturn"
|
assert doc(m.annotate_no_return) == "annotate_no_return() -> NoReturn"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user