mirror of
https://github.com/pybind/pybind11.git
synced 2025-02-20 15:40:45 +00:00
Merge branch 'master' into sh_merge_master
This commit is contained in:
commit
c7a0c882c6
16
.github/workflows/ci.yml
vendored
16
.github/workflows/ci.yml
vendored
@ -81,7 +81,7 @@ jobs:
|
||||
run: brew install boost
|
||||
|
||||
- name: Update CMake
|
||||
uses: jwlawson/actions-setup-cmake@v1.12
|
||||
uses: jwlawson/actions-setup-cmake@v1.13
|
||||
|
||||
- name: Cache wheels
|
||||
if: runner.os == 'macOS'
|
||||
@ -203,7 +203,7 @@ jobs:
|
||||
debug: ${{ matrix.python-debug }}
|
||||
|
||||
- name: Update CMake
|
||||
uses: jwlawson/actions-setup-cmake@v1.12
|
||||
uses: jwlawson/actions-setup-cmake@v1.13
|
||||
|
||||
- name: Valgrind cache
|
||||
if: matrix.valgrind
|
||||
@ -466,7 +466,7 @@ jobs:
|
||||
run: python3 -m pip install --upgrade pip
|
||||
|
||||
- name: Update CMake
|
||||
uses: jwlawson/actions-setup-cmake@v1.12
|
||||
uses: jwlawson/actions-setup-cmake@v1.13
|
||||
|
||||
- name: Configure
|
||||
shell: bash
|
||||
@ -755,10 +755,10 @@ jobs:
|
||||
architecture: x86
|
||||
|
||||
- name: Update CMake
|
||||
uses: jwlawson/actions-setup-cmake@v1.12
|
||||
uses: jwlawson/actions-setup-cmake@v1.13
|
||||
|
||||
- name: Prepare MSVC
|
||||
uses: ilammy/msvc-dev-cmd@v1.11.0
|
||||
uses: ilammy/msvc-dev-cmd@v1.12.0
|
||||
with:
|
||||
arch: x86
|
||||
|
||||
@ -808,10 +808,10 @@ jobs:
|
||||
architecture: x86
|
||||
|
||||
- name: Update CMake
|
||||
uses: jwlawson/actions-setup-cmake@v1.12
|
||||
uses: jwlawson/actions-setup-cmake@v1.13
|
||||
|
||||
- name: Prepare MSVC
|
||||
uses: ilammy/msvc-dev-cmd@v1.11.0
|
||||
uses: ilammy/msvc-dev-cmd@v1.12.0
|
||||
with:
|
||||
arch: x86
|
||||
|
||||
@ -859,7 +859,7 @@ jobs:
|
||||
python3 -m pip install -r tests/requirements.txt
|
||||
|
||||
- name: Update CMake
|
||||
uses: jwlawson/actions-setup-cmake@v1.12
|
||||
uses: jwlawson/actions-setup-cmake@v1.13
|
||||
|
||||
- name: Configure C++20
|
||||
run: >
|
||||
|
2
.github/workflows/configure.yml
vendored
2
.github/workflows/configure.yml
vendored
@ -52,7 +52,7 @@ jobs:
|
||||
# An action for adding a specific version of CMake:
|
||||
# https://github.com/jwlawson/actions-setup-cmake
|
||||
- name: Setup CMake ${{ matrix.cmake }}
|
||||
uses: jwlawson/actions-setup-cmake@v1.12
|
||||
uses: jwlawson/actions-setup-cmake@v1.13
|
||||
with:
|
||||
cmake-version: ${{ matrix.cmake }}
|
||||
|
||||
|
2
.github/workflows/upstream.yml
vendored
2
.github/workflows/upstream.yml
vendored
@ -31,7 +31,7 @@ jobs:
|
||||
run: sudo apt-get install libboost-dev
|
||||
|
||||
- name: Update CMake
|
||||
uses: jwlawson/actions-setup-cmake@v1.12
|
||||
uses: jwlawson/actions-setup-cmake@v1.13
|
||||
|
||||
- name: Prepare env
|
||||
run: |
|
||||
|
@ -1382,7 +1382,7 @@ public:
|
||||
private:
|
||||
void advance() {
|
||||
value = reinterpret_steal<object>(PyIter_Next(m_ptr));
|
||||
if (PyErr_Occurred()) {
|
||||
if (value.ptr() == nullptr && PyErr_Occurred()) {
|
||||
throw error_already_set();
|
||||
}
|
||||
}
|
||||
@ -1809,16 +1809,16 @@ public:
|
||||
|
||||
explicit capsule(const void *value,
|
||||
const char *name = nullptr,
|
||||
void (*destructor)(PyObject *) = nullptr)
|
||||
PyCapsule_Destructor destructor = nullptr)
|
||||
: object(PyCapsule_New(const_cast<void *>(value), name, destructor), stolen_t{}) {
|
||||
if (!m_ptr) {
|
||||
throw error_already_set();
|
||||
}
|
||||
}
|
||||
|
||||
PYBIND11_DEPRECATED("Please pass a destructor that takes a void pointer as input")
|
||||
capsule(const void *value, void (*destruct)(PyObject *))
|
||||
: object(PyCapsule_New(const_cast<void *>(value), nullptr, destruct), stolen_t{}) {
|
||||
PYBIND11_DEPRECATED("Please use the ctor with value, name, destructor args")
|
||||
capsule(const void *value, PyCapsule_Destructor destructor)
|
||||
: object(PyCapsule_New(const_cast<void *>(value), nullptr, destructor), stolen_t{}) {
|
||||
if (!m_ptr) {
|
||||
throw error_already_set();
|
||||
}
|
||||
@ -1829,7 +1829,7 @@ public:
|
||||
// guard if destructor called while err indicator is set
|
||||
error_scope error_guard;
|
||||
auto destructor = reinterpret_cast<void (*)(void *)>(PyCapsule_GetContext(o));
|
||||
if (PyErr_Occurred()) {
|
||||
if (destructor == nullptr && PyErr_Occurred()) {
|
||||
throw error_already_set();
|
||||
}
|
||||
const char *name = get_name_in_error_scope(o);
|
||||
@ -1843,7 +1843,7 @@ public:
|
||||
}
|
||||
});
|
||||
|
||||
if (!m_ptr || PyCapsule_SetContext(m_ptr, (void *) destructor) != 0) {
|
||||
if (!m_ptr || PyCapsule_SetContext(m_ptr, reinterpret_cast<void *>(destructor)) != 0) {
|
||||
throw error_already_set();
|
||||
}
|
||||
}
|
||||
@ -1967,7 +1967,11 @@ public:
|
||||
void clear() /* py-non-const */ { PyDict_Clear(ptr()); }
|
||||
template <typename T>
|
||||
bool contains(T &&key) const {
|
||||
return PyDict_Contains(m_ptr, detail::object_or_cast(std::forward<T>(key)).ptr()) == 1;
|
||||
auto result = PyDict_Contains(m_ptr, detail::object_or_cast(std::forward<T>(key)).ptr());
|
||||
if (result == -1) {
|
||||
throw error_already_set();
|
||||
}
|
||||
return result == 1;
|
||||
}
|
||||
|
||||
private:
|
||||
@ -2053,7 +2057,11 @@ public:
|
||||
bool empty() const { return size() == 0; }
|
||||
template <typename T>
|
||||
bool contains(T &&val) const {
|
||||
return PySet_Contains(m_ptr, detail::object_or_cast(std::forward<T>(val)).ptr()) == 1;
|
||||
auto result = PySet_Contains(m_ptr, detail::object_or_cast(std::forward<T>(val)).ptr());
|
||||
if (result == -1) {
|
||||
throw error_already_set();
|
||||
}
|
||||
return result == 1;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -183,7 +183,7 @@ TEST_SUBMODULE(pytypes, m) {
|
||||
return d2;
|
||||
});
|
||||
m.def("dict_contains",
|
||||
[](const py::dict &dict, py::object val) { return dict.contains(val); });
|
||||
[](const py::dict &dict, const py::object &val) { return dict.contains(val); });
|
||||
m.def("dict_contains",
|
||||
[](const py::dict &dict, const char *val) { return dict.contains(val); });
|
||||
|
||||
@ -538,6 +538,9 @@ TEST_SUBMODULE(pytypes, m) {
|
||||
|
||||
m.def("hash_function", [](py::object obj) { return py::hash(std::move(obj)); });
|
||||
|
||||
m.def("obj_contains",
|
||||
[](py::object &obj, const py::object &key) { return obj.contains(key); });
|
||||
|
||||
m.def("test_number_protocol", [](const py::object &a, const py::object &b) {
|
||||
py::list l;
|
||||
l.append(a.equal(b));
|
||||
|
@ -168,6 +168,31 @@ def test_dict(capture, doc):
|
||||
assert m.dict_keyword_constructor() == {"x": 1, "y": 2, "z": 3}
|
||||
|
||||
|
||||
class CustomContains:
|
||||
d = {"key": None}
|
||||
|
||||
def __contains__(self, m):
|
||||
return m in self.d
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"arg,func",
|
||||
[
|
||||
(set(), m.anyset_contains),
|
||||
(dict(), m.dict_contains),
|
||||
(CustomContains(), m.obj_contains),
|
||||
],
|
||||
)
|
||||
@pytest.mark.xfail("env.PYPY and sys.pypy_version_info < (7, 3, 10)", strict=False)
|
||||
def test_unhashable_exceptions(arg, func):
|
||||
class Unhashable:
|
||||
__hash__ = None
|
||||
|
||||
with pytest.raises(TypeError) as exc_info:
|
||||
func(arg, Unhashable())
|
||||
assert "unhashable type:" in str(exc_info.value)
|
||||
|
||||
|
||||
def test_tuple():
|
||||
assert m.tuple_no_args() == ()
|
||||
assert m.tuple_ssize_t() == ()
|
||||
|
Loading…
Reference in New Issue
Block a user