https://github.com/DeinAlptraum updated 
https://github.com/llvm/llvm-project/pull/187412

>From 4a0fb3d1a4a7d688fbfe210532ba92b17d40b9a9 Mon Sep 17 00:00:00 2001
From: Jannick Kremer <[email protected]>
Date: Thu, 19 Mar 2026 09:13:35 +0900
Subject: [PATCH 1/2] Deprecate _CXUnsavedFile, introduce UnsavedFile instead

---
 clang/bindings/python/clang/cindex.py         | 25 ++++++++++++++++---
 .../bindings/python/tests/cindex/test_file.py | 12 ++++++++-
 clang/docs/ReleaseNotes.rst                   |  4 +++
 3 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 26da1a78069a4..5cf2669195aaa 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -3071,12 +3071,31 @@ def __str__(self) -> str:
     VERTICAL_SPACE = 20
 
 
-class _CXUnsavedFile(Structure):
+class UnsavedFile(Structure):
     """Helper for passing unsaved file arguments."""
 
     _fields_ = [("name", c_char_p), ("contents", c_char_p), ("length", 
c_ulong)]
 
 
+class _CXUnsavedFile(UnsavedFile):
+    """
+    _CXUnsavedFile acts as an alias to UnsavedFile.
+    This will be removed  in a future release.
+    All existing usage should be replaced directly with UnsavedFile.
+    No other changes are required.
+    """
+
+    def __getattribute__(self, attr):
+        warnings.warn(
+            "'_CXUnsavedFile' will be renamed to 'UnsavedFile' for 
consistency. "
+            "'UnsavedFile' is already available to use and existing uses 
should "
+            "be adapted to refer to it instead. '_CXUnsavedFile' will be "
+            "removed in a future release.",
+            DeprecationWarning
+        )
+        return super().__getattribute__(attr)
+
+
 class CompletionChunk:
     class SpellingCacheAlias:
         """
@@ -3464,10 +3483,10 @@ class TranslationUnit(ClangObject):
     @staticmethod
     def process_unsaved_files(
         unsaved_files: list[InMemoryFile],
-    ) -> Array[_CXUnsavedFile] | None:
+    ) -> Array[UnsavedFile] | None:
         unsaved_array = None
         if len(unsaved_files):
-            unsaved_array = (_CXUnsavedFile * len(unsaved_files))()
+            unsaved_array = (UnsavedFile * len(unsaved_files))()
             for i, (name, contents) in enumerate(unsaved_files):
                 if hasattr(contents, "read"):
                     contents = contents.read()
diff --git a/clang/bindings/python/tests/cindex/test_file.py 
b/clang/bindings/python/tests/cindex/test_file.py
index ab5c7ca543055..d485bba01d859 100644
--- a/clang/bindings/python/tests/cindex/test_file.py
+++ b/clang/bindings/python/tests/cindex/test_file.py
@@ -1,9 +1,10 @@
 import os
 
-from clang.cindex import File, Index, TranslationUnit
+from clang.cindex import _CXUnsavedFile, File, Index, TranslationUnit
 
 
 import unittest
+import warnings
 
 inputs_dir = os.path.join(os.path.dirname(__file__), "INPUTS")
 
@@ -67,3 +68,12 @@ def test_file_eq_in_memory(self):
         self.assertNotEqual(main_file, a_file)
         self.assertNotEqual(main_file, b_file)
         self.assertNotEqual(main_file, "a.inc")
+
+class TestUnsavedFile(unittest.TestCase):
+    def test_deprecation_warning(self):
+        unsaved_file = _CXUnsavedFile()
+        with warnings.catch_warnings(record=True) as log:
+            unsaved_file.name
+            self.assertEqual(len(log), 1)
+            for warning in log:
+                self.assertIsInstance(warning.message, DeprecationWarning)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 909a619eba9c1..295e5c4b6bd88 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -108,6 +108,10 @@ Clang Python Bindings Potentially Breaking Changes
   with objects of other classes.
 - ``TranslationUnit.get_tokens`` now throws an error if both the ``extent`` and
   ``locations`` argument are passed. Previousy, ``locations`` took precedence.
+- ``_CXUnsavedFile`` will be renamed to ``UnsavedFile`` for consistency.
+  ``UnsavedFile`` is already available to use and existing uses should
+  be adapted to refer to it instead. ``_CXUnsavedFile`` will be removed in a 
+  future release.
 
 What's New in Clang |release|?
 ==============================

>From 6403f2d798508c2fcb7545c7f9cce1e5de246b28 Mon Sep 17 00:00:00 2001
From: Jannick Kremer <[email protected]>
Date: Thu, 19 Mar 2026 22:21:39 +0900
Subject: [PATCH 2/2] Fix formatting

---
 clang/bindings/python/clang/cindex.py           | 2 +-
 clang/bindings/python/tests/cindex/test_file.py | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 5cf2669195aaa..c34a1c0db01e9 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -3091,7 +3091,7 @@ def __getattribute__(self, attr):
             "'UnsavedFile' is already available to use and existing uses 
should "
             "be adapted to refer to it instead. '_CXUnsavedFile' will be "
             "removed in a future release.",
-            DeprecationWarning
+            DeprecationWarning,
         )
         return super().__getattribute__(attr)
 
diff --git a/clang/bindings/python/tests/cindex/test_file.py 
b/clang/bindings/python/tests/cindex/test_file.py
index d485bba01d859..405c9fec429b2 100644
--- a/clang/bindings/python/tests/cindex/test_file.py
+++ b/clang/bindings/python/tests/cindex/test_file.py
@@ -69,6 +69,7 @@ def test_file_eq_in_memory(self):
         self.assertNotEqual(main_file, b_file)
         self.assertNotEqual(main_file, "a.inc")
 
+
 class TestUnsavedFile(unittest.TestCase):
     def test_deprecation_warning(self):
         unsaved_file = _CXUnsavedFile()

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

Reply via email to