Skip to content

Commit 4d0fced

Browse files
authored
fix: support Python 3.13.0b1 (PEP 667 fix) (#5127)
* ci: add Python 3.13 Signed-off-by: Henry Schreiner <[email protected]> * tests: run the gc for 3.13+ Signed-off-by: Henry Schreiner <[email protected]> * Revert "tests: run the gc for 3.13+" This reverts commit fe8a3ce. * ci: drop macos ARM for now, need pin updates Signed-off-by: Henry Schreiner <[email protected]> * fix: use Python 3.13 API if on 3.13 Signed-off-by: Henry Schreiner <[email protected]> --------- Signed-off-by: Henry Schreiner <[email protected]>
1 parent b07fddb commit 4d0fced

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

.github/workflows/ci.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ jobs:
3434
python:
3535
- '3.6'
3636
- '3.9'
37-
- '3.10'
38-
- '3.11'
3937
- '3.12'
38+
- '3.13'
4039
- 'pypy-3.8'
4140
- 'pypy-3.9'
4241
- 'pypy-3.10'
@@ -64,6 +63,10 @@ jobs:
6463
# Inject a couple Windows 2019 runs
6564
- runs-on: windows-2019
6665
python: '3.9'
66+
# Extra ubuntu latest job
67+
- runs-on: ubuntu-latest
68+
python: '3.11'
69+
6770

6871
name: "🐍 ${{ matrix.python }} • ${{ matrix.runs-on }} • x64 ${{ matrix.args }}"
6972
runs-on: ${{ matrix.runs-on }}
@@ -75,6 +78,7 @@ jobs:
7578
uses: actions/setup-python@v5
7679
with:
7780
python-version: ${{ matrix.python }}
81+
allow-prereleases: true
7882

7983
- name: Setup Boost (Linux)
8084
# Can't use boost + define _

include/pybind11/pybind11.h

+12
Original file line numberDiff line numberDiff line change
@@ -1344,8 +1344,14 @@ using module = module_;
13441344
/// Return a dictionary representing the global variables in the current execution frame,
13451345
/// or ``__main__.__dict__`` if there is no frame (usually when the interpreter is embedded).
13461346
inline dict globals() {
1347+
#if PY_VERSION_HEX >= 0x030d0000
1348+
PyObject *p = PyEval_GetFrameGlobals();
1349+
return p ? reinterpret_steal<dict>(p)
1350+
: reinterpret_borrow<dict>(module_::import("__main__").attr("__dict__").ptr());
1351+
#else
13471352
PyObject *p = PyEval_GetGlobals();
13481353
return reinterpret_borrow<dict>(p ? p : module_::import("__main__").attr("__dict__").ptr());
1354+
#endif
13491355
}
13501356

13511357
template <typename... Args, typename = detail::enable_if_t<args_are_all_keyword_or_ds<Args...>()>>
@@ -2770,7 +2776,12 @@ get_type_override(const void *this_ptr, const type_info *this_type, const char *
27702776
PyCodeObject *f_code = PyFrame_GetCode(frame);
27712777
// f_code is guaranteed to not be NULL
27722778
if ((std::string) str(f_code->co_name) == name && f_code->co_argcount > 0) {
2779+
# if PY_VERSION_HEX >= 0x030d0000
2780+
PyObject *locals = PyEval_GetFrameLocals();
2781+
# else
27732782
PyObject *locals = PyEval_GetLocals();
2783+
Py_INCREF(locals);
2784+
# endif
27742785
if (locals != nullptr) {
27752786
# if PY_VERSION_HEX >= 0x030b0000
27762787
PyObject *co_varnames = PyCode_GetVarnames(f_code);
@@ -2780,6 +2791,7 @@ get_type_override(const void *this_ptr, const type_info *this_type, const char *
27802791
PyObject *self_arg = PyTuple_GET_ITEM(co_varnames, 0);
27812792
Py_DECREF(co_varnames);
27822793
PyObject *self_caller = dict_getitem(locals, self_arg);
2794+
Py_DECREF(locals);
27832795
if (self_caller == self.ptr()) {
27842796
Py_DECREF(f_code);
27852797
Py_DECREF(frame);

0 commit comments

Comments
 (0)