[clang] [libclang/python] Unify CompletionChunkKind.__str__ representation (PR #210676)
Jannick Kremer via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 20 03:17:27 PDT 2026
https://github.com/DeinAlptraum created https://github.com/llvm/llvm-project/pull/210676
This ensures consistency with other enums.
This change is a follow-up to https://github.com/llvm/llvm-project/pull/176631, following the release branch, to ensure a one release-cycle deprecation period. This also completes the first step of https://github.com/llvm/llvm-project/issues/156680
>From 94416a7f7330fe4fe7fb15aa47e58e2fa7cb78b1 Mon Sep 17 00:00:00 2001
From: Jannick Kremer <jannick.kremer at mailbox.org>
Date: Mon, 20 Jul 2026 19:14:01 +0900
Subject: [PATCH] [libclang/python] Unify CompletionChunkKind.__str__
representation
This ensures consistency with other enums.
This change is a follow-up to https://github.com/llvm/llvm-project/pull/176631,
following the release branch, to ensure a one release-cycle deprecation period
---
clang/bindings/python/clang/cindex.py | 20 -----
.../tests/cindex/test_code_completion.py | 75 +++++--------------
clang/docs/ReleaseNotes.md | 3 +
3 files changed, 20 insertions(+), 78 deletions(-)
diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py
index 24b737139dba8..9108733bedbfb 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -3032,26 +3032,6 @@ class CompletionChunkKind(BaseEnumeration):
Describes a single piece of text within a code-completion string.
"""
- 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 'CompletionChunkKind' will be "
- "changed in a future release from 'camelCase' to 'ALL_CAPS' to "
- "match other enums. 'CompletionChunkKind's can be "
- "compared to one another 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)
-
OPTIONAL = 0
TYPED_TEXT = 1
TEXT = 2
diff --git a/clang/bindings/python/tests/cindex/test_code_completion.py b/clang/bindings/python/tests/cindex/test_code_completion.py
index d969bb2fa0e6c..5be03fab36db8 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', CompletionChunkKind.RESULT_TYPE} | {'test1', CompletionChunkKind.TYPED_TEXT} || Priority: 50 || Availability: Available || Brief comment: Aaa.",
+ "{'void', CompletionChunkKind.RESULT_TYPE} | {'test2', CompletionChunkKind.TYPED_TEXT} | {'(', CompletionChunkKind.LEFT_PAREN} | {')', CompletionChunkKind.RIGHT_PAREN} || Priority: 50 || Availability: Available || Brief comment: Bbb.",
+ "{'return', CompletionChunkKind.TYPED_TEXT} | {';', CompletionChunkKind.SEMI_COLON} || Priority: 40 || Availability: 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', CompletionChunkKind.RESULT_TYPE} | {'test1', CompletionChunkKind.TYPED_TEXT} || Priority: 50 || Availability: Available || Brief comment: Aaa.",
+ "{'void', CompletionChunkKind.RESULT_TYPE} | {'test2', CompletionChunkKind.TYPED_TEXT} | {'(', CompletionChunkKind.LEFT_PAREN} | {')', CompletionChunkKind.RIGHT_PAREN} || Priority: 50 || Availability: Available || Brief comment: Bbb.",
+ "{'return', CompletionChunkKind.TYPED_TEXT} | {';', CompletionChunkKind.SEMI_COLON} || Priority: 40 || Availability: Available || Brief comment: ",
]
self.check_completion_results(cr, expected)
@@ -141,20 +141,20 @@ 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', CompletionChunkKind.TYPED_TEXT} || Priority: 50 || Availability: Available || Brief comment: ",
+ "{'volatile', CompletionChunkKind.TYPED_TEXT} || Priority: 50 || Availability: Available || Brief comment: ",
+ "{'operator', CompletionChunkKind.TYPED_TEXT} || Priority: 40 || Availability: Available || Brief comment: ",
+ "{'P', CompletionChunkKind.TYPED_TEXT} || Priority: 50 || Availability: Available || Brief comment: ",
+ "{'Q', CompletionChunkKind.TYPED_TEXT} || Priority: 50 || Availability: 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', CompletionChunkKind.TYPED_TEXT} | {'::', CompletionChunkKind.TEXT} || Priority: 75 || Availability: Available || Brief comment: ",
+ "{'P &', CompletionChunkKind.RESULT_TYPE} | {'operator=', CompletionChunkKind.TYPED_TEXT} | {'(', CompletionChunkKind.LEFT_PAREN} | {'const P &', CompletionChunkKind.PLACEHOLDER} | {')', CompletionChunkKind.RIGHT_PAREN} || Priority: 79 || Availability: Available || Brief comment: ",
+ "{'int', CompletionChunkKind.RESULT_TYPE} | {'member', CompletionChunkKind.TYPED_TEXT} || Priority: 35 || Availability: NotAccessible || Brief comment: ",
+ "{'void', CompletionChunkKind.RESULT_TYPE} | {'~P', CompletionChunkKind.TYPED_TEXT} | {'(', CompletionChunkKind.LEFT_PAREN} | {')', CompletionChunkKind.RIGHT_PAREN} || Priority: 79 || Availability: Available || Brief comment: ",
]
self.check_completion_results(cr, expected)
@@ -199,47 +199,6 @@ def test_compat_str(self):
self.assertEqual(len(log), 1)
self.assertIsInstance(log[0].message, DeprecationWarning)
- def test_completion_chunk_kind_compatibility(self):
- value_to_old_str = {
- 0: "Optional",
- 1: "TypedText",
- 2: "Text",
- 3: "Placeholder",
- 4: "Informative",
- 5: "CurrentParameter",
- 6: "LeftParen",
- 7: "RightParen",
- 8: "LeftBracket",
- 9: "RightBracket",
- 10: "LeftBrace",
- 11: "RightBrace",
- 12: "LeftAngle",
- 13: "RightAngle",
- 14: "Comma",
- 15: "ResultType",
- 16: "Colon",
- 17: "SemiColon",
- 18: "Equal",
- 19: "HorizontalSpace",
- 20: "VerticalSpace",
- }
-
- # Check that all new kinds correspond to an old kind
- for new_kind in CompletionChunkKind:
- old_str = value_to_old_str[new_kind.value]
- with warnings.catch_warnings(record=True) as log:
- self.assertEqual(old_str, str(new_kind))
- self.assertEqual(len(log), 1)
- self.assertIsInstance(log[0].message, DeprecationWarning)
-
- # Check that all old kinds correspond to a new kind
- for value, old_str in value_to_old_str.items():
- new_kind = CompletionChunkKind.from_id(value)
- with warnings.catch_warnings(record=True) as log:
- self.assertEqual(old_str, str(new_kind))
- self.assertEqual(len(log), 1)
- self.assertIsInstance(log[0].message, DeprecationWarning)
-
def test_spelling_cache_missing_attribute(self):
# Test that accessing missing attributes on SpellingCacheAlias raises
# during the transitionary period
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 9301745b9628e..85de286920158 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -58,6 +58,9 @@ latest release, please see the [Clang Web Site](https://clang.llvm.org) or the
### Clang Python Bindings Potentially Breaking Changes
+- `CompletionChunkKind` instance's `__str__` representation has been adapted to be consistent with other enums in the library.
+ The representation now follows the `CompletionChunkKind.VARIANT_NAME` scheme instead of `VariantName`.
+
### OpenCL Potentially Breaking Changes
## What's New in Clang {{env.config.release}}?
More information about the cfe-commits
mailing list