https://github.com/Endilll updated 
https://github.com/llvm/llvm-project/pull/229510

>From 1494ca17d84e48db11bcb4d2cf2d78a6ebb27bb9 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov <[email protected]>
Date: Tue, 6 Oct 2026 20:49:37 +0300
Subject: [PATCH] [clang][python] Inherit Diiagnostic from OpaqueClangObject

---
 clang/bindings/python/clang/cindex.py | 48 ++++++++++-----------------
 1 file changed, 18 insertions(+), 30 deletions(-)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index bbfb229b7dd9e9f..27216a5703d5f1f 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -424,7 +424,24 @@ def __repr__(self) -> str:
         return "<SourceRange start %r, end %r>" % (self.start, self.end)
 
 
-class Diagnostic:
+class OpaqueClangObject:
+    """
+    A helper for Python objects that mirror opaque types of the C API.
+    It stores an opaque pointer returned by the C API, and implements a
+    `from_param` method, allowing Python objects to be implicitly converted
+    to the stored opaque pointer when it is passed as an argument to the
+    C API.
+    """
+
+    def __init__(self, obj):
+        assert isinstance(obj, c_object_p) and obj
+        self.obj = self._as_parameter_ = obj
+
+    def from_param(self):
+        return self._as_parameter_
+
+
+class Diagnostic(OpaqueClangObject):
     """
     A Diagnostic is a single instance of a Clang diagnostic. It includes the
     diagnostic severity, the message, the location the diagnostic occurred, as
@@ -445,9 +462,6 @@ class Diagnostic:
     DisplayCategoryName = 0x20
     _FormatOptionsMask = 0x3F
 
-    def __init__(self, ptr):
-        self.ptr = ptr
-
     def __del__(self):
         conf.lib.clang_disposeDiagnostic(self)
 
@@ -560,9 +574,6 @@ def __repr__(self):
     def __str__(self):
         return self.format()
 
-    def from_param(self):
-        return self.ptr
-
 
 class FixIt:
     """
@@ -3052,23 +3063,6 @@ def __ne__(self, other: object) -> bool:
 
 ## Opaque Clang Objects ##
 
-class OpaqueClangObject:
-    """
-    A helper for Python objects that mirror opaque types of the C API.
-    It stores an opaque pointer returned by the C API, and implements a
-    `from_param` method, allowing Python objects to be implicitly converted
-    to the stored opaque pointer when it is passed as an argument to the
-    C API.
-    """
-
-    def __init__(self, obj):
-        assert isinstance(obj, c_object_p) and obj
-        self.obj = self._as_parameter_ = obj
-
-    def from_param(self):
-        return self._as_parameter_
-
-
 ### Completion Chunk Kinds ###
 class CompletionChunkKind(BaseEnumeration):
     """
@@ -4042,9 +4036,6 @@ def create(tu):
         """
         return Rewriter(conf.lib.clang_CXRewriter_create(tu))
 
-    def __init__(self, ptr):
-        OpaqueClangObject.__init__(self, ptr)
-
     def __del__(self):
         conf.lib.clang_CXRewriter_dispose(self)
 
@@ -4136,9 +4127,6 @@ def create(cursor):
         """
         return PrintingPolicy(conf.lib.clang_getCursorPrintingPolicy(cursor))
 
-    def __init__(self, ptr):
-        OpaqueClangObject.__init__(self, ptr)
-
     def __del__(self):
         conf.lib.clang_PrintingPolicy_dispose(self)
 

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to