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

Vlad Serebrennikov via cfe-commits cfe-commits at lists.llvm.org
Wed May 14 10:06:55 PDT 2025


================
@@ -1552,68 +1553,85 @@ class Cursor(Structure):
 
     _fields_ = [("_kind_id", c_int), ("xdata", c_int), ("data", c_void_p * 3)]
 
+    _tu: TranslationUnit
+
+    # This ensures that no operations are possible on null cursors
+    # by guarding all method calls with a not-null assert
+    def __getattribute__(self, key: str) -> object:
----------------
Endilll wrote:

I understand what do you here, but I'm not sure I like the cleverness and non-locality relative to the methods that are affected. Do you insist on doing it this way instead of adding an assert to every method that needs it?

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


More information about the cfe-commits mailing list