[clang] [libclang/python] Derive library function types from annotations (PR #142120)

Jannick Kremer via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 5 05:31:45 PDT 2025


================
@@ -3986,256 +3987,588 @@ def set_property(self, property, value):
 # Now comes the plumbing to hook up the C library.
 
 # Register callback types
-translation_unit_includes_callback = CFUNCTYPE(
+translation_unit_includes_callback: TypeAlias = CFUNCTYPE(  # type: ignore [valid-type]
     None, c_object_p, POINTER(SourceLocation), c_uint, py_object
 )
-cursor_visit_callback = CFUNCTYPE(c_int, Cursor, Cursor, py_object)
-fields_visit_callback = CFUNCTYPE(c_int, Cursor, py_object)
+cursor_visit_callback: TypeAlias = CFUNCTYPE(c_int, Cursor, Cursor, py_object)  # type: ignore [valid-type]
+fields_visit_callback: TypeAlias = CFUNCTYPE(c_int, Cursor, py_object)  # type: ignore [valid-type]
+
+
+def _get_annotations() -> list[LibFunc]:
+    def str_to_type(typename: str) -> type:
----------------
DeinAlptraum wrote:

Thanks for the suggestion! I'll have to try this to see if it works as intended - have you looked at the other issues I mentioned though?
Especially the first one breaks almost all annotations anyway, making this approach pointless if we can't resolve it.

https://github.com/llvm/llvm-project/pull/142120


More information about the cfe-commits mailing list