fix(TypeTree): support py3.14+ annotation fetching · K0lb3/UnityPy@28160b8 · GitHub
Skip to content

Commit 28160b8

Browse files
committed
fix(TypeTree): support py3.14+ annotation fetching
1 parent 06087c1 commit 28160b8

3 files changed

Lines changed: 24 additions & 14 deletions

File tree

‎UnityPy/helpers/TypeTreeHelper.py‎

Lines changed: 14 additions & 2 deletions

‎UnityPyBoost/TypeTreeHelper.cpp‎

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -432,22 +432,12 @@ inline PyObject *read_class(ReaderT *reader, TypeTreeNodeObject *node, TypeTreeR
432432
return value;
433433
}
434434

435-
#if PY_VERSION_HEX >= 0x030e0000
436-
PyObject *get_annotations = nullptr;
437-
#endif
435+
static PyObject *_get_annotations = nullptr;
438436

439437
inline PyObject *get_annotations(PyObject *clz)
440438
{
441439
#if PY_VERSION_HEX >= 0x030e0000
442-
if (get_annotations == nullptr)
443-
{
444-
// from annotationlib import get_annotations
445-
PyObject *annotationlib = PyImport_ImportModule("annotationlib");
446-
get_annotations = PyObject_GetAttrString(annotationlib, "get_annotations");
447-
Py_INCREF(get_annotations);
448-
Py_DECREF(annotationlib);
449-
}
450-
return PyObject_CallFunctionObjArgs(get_annotations, clz, NULL);
440+
return PyObject_CallFunctionObjArgs(_get_annotations, clz, NULL);
451441
#else
452442
return PyObject_GetAttrString(clz, "__annotations__");
453443
#endif
@@ -1266,5 +1256,12 @@ int add_typetreenode_to_module(PyObject *m)
12661256
return -1;
12671257
Py_INCREF(&TypeTreeNodeType);
12681258
PyModule_AddObject(m, "TypeTreeNode", (PyObject *)&TypeTreeNodeType);
1259+
#if PY_VERSION_HEX >= 0x030e0000
1260+
PyObject *annotationlib = PyImport_ImportModule("annotationlib");
1261+
_get_annotations = PyObject_GetAttrString(annotationlib, "get_annotations");
1262+
PyModule_AddObject(m, "_get_annotations", _get_annotations); // steals ref
1263+
Py_INCREF(_get_annotations);
1264+
Py_DECREF(annotationlib);
1265+
#endif
12691266
return 0;
12701267
}

‎pyproject.toml‎

Lines changed: 1 addition & 0 deletions

0 commit comments

Comments
 (0)