[clang] [libclang/python] Add typing annotations for the Cursor class (PR #138103)

Jannick Kremer via cfe-commits cfe-commits at lists.llvm.org
Tue May 13 01:30:53 PDT 2025


================
@@ -1913,7 +1916,7 @@ def type(self):
         return self._type
 
     @property
-    def canonical(self):
+    def canonical(self) -> Cursor | None:
         """Return the canonical Cursor corresponding to this Cursor.
----------------
DeinAlptraum wrote:

That's a good idea, I added `from_non_null_cursor_result` and used it for `clang_getTypeDeclaration` and `clang_getCanonicalCursor` which seem to be the only places where we can guarantee that we won't get a null-Cursor. All the others explicitly return a null-Cursor under certain conditions.

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


More information about the cfe-commits mailing list