[clang] [libclang/python] Fix some type errors, add type annotations (PR #98745)

Vlad Serebrennikov via cfe-commits cfe-commits at lists.llvm.org
Sat Jul 20 16:45:04 PDT 2024


================
@@ -200,13 +236,16 @@ class _CXString(Structure):
 
     _fields_ = [("spelling", c_char_p), ("free", c_int)]
 
-    def __del__(self):
+    def __del__(self) -> None:
         conf.lib.clang_disposeString(self)
 
     @staticmethod
-    def from_result(res, fn=None, args=None):
+    def from_result(res: _CXString, fn: Any = None, args: Any = None) -> str:
         assert isinstance(res, _CXString)
-        return conf.lib.clang_getCString(res)
+        pystr: str | None = conf.lib.clang_getCString(res)
+        if pystr is None:
+            return ""
+        return pystr
----------------
Endilll wrote:

This change makes sense. I'm not sure it's breaking, though, because nothing breaks for both users who have been checking for `None`, and those who have not been.

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


More information about the cfe-commits mailing list