Skip to content

Commit 6b771d5

Browse files
committed
Merge branch 'master' into annotated_any
2 parents 65661fe + eeac2f4 commit 6b771d5

File tree

23 files changed

+201
-69
lines changed

23 files changed

+201
-69
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,9 @@ jobs:
7272
- uses: actions/checkout@v4
7373

7474
- name: Setup Python ${{ matrix.python }}
75-
uses: actions/setup-python@v4
75+
uses: actions/setup-python@v5
7676
with:
7777
python-version: ${{ matrix.python }}
78-
allow-prereleases: true
7978

8079
- name: Setup Boost (Linux)
8180
# Can't use boost + define _
@@ -209,7 +208,7 @@ jobs:
209208
- uses: actions/checkout@v4
210209

211210
- name: Setup Python ${{ matrix.python-version }} (deadsnakes)
212-
uses: deadsnakes/action@v3.0.1
211+
uses: deadsnakes/action@v3.1.0
213212
with:
214213
python-version: ${{ matrix.python-version }}
215214
debug: ${{ matrix.python-debug }}
@@ -739,7 +738,7 @@ jobs:
739738
steps:
740739
- uses: actions/checkout@v4
741740

742-
- uses: actions/setup-python@v4
741+
- uses: actions/setup-python@v5
743742
with:
744743
python-version: "3.x"
745744

@@ -792,7 +791,7 @@ jobs:
792791
- uses: actions/checkout@v4
793792

794793
- name: Setup Python ${{ matrix.python }}
795-
uses: actions/setup-python@v4
794+
uses: actions/setup-python@v5
796795
with:
797796
python-version: ${{ matrix.python }}
798797
architecture: x86
@@ -845,7 +844,7 @@ jobs:
845844
- uses: actions/checkout@v4
846845

847846
- name: Setup Python ${{ matrix.python }}
848-
uses: actions/setup-python@v4
847+
uses: actions/setup-python@v5
849848
with:
850849
python-version: ${{ matrix.python }}
851850
architecture: x86
@@ -893,7 +892,7 @@ jobs:
893892
- uses: actions/checkout@v4
894893

895894
- name: Setup Python ${{ matrix.python }}
896-
uses: actions/setup-python@v4
895+
uses: actions/setup-python@v5
897896
with:
898897
python-version: ${{ matrix.python }}
899898

@@ -973,7 +972,10 @@ jobs:
973972
- name: Configure C++11
974973
# LTO leads to many undefined reference like
975974
# `pybind11::detail::function_call::function_call(pybind11::detail::function_call&&)
976-
run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=11 -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -S . -B build
975+
run: >-
976+
cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=11 -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON
977+
-DPYTHON_EXECUTABLE=$(python -c "import sys; print(sys.executable)")
978+
-S . -B build
977979
978980
- name: Build C++11
979981
run: cmake --build build -j 2
@@ -991,7 +993,10 @@ jobs:
991993
run: git clean -fdx
992994

993995
- name: Configure C++14
994-
run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=14 -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -S . -B build2
996+
run: >-
997+
cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=14 -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON
998+
-DPYTHON_EXECUTABLE=$(python -c "import sys; print(sys.executable)")
999+
-S . -B build2
9951000
9961001
- name: Build C++14
9971002
run: cmake --build build2 -j 2
@@ -1009,7 +1014,10 @@ jobs:
10091014
run: git clean -fdx
10101015

10111016
- name: Configure C++17
1012-
run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=17 -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -S . -B build3
1017+
run: >-
1018+
cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=17 -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON
1019+
-DPYTHON_EXECUTABLE=$(python -c "import sys; print(sys.executable)")
1020+
-S . -B build3
10131021
10141022
- name: Build C++17
10151023
run: cmake --build build3 -j 2
@@ -1045,7 +1053,7 @@ jobs:
10451053
uses: egor-tensin/setup-clang@v1
10461054

10471055
- name: Setup Python ${{ matrix.python }}
1048-
uses: actions/setup-python@v4
1056+
uses: actions/setup-python@v5
10491057
with:
10501058
python-version: ${{ matrix.python }}
10511059

.github/workflows/configure.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
- uses: actions/checkout@v4
5353

5454
- name: Setup Python 3.7
55-
uses: actions/setup-python@v4
55+
uses: actions/setup-python@v5
5656
with:
5757
python-version: 3.7
5858
architecture: ${{ matrix.arch }}

.github/workflows/format.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
runs-on: ubuntu-latest
2727
steps:
2828
- uses: actions/checkout@v4
29-
- uses: actions/setup-python@v4
29+
- uses: actions/setup-python@v5
3030
with:
3131
python-version: "3.x"
3232
- name: Add matchers

.github/workflows/pip.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- uses: actions/checkout@v4
3232

3333
- name: Setup 🐍 3.6
34-
uses: actions/setup-python@v4
34+
uses: actions/setup-python@v5
3535
with:
3636
python-version: 3.6
3737

@@ -53,7 +53,7 @@ jobs:
5353
- uses: actions/checkout@v4
5454

5555
- name: Setup 🐍 3.8
56-
uses: actions/setup-python@v4
56+
uses: actions/setup-python@v5
5757
with:
5858
python-version: 3.8
5959

@@ -73,13 +73,13 @@ jobs:
7373
run: twine check dist/*
7474

7575
- name: Save standard package
76-
uses: actions/upload-artifact@v3
76+
uses: actions/upload-artifact@v4
7777
with:
7878
name: standard
7979
path: dist/pybind11-*
8080

8181
- name: Save global package
82-
uses: actions/upload-artifact@v3
82+
uses: actions/upload-artifact@v4
8383
with:
8484
name: global
8585
path: dist/pybind11_global-*
@@ -94,12 +94,12 @@ jobs:
9494
needs: [packaging]
9595

9696
steps:
97-
- uses: actions/setup-python@v4
97+
- uses: actions/setup-python@v5
9898
with:
9999
python-version: "3.x"
100100

101101
# Downloads all to directories matching the artifact names
102-
- uses: actions/download-artifact@v3
102+
- uses: actions/download-artifact@v4
103103

104104
- name: Publish standard package
105105
uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/upstream.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@ concurrency:
1313

1414
env:
1515
PIP_BREAK_SYSTEM_PACKAGES: 1
16-
PIP_ONLY_BINARY: ":all:"
1716
# For cmake:
1817
VERBOSE: 1
1918

2019
jobs:
2120
standard:
22-
name: "🐍 3.12 latest • ubuntu-latest • x64"
21+
name: "🐍 3.13 latest • ubuntu-latest • x64"
2322
runs-on: ubuntu-latest
2423
# Only runs when the 'python dev' label is selected
2524
if: "contains(github.event.pull_request.labels.*.name, 'python dev')"
2625

2726
steps:
2827
- uses: actions/checkout@v4
2928

30-
- name: Setup Python 3.12
31-
uses: actions/setup-python@v4
29+
- name: Setup Python 3.13
30+
uses: actions/setup-python@v5
3231
with:
33-
python-version: "3.12-dev"
32+
python-version: "3.13"
33+
allow-prereleases: true
3434

3535
- name: Setup Boost
3636
run: sudo apt-get install libboost-dev

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@ repos:
2525

2626
# Clang format the codebase automatically
2727
- repo: https://github.com/pre-commit/mirrors-clang-format
28-
rev: "v17.0.4"
28+
rev: "v17.0.6"
2929
hooks:
3030
- id: clang-format
3131
types_or: [c++, c, cuda]
3232

3333
# Ruff, the Python auto-correcting linter/formatter written in Rust
3434
- repo: https://github.com/astral-sh/ruff-pre-commit
35-
rev: v0.1.4
35+
rev: v0.1.6
3636
hooks:
3737
- id: ruff
3838
args: ["--fix", "--show-fixes"]
3939
- id: ruff-format
4040

4141
# Check static types with mypy
4242
- repo: https://github.com/pre-commit/mirrors-mypy
43-
rev: "v1.6.1"
43+
rev: "v1.7.1"
4444
hooks:
4545
- id: mypy
4646
args: []
@@ -93,7 +93,7 @@ repos:
9393

9494
# Avoid directional quotes
9595
- repo: https://github.com/sirosen/texthooks
96-
rev: "0.6.2"
96+
rev: "0.6.3"
9797
hooks:
9898
- id: fix-ligatures
9999
- id: fix-smartquotes

CMakeLists.txt

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ endif()
1212

1313
cmake_minimum_required(VERSION 3.5)
1414

15-
# The `cmake_minimum_required(VERSION 3.5...3.26)` syntax does not work with
15+
# The `cmake_minimum_required(VERSION 3.5...3.27)` syntax does not work with
1616
# some versions of VS that have a patched CMake 3.11. This forces us to emulate
1717
# the behavior using the following workaround:
18-
if(${CMAKE_VERSION} VERSION_LESS 3.26)
18+
if(${CMAKE_VERSION} VERSION_LESS 3.27)
1919
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
2020
else()
21-
cmake_policy(VERSION 3.26)
21+
cmake_policy(VERSION 3.27)
2222
endif()
2323

2424
if(_pybind11_cmp0148)
@@ -92,9 +92,15 @@ if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
9292
set(pybind11_system "")
9393

9494
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
95+
if(CMAKE_VERSION VERSION_LESS "3.18")
96+
set(_pybind11_findpython_default OFF)
97+
else()
98+
set(_pybind11_findpython_default ON)
99+
endif()
95100
else()
96101
set(PYBIND11_MASTER_PROJECT OFF)
97102
set(pybind11_system SYSTEM)
103+
set(_pybind11_findpython_default OFF)
98104
endif()
99105

100106
# Options
@@ -116,9 +122,18 @@ cmake_dependent_option(
116122
"Install pybind11 headers in Python include directory instead of default installation prefix"
117123
OFF "PYBIND11_INSTALL" OFF)
118124

119-
cmake_dependent_option(PYBIND11_FINDPYTHON "Force new FindPython" OFF
125+
cmake_dependent_option(PYBIND11_FINDPYTHON "Force new FindPython" ${_pybind11_findpython_default}
120126
"NOT CMAKE_VERSION VERSION_LESS 3.12" OFF)
121127

128+
# Allow PYTHON_EXECUTABLE if in FINDPYTHON mode and building pybind11's tests
129+
# (makes transition easier while we support both modes).
130+
if(PYBIND11_MASTER_PROJECT
131+
AND PYBIND11_FINDPYTHON
132+
AND DEFINED PYTHON_EXECUTABLE
133+
AND NOT DEFINED Python_EXECUTABLE)
134+
set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}")
135+
endif()
136+
122137
# NB: when adding a header don't forget to also add it to setup.py
123138
set(PYBIND11_HEADERS
124139
include/pybind11/detail/class.h

docs/advanced/embedding.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ information, see :doc:`/compiling`.
1818

1919
.. code-block:: cmake
2020
21-
cmake_minimum_required(VERSION 3.5...3.26)
21+
cmake_minimum_required(VERSION 3.5...3.27)
2222
project(example)
2323
2424
find_package(pybind11 REQUIRED) # or `add_subdirectory(pybind11)`

docs/compiling.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ extension module can be created with just a few lines of code:
241241

242242
.. code-block:: cmake
243243
244-
cmake_minimum_required(VERSION 3.5...3.26)
244+
cmake_minimum_required(VERSION 3.5...3.27)
245245
project(example LANGUAGES CXX)
246246
247247
add_subdirectory(pybind11)
@@ -498,7 +498,7 @@ You can use these targets to build complex applications. For example, the
498498

499499
.. code-block:: cmake
500500
501-
cmake_minimum_required(VERSION 3.5...3.26)
501+
cmake_minimum_required(VERSION 3.5...3.27)
502502
project(example LANGUAGES CXX)
503503
504504
find_package(pybind11 REQUIRED) # or add_subdirectory(pybind11)
@@ -556,7 +556,7 @@ information about usage in C++, see :doc:`/advanced/embedding`.
556556

557557
.. code-block:: cmake
558558
559-
cmake_minimum_required(VERSION 3.5...3.26)
559+
cmake_minimum_required(VERSION 3.5...3.27)
560560
project(example LANGUAGES CXX)
561561
562562
find_package(pybind11 REQUIRED) # or add_subdirectory(pybind11)

include/pybind11/detail/class.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,16 @@ inline PyTypeObject *make_static_property_type() {
8686
type->tp_descr_get = pybind11_static_get;
8787
type->tp_descr_set = pybind11_static_set;
8888

89-
if (PyType_Ready(type) < 0) {
90-
pybind11_fail("make_static_property_type(): failure in PyType_Ready()!");
91-
}
92-
9389
# if PY_VERSION_HEX >= 0x030C0000
94-
// PRE 3.12 FEATURE FREEZE. PLEASE REVIEW AFTER FREEZE.
9590
// Since Python-3.12 property-derived types are required to
9691
// have dynamic attributes (to set `__doc__`)
9792
enable_dynamic_attributes(heap_type);
9893
# endif
9994

95+
if (PyType_Ready(type) < 0) {
96+
pybind11_fail("make_static_property_type(): failure in PyType_Ready()!");
97+
}
98+
10099
setattr((PyObject *) type, "__module__", str("pybind11_builtins"));
101100
PYBIND11_SET_OLDPY_QUALNAME(type, name_obj);
102101

@@ -520,8 +519,12 @@ inline PyObject *make_object_base_type(PyTypeObject *metaclass) {
520519

521520
/// dynamic_attr: Allow the garbage collector to traverse the internal instance `__dict__`.
522521
extern "C" inline int pybind11_traverse(PyObject *self, visitproc visit, void *arg) {
522+
#if PY_VERSION_HEX >= 0x030D0000
523+
PyObject_VisitManagedDict(self, visit, arg);
524+
#else
523525
PyObject *&dict = *_PyObject_GetDictPtr(self);
524526
Py_VISIT(dict);
527+
#endif
525528
// https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_traverse
526529
#if PY_VERSION_HEX >= 0x03090000
527530
Py_VISIT(Py_TYPE(self));
@@ -531,8 +534,12 @@ extern "C" inline int pybind11_traverse(PyObject *self, visitproc visit, void *a
531534

532535
/// dynamic_attr: Allow the GC to clear the dictionary.
533536
extern "C" inline int pybind11_clear(PyObject *self) {
537+
#if PY_VERSION_HEX >= 0x030D0000
538+
PyObject_ClearManagedDict(self);
539+
#else
534540
PyObject *&dict = *_PyObject_GetDictPtr(self);
535541
Py_CLEAR(dict);
542+
#endif
536543
return 0;
537544
}
538545

include/pybind11/stl_bind.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ class_<Vector, holder_type> bind_vector(handle scope, std::string const &name, A
525525
[](const Vector &v) -> bool { return !v.empty(); },
526526
"Check whether the list is nonempty");
527527

528-
cl.def("__len__", &Vector::size);
528+
cl.def("__len__", [](const Vector &vec) { return vec.size(); });
529529

530530
#if 0
531531
// C++ style functions deprecated, leaving it here as an example
@@ -843,7 +843,8 @@ class_<Map, holder_type> bind_map(handle scope, const std::string &name, Args &&
843843
m.erase(it);
844844
});
845845

846-
cl.def("__len__", &Map::size);
846+
// Always use a lambda in case of `using` declaration
847+
cl.def("__len__", [](const Map &m) { return m.size(); });
847848

848849
return cl;
849850
}

0 commit comments

Comments
 (0)