Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion include/pybind11/pytypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1690,7 +1690,13 @@ class str : public object {
Return a string representation of the object. This is analogous to
the ``str()`` function in Python.
\endrst */
explicit str(handle h) : object(raw_str(h.ptr()), stolen_t{}) {
// Templatized to avoid ambiguity with str(const object&) for object-derived types.
template <typename T,
detail::enable_if_t<!std::is_base_of<object, detail::remove_cvref_t<T>>::value
&& std::is_constructible<handle, T>::value,
int>
= 0>
explicit str(T &&h) : object(raw_str(handle(std::forward<T>(h)).ptr()), stolen_t{}) {
if (!m_ptr) {
throw error_already_set();
}
Expand Down
6 changes: 6 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,12 @@ if(NOT PYBIND11_CUDA_TESTS)
endif()
endforeach()

if(SKBUILD)
foreach(mod IN LISTS PYBIND11_MULTIPLE_INTERPRETERS_TEST_MODULES)
install(TARGETS "${mod}" LIBRARY DESTINATION .)
endforeach()
endif()

if(PYBIND11_TEST_SMART_HOLDER)
foreach(mod IN LISTS PYBIND11_MULTIPLE_INTERPRETERS_TEST_MODULES)
target_compile_definitions(
Expand Down
1 change: 1 addition & 0 deletions tests/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sysconfig

ANDROID = sys.platform.startswith("android")
IOS = sys.platform.startswith("ios")
LINUX = sys.platform.startswith("linux")
MACOS = sys.platform.startswith("darwin")
WIN = sys.platform.startswith("win32") or sys.platform.startswith("cygwin")
Expand Down
4 changes: 3 additions & 1 deletion tests/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ PYBIND11_FINDPYTHON = true

[tool.cibuildwheel]
test-sources = ["tests", "pyproject.toml"]
test-command = "python -m pytest -o timeout=0 -p no:cacheprovider tests"
test-command = "python -m pytest -v -o timeout=120 -p no:cacheprovider tests"
# Pyodide doesn't have signal.setitimer, so pytest-timeout can't work with timeout > 0
pyodide.test-command = "python -m pytest -v -o timeout=0 -p no:cacheprovider tests"
environment.PIP_ONLY_BINARY = "numpy"
environment.PIP_PREFER_BINARY = "1"

Expand Down
1 change: 1 addition & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ numpy~=1.22.2; platform_python_implementation=="CPython" and python_version=="3.
numpy~=1.26.0; platform_python_implementation=="CPython" and python_version>="3.11" and python_version<"3.13" and platform_machine!="ARM64"
numpy~=2.3.0; platform_python_implementation=="CPython" and python_version>="3.11" and platform_machine=="ARM64"
numpy~=2.2.0; platform_python_implementation=="CPython" and python_version=="3.13" and platform_machine!="ARM64"
numpy==2.4.0; platform_python_implementation=="CPython" and python_version>="3.14"
pytest>=6
pytest-timeout
scipy~=1.5.4; platform_python_implementation=="CPython" and python_version<"3.10"
Expand Down
4 changes: 4 additions & 0 deletions tests/test_multiple_interpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@

import pytest

import env
import pybind11_tests

if env.IOS:
pytest.skip("Subinterpreters not supported on iOS", allow_module_level=True)

# 3.14.0b3+, though sys.implementation.supports_isolated_interpreters is being added in b4
# Can be simplified when we drop support for the first three betas
CONCURRENT_INTERPRETERS_SUPPORT = (
Expand Down
2 changes: 2 additions & 0 deletions tests/test_pytypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1211,4 +1211,6 @@ TEST_SUBMODULE(pytypes, m) {
m.def("check_type_is", [](const py::object &x) -> py::typing::TypeIs<RealNumber> {
return py::isinstance<RealNumber>(x);
});

m.def("const_kwargs_ref_to_str", [](const py::kwargs &kwargs) { return py::str(kwargs); });
}
5 changes: 5 additions & 0 deletions tests/test_pytypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1367,3 +1367,8 @@ def test_arg_return_type_hints(doc, backport_typehints):
backport_typehints(doc(m.check_type_guard))
== "check_type_guard(arg0: list[object]) -> typing.TypeGuard[list[float]]"
)


def test_const_kwargs_ref_to_str():
assert m.const_kwargs_ref_to_str() == "{}"
assert m.const_kwargs_ref_to_str(a=1) == "{'a': 1}"
Loading