https://github.com/DeinAlptraum created 
https://github.com/llvm/llvm-project/pull/210682

This completes the fourth step of 
https://github.com/llvm/llvm-project/pull/156680
This change is a follow-up to https://github.com/llvm/llvm-project/pull/160296, 
following the release branching, to ensure a one release-cycle deprecation 
period.

>From 548e64102da2b15e163347d2016d512a2c4a0a0b Mon Sep 17 00:00:00 2001
From: Jannick Kremer <[email protected]>
Date: Mon, 20 Jul 2026 19:55:22 +0900
Subject: [PATCH] [libclang/python] Remove
 CompletionString.AvailabilityKindCompat

This completes the fourth step of 
https://github.com/llvm/llvm-project/pull/156680
This change is a follow-up to https://github.com/llvm/llvm-project/pull/160296, 
following the release branching, to ensure a one release-cycle deprecation 
period.
---
 clang/bindings/python/clang/cindex.py         | 50 +------------
 .../tests/cindex/test_code_completion.py      | 75 +++++--------------
 .../python/tests/cindex/test_enums.py         |  1 -
 clang/docs/ReleaseNotes.md                    |  4 +
 4 files changed, 23 insertions(+), 107 deletions(-)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 24b737139dba8..89293b77bc0a6 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -3240,52 +3240,6 @@ def isKindResultType(self) -> bool:
 
 
 class CompletionString(ClangObject):
-    # AvailabilityKindCompat is an exact copy of AvailabilityKind, except for 
__str__.
-    # This is a temporary measure to keep the string representation the same
-    # until we change CompletionString.availability to return AvailabilityKind,
-    # like Cursor.availability does.
-    # Note that deriving from AvailabilityKind directly is not possible.
-    class AvailabilityKindCompat(BaseEnumeration):
-        """
-        Describes the availability of an entity.
-        It is deprecated in favor of AvailabilityKind.
-        """
-
-        # Ensure AvailabilityKindCompat is comparable with AvailabilityKind
-        def __eq__(self, other: object) -> bool:
-            if isinstance(
-                other, (AvailabilityKind, 
CompletionString.AvailabilityKindCompat)
-            ):
-                return self.value == other.value
-            else:
-                return NotImplemented
-
-        def __str__(self) -> str:
-            """
-            Converts enum value to string in the old camelCase format.
-            This is a temporary measure that will be changed in the future 
release
-            to return string in ALL_CAPS format, like for other enums.
-            """
-
-            warnings.warn(
-                "String representation of 'CompletionString.availability' will 
be "
-                "changed in a future release from 'camelCase' to 'ALL_CAPS' to 
"
-                "match other enums. 'CompletionString.availability' can be "
-                "compared to 'AvailabilityKind' directly, "
-                "without conversion to string.",
-                DeprecationWarning,
-            )
-            # Remove underscores
-            components = self.name.split("_")
-            # Upper-camel case each split component
-            components = [component.lower().capitalize() for component in 
components]
-            return "".join(components)
-
-        AVAILABLE = 0
-        DEPRECATED = 1
-        NOT_AVAILABLE = 2
-        NOT_ACCESSIBLE = 3
-
     def __len__(self) -> int:
         return self.num_chunks
 
@@ -3310,9 +3264,9 @@ def priority(self) -> int:
         return conf.lib.clang_getCompletionPriority(self.obj)  # type: ignore 
[no-any-return]
 
     @property
-    def availability(self) -> AvailabilityKindCompat:
+    def availability(self) -> AvailabilityKind:
         res = conf.lib.clang_getCompletionAvailability(self.obj)
-        return CompletionString.AvailabilityKindCompat.from_id(res)
+        return AvailabilityKind.from_id(res)
 
     @property
     def briefComment(self) -> str:
diff --git a/clang/bindings/python/tests/cindex/test_code_completion.py 
b/clang/bindings/python/tests/cindex/test_code_completion.py
index d969bb2fa0e6c..9c840fa8f417c 100644
--- a/clang/bindings/python/tests/cindex/test_code_completion.py
+++ b/clang/bindings/python/tests/cindex/test_code_completion.py
@@ -19,7 +19,7 @@ def check_completion_results(self, cr, expected):
 
         with warnings.catch_warnings(record=True) as log:
             completions = [str(c) for c in cr]
-            self.assertEqual(len(log), 2)
+            self.assertEqual(len(log), 1)
             for warning in log:
                 self.assertIsInstance(warning.message, DeprecationWarning)
 
@@ -28,7 +28,7 @@ def check_completion_results(self, cr, expected):
 
         with warnings.catch_warnings(record=True) as log:
             completions_deprecated = [str(c) for c in cr.results]
-            self.assertEqual(len(log), 3)
+            self.assertEqual(len(log), 2)
             for warning in log:
                 self.assertIsInstance(warning.message, DeprecationWarning)
 
@@ -65,9 +65,9 @@ def test_code_complete(self):
         )
 
         expected = [
-            "{'int', ResultType} | {'test1', TypedText} || Priority: 50 || 
Availability: Available || Brief comment: Aaa.",
-            "{'void', ResultType} | {'test2', TypedText} | {'(', LeftParen} | 
{')', RightParen} || Priority: 50 || Availability: Available || Brief comment: 
Bbb.",
-            "{'return', TypedText} | {';', SemiColon} || Priority: 40 || 
Availability: Available || Brief comment: ",
+            "{'int', ResultType} | {'test1', TypedText} || Priority: 50 || 
Availability: AvailabilityKind.AVAILABLE || Brief comment: Aaa.",
+            "{'void', ResultType} | {'test2', TypedText} | {'(', LeftParen} | 
{')', RightParen} || Priority: 50 || Availability: AvailabilityKind.AVAILABLE 
|| Brief comment: Bbb.",
+            "{'return', TypedText} | {';', SemiColon} || Priority: 40 || 
Availability: AvailabilityKind.AVAILABLE || Brief comment: ",
         ]
         self.check_completion_results(cr, expected)
 
@@ -105,9 +105,9 @@ def test_code_complete_pathlike(self):
         )
 
         expected = [
-            "{'int', ResultType} | {'test1', TypedText} || Priority: 50 || 
Availability: Available || Brief comment: Aaa.",
-            "{'void', ResultType} | {'test2', TypedText} | {'(', LeftParen} | 
{')', RightParen} || Priority: 50 || Availability: Available || Brief comment: 
Bbb.",
-            "{'return', TypedText} | {';', SemiColon} || Priority: 40 || 
Availability: Available || Brief comment: ",
+            "{'int', ResultType} | {'test1', TypedText} || Priority: 50 || 
Availability: AvailabilityKind.AVAILABLE || Brief comment: Aaa.",
+            "{'void', ResultType} | {'test2', TypedText} | {'(', LeftParen} | 
{')', RightParen} || Priority: 50 || Availability: AvailabilityKind.AVAILABLE 
|| Brief comment: Bbb.",
+            "{'return', TypedText} | {';', SemiColon} || Priority: 40 || 
Availability: AvailabilityKind.AVAILABLE || Brief comment: ",
         ]
         self.check_completion_results(cr, expected)
 
@@ -141,64 +141,23 @@ class Q : public P {
         cr = tu.codeComplete("fake.cpp", 12, 5, unsaved_files=files)
 
         expected = [
-            "{'const', TypedText} || Priority: 50 || Availability: Available 
|| Brief comment: ",
-            "{'volatile', TypedText} || Priority: 50 || Availability: 
Available || Brief comment: ",
-            "{'operator', TypedText} || Priority: 40 || Availability: 
Available || Brief comment: ",
-            "{'P', TypedText} || Priority: 50 || Availability: Available || 
Brief comment: ",
-            "{'Q', TypedText} || Priority: 50 || Availability: Available || 
Brief comment: ",
+            "{'const', TypedText} || Priority: 50 || Availability: 
AvailabilityKind.AVAILABLE || Brief comment: ",
+            "{'volatile', TypedText} || Priority: 50 || Availability: 
AvailabilityKind.AVAILABLE || Brief comment: ",
+            "{'operator', TypedText} || Priority: 40 || Availability: 
AvailabilityKind.AVAILABLE || Brief comment: ",
+            "{'P', TypedText} || Priority: 50 || Availability: 
AvailabilityKind.AVAILABLE || Brief comment: ",
+            "{'Q', TypedText} || Priority: 50 || Availability: 
AvailabilityKind.AVAILABLE || Brief comment: ",
         ]
         self.check_completion_results(cr, expected)
 
         cr = tu.codeComplete("fake.cpp", 13, 5, unsaved_files=files)
         expected = [
-            "{'P', TypedText} | {'::', Text} || Priority: 75 || Availability: 
Available || Brief comment: ",
-            "{'P &', ResultType} | {'operator=', TypedText} | {'(', LeftParen} 
| {'const P &', Placeholder} | {')', RightParen} || Priority: 79 || 
Availability: Available || Brief comment: ",
-            "{'int', ResultType} | {'member', TypedText} || Priority: 35 || 
Availability: NotAccessible || Brief comment: ",
-            "{'void', ResultType} | {'~P', TypedText} | {'(', LeftParen} | 
{')', RightParen} || Priority: 79 || Availability: Available || Brief comment: 
",
+            "{'P', TypedText} | {'::', Text} || Priority: 75 || Availability: 
AvailabilityKind.AVAILABLE || Brief comment: ",
+            "{'P &', ResultType} | {'operator=', TypedText} | {'(', LeftParen} 
| {'const P &', Placeholder} | {')', RightParen} || Priority: 79 || 
Availability: AvailabilityKind.AVAILABLE || Brief comment: ",
+            "{'int', ResultType} | {'member', TypedText} || Priority: 35 || 
Availability: AvailabilityKind.NOT_ACCESSIBLE || Brief comment: ",
+            "{'void', ResultType} | {'~P', TypedText} | {'(', LeftParen} | 
{')', RightParen} || Priority: 79 || Availability: AvailabilityKind.AVAILABLE 
|| Brief comment: ",
         ]
         self.check_completion_results(cr, expected)
 
-    def test_availability_kind_compat(self):
-        numKinds = len(CompletionString.AvailabilityKindCompat)
-
-        # Compare with regular kind
-        for compatKind in CompletionString.AvailabilityKindCompat:
-            commonKind = AvailabilityKind.from_id(compatKind.value)
-            nextKindId = (compatKind.value + 1) % numKinds
-            commonKindUnequal = AvailabilityKind.from_id(nextKindId)
-            self.assertEqual(commonKind, compatKind)
-            self.assertEqual(compatKind, commonKind)
-            self.assertNotEqual(commonKindUnequal, compatKind)
-            self.assertNotEqual(compatKind, commonKindUnequal)
-
-        # Compare two compat kinds
-        for compatKind in CompletionString.AvailabilityKindCompat:
-            compatKind2 = CompletionString.AvailabilityKindCompat.from_id(
-                compatKind.value
-            )
-            nextKindId = (compatKind.value + 1) % numKinds
-            compatKind2Unequal = 
CompletionString.AvailabilityKindCompat.from_id(
-                nextKindId
-            )
-            self.assertEqual(compatKind, compatKind2)
-            self.assertEqual(compatKind2, compatKind)
-            self.assertNotEqual(compatKind2Unequal, compatKind)
-            self.assertNotEqual(compatKind, compatKind2Unequal)
-
-    def test_compat_str(self):
-        kindStringMap = {
-            0: "Available",
-            1: "Deprecated",
-            2: "NotAvailable",
-            3: "NotAccessible",
-        }
-        for id, string in kindStringMap.items():
-            kind = CompletionString.AvailabilityKindCompat.from_id(id)
-            with warnings.catch_warnings(record=True) as log:
-                self.assertEqual(str(kind), string)
-                self.assertEqual(len(log), 1)
-                self.assertIsInstance(log[0].message, DeprecationWarning)
-
     def test_completion_chunk_kind_compatibility(self):
         value_to_old_str = {
             0: "Optional",
diff --git a/clang/bindings/python/tests/cindex/test_enums.py 
b/clang/bindings/python/tests/cindex/test_enums.py
index 283a54998470c..09f346ee6e11f 100644
--- a/clang/bindings/python/tests/cindex/test_enums.py
+++ b/clang/bindings/python/tests/cindex/test_enums.py
@@ -27,7 +27,6 @@ class TestEnums(unittest.TestCase):
     # Test all enum classes, except for AvailabilityKindCompat since it is
     # just a copy of AvailabilityKind and has no corresponding C-class
     enums = BaseEnumeration.__subclasses__()
-    enums.remove(CompletionString.AvailabilityKindCompat)
 
     def test_from_id(self):
         """Check that kinds can be constructed from valid IDs"""
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 9301745b9628e..d5a603cc20c14 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -58,6 +58,10 @@ latest release, please see the [Clang Web 
Site](https://clang.llvm.org) or the
 
 ### Clang Python Bindings Potentially Breaking Changes
 
+- `CompletionString.availability` now returns instances of `AvailabilityKind`.
+  As a result, the `__str__` representation of its return values changed.
+  It now follows the `CompletionChunkKind.VARIANT_NAME` scheme instead of 
`VariantName`, like other libclang enums. 
+
 ### OpenCL Potentially Breaking Changes
 
 ## What's New in Clang {{env.config.release}}?

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

Reply via email to