Skip to content

Commit dc477fa

Browse files
vstinnerhenryiii
andauthored
fix: Use PyObject_VisitManagedDict() of Python 3.13 (#4973)
* fix: Use PyObject_VisitManagedDict() of Python 3.13 Use PyObject_VisitManagedDict() and PyObject_ClearManagedDict() in pybind11_traverse() and pybind11_clear() on Python 3.13 and newer. * Add Python 3.13 CI * tests: don't get numpy/scipy on 3.13 yet * ci: move 3.13 to upstream Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> --------- Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
1 parent daea113 commit dc477fa

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ jobs:
7575
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 _

.github/workflows/upstream.yml

Lines changed: 4 additions & 4 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
29+
- name: Setup Python 3.13
3130
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

include/pybind11/detail/class.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,12 @@ inline PyObject *make_object_base_type(PyTypeObject *metaclass) {
519519

520520
/// dynamic_attr: Allow the garbage collector to traverse the internal instance `__dict__`.
521521
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
522525
PyObject *&dict = *_PyObject_GetDictPtr(self);
523526
Py_VISIT(dict);
527+
#endif
524528
// https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_traverse
525529
#if PY_VERSION_HEX >= 0x03090000
526530
Py_VISIT(Py_TYPE(self));
@@ -530,8 +534,12 @@ extern "C" inline int pybind11_traverse(PyObject *self, visitproc visit, void *a
530534

531535
/// dynamic_attr: Allow the GC to clear the dictionary.
532536
extern "C" inline int pybind11_clear(PyObject *self) {
537+
#if PY_VERSION_HEX >= 0x030D0000
538+
PyObject_ClearManagedDict(self);
539+
#else
533540
PyObject *&dict = *_PyObject_GetDictPtr(self);
534541
Py_CLEAR(dict);
542+
#endif
535543
return 0;
536544
}
537545

tests/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ numpy~=1.25.0; python_version=="3.9" and platform_python_implementation=='PyPy'
77
numpy~=1.19.3; platform_python_implementation!="PyPy" and python_version=="3.6"
88
numpy~=1.21.5; platform_python_implementation!="PyPy" and python_version>="3.7" and python_version<"3.10"
99
numpy~=1.22.2; platform_python_implementation!="PyPy" and python_version=="3.10"
10-
numpy~=1.26.0; platform_python_implementation!="PyPy" and python_version>="3.11"
10+
numpy~=1.26.0; platform_python_implementation!="PyPy" and python_version>="3.11" and python_version<"3.13"
1111
pytest~=7.0
1212
pytest-timeout
1313
scipy~=1.5.4; platform_python_implementation!="PyPy" and python_version<"3.10"
1414
scipy~=1.8.0; platform_python_implementation!="PyPy" and python_version=="3.10"
15-
scipy~=1.11.1; platform_python_implementation!="PyPy" and python_version>="3.11"
15+
scipy~=1.11.1; platform_python_implementation!="PyPy" and python_version>="3.11" and python_version<"3.13"

0 commit comments

Comments
 (0)