|
58 | 58 |
|
59 | 59 | #include <QDir> |
60 | 60 |
|
61 | | -#if PY_MINOR_VERSION >= 10 |
| 61 | +#if PY_VERSION_HEX >= 0x030A0000 |
62 | 62 | #include <cpython/pydebug.h> |
63 | 63 | #else |
64 | 64 | #include <pydebug.h> |
65 | 65 | #endif |
66 | 66 |
|
| 67 | +// .co_varnames was removed in 3.11, but the helper function was added |
| 68 | +#if PY_VERSION_HEX < 0x030B0000 |
| 69 | +static inline PyObject *PyCode_GetVarnames(PyCodeObject *o) { |
| 70 | + Py_XINCREF(o->co_varnames); |
| 71 | + return o->co_varnames; |
| 72 | +} |
| 73 | +#endif |
| 74 | + |
67 | 75 | #include <vector> |
68 | 76 |
|
69 | 77 | PythonQt* PythonQt::_self = nullptr; |
@@ -2427,25 +2435,26 @@ QString PythonQtPrivate::getSignature(PyObject* object) |
2427 | 2435 | // inspect.getargs() can handle anonymous (tuple) arguments, while this code does not. |
2428 | 2436 | // It can be implemented, but it may be rarely needed and not necessary. |
2429 | 2437 | PyCodeObject* code = (PyCodeObject*)func->func_code; |
2430 | | - if (code->co_varnames) { |
| 2438 | + if (auto co_varnames = PyCode_GetVarnames(code)) { |
2431 | 2439 | int nargs = code->co_argcount; |
2432 | | - Q_ASSERT(PyTuple_Check(code->co_varnames)); |
| 2440 | + Q_ASSERT(PyTuple_Check(co_varnames)); |
2433 | 2441 | for (int i=0; i<nargs; i++) { |
2434 | | - PyObject* name = PyTuple_GetItem(code->co_varnames, i); |
| 2442 | + PyObject* name = PyTuple_GetItem(co_varnames, i); |
2435 | 2443 | Q_ASSERT(PyString_Check(name)); |
2436 | 2444 | arguments << PyString_AsString(name); |
2437 | 2445 | } |
2438 | 2446 | if (code->co_flags & CO_VARARGS) { |
2439 | | - PyObject* s = PyTuple_GetItem(code->co_varnames, nargs); |
| 2447 | + PyObject* s = PyTuple_GetItem(co_varnames, nargs); |
2440 | 2448 | Q_ASSERT(PyString_Check(s)); |
2441 | 2449 | varargs = PyString_AsString(s); |
2442 | 2450 | nargs += 1; |
2443 | 2451 | } |
2444 | 2452 | if (code->co_flags & CO_VARKEYWORDS) { |
2445 | | - PyObject* s = PyTuple_GetItem(code->co_varnames, nargs); |
| 2453 | + PyObject* s = PyTuple_GetItem(co_varnames, nargs); |
2446 | 2454 | Q_ASSERT(PyString_Check(s)); |
2447 | 2455 | varkeywords = PyString_AsString(s); |
2448 | 2456 | } |
| 2457 | + Py_DECREF(co_varnames); |
2449 | 2458 | } |
2450 | 2459 |
|
2451 | 2460 | PyObject* defaultsTuple = func->func_defaults; |
|
0 commit comments