[clang] [libclang/python] Remove global SPELLING_CACHE alias (PR #210677)
Jannick Kremer via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 20 03:30:16 PDT 2026
https://github.com/DeinAlptraum created https://github.com/llvm/llvm-project/pull/210677
This completes the second step of https://github.com/llvm/llvm-project/issues/156680
This change is a follow-up to https://github.com/llvm/llvm-project/pull/177586, following the release branching, to ensure a one release-cycle deprecation period.
>From d551a1ef656490f55168c8cb16d53416681fd0ee Mon Sep 17 00:00:00 2001
From: Jannick Kremer <jannick.kremer at mailbox.org>
Date: Mon, 20 Jul 2026 19:28:31 +0900
Subject: [PATCH] [libclang/python] Remove global SPELLING_CACHE alias
This completes the second step of https://github.com/llvm/llvm-project/issues/156680
This change is a follow-up to https://github.com/llvm/llvm-project/pull/177586, following the release branching, to ensure a one release-cycle deprecation period.
---
clang/bindings/python/clang/cindex.py | 29 -------------------
.../tests/cindex/test_code_completion.py | 25 ----------------
clang/docs/ReleaseNotes.md | 4 +++
3 files changed, 4 insertions(+), 54 deletions(-)
diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py
index 24b737139dba8..5a1d761d13e02 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -3101,32 +3101,6 @@ def __getattribute__(self, attr):
class CompletionChunk:
- class SpellingCacheAlias:
- """
- A temporary utility that acts as an alias to CompletionChunk.SPELLING_CACHE.
- This will be removed without deprecation warning in a future release.
- Please do not use it directly!
- """
-
- deprecation_message = (
- "'SPELLING_CACHE' has been moved into the scope of 'CompletionChunk' "
- "and adapted to use 'CompletionChunkKind's as keys instead of their "
- "enum values. Please adapt all uses of 'SPELLING_CACHE' to use "
- "'CompletionChunk.SPELLING_CACHE' instead. The old 'SPELLING_CACHE' "
- "will be removed in a future release."
- )
-
- def __getattr__(self, _: Any) -> NoReturn:
- raise AttributeError(self.deprecation_message)
-
- def __getitem__(self, value: int) -> str:
- warnings.warn(self.deprecation_message, DeprecationWarning)
- return CompletionChunk.SPELLING_CACHE[CompletionChunkKind.from_id(value)]
-
- def __contains__(self, value: int) -> bool:
- warnings.warn(self.deprecation_message, DeprecationWarning)
- return CompletionChunkKind.from_id(value) in CompletionChunk.SPELLING_CACHE
-
# Functions calls through the python interface are rather slow. Fortunately,
# for most symbols, we do not need to perform a function call. Their spelling
# never changes and is consequently provided by this spelling cache.
@@ -3236,9 +3210,6 @@ def isKindResultType(self) -> bool:
return self.kind == CompletionChunkKind.RESULT_TYPE
-SPELLING_CACHE = CompletionChunk.SpellingCacheAlias()
-
-
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
diff --git a/clang/bindings/python/tests/cindex/test_code_completion.py b/clang/bindings/python/tests/cindex/test_code_completion.py
index d969bb2fa0e6c..593e07ed55496 100644
--- a/clang/bindings/python/tests/cindex/test_code_completion.py
+++ b/clang/bindings/python/tests/cindex/test_code_completion.py
@@ -3,7 +3,6 @@
CompletionChunk,
CompletionChunkKind,
CompletionString,
- SPELLING_CACHE,
TranslationUnit,
)
@@ -239,27 +238,3 @@ def test_completion_chunk_kind_compatibility(self):
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
- with self.assertRaises(AttributeError, msg=SPELLING_CACHE.deprecation_message):
- SPELLING_CACHE.keys()
-
- def test_spelling_cache_alias(self):
- kind_keys = list(CompletionChunk.SPELLING_CACHE)
- self.assertEqual(len(kind_keys), 13)
- for kind_key in kind_keys:
- with warnings.catch_warnings(record=True) as log:
- self.assertEqual(
- SPELLING_CACHE[kind_key.value],
- CompletionChunk.SPELLING_CACHE[kind_key],
- )
- 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
- with self.assertRaises(AttributeError, msg=SPELLING_CACHE.deprecation_message):
- SPELLING_CACHE.keys()
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 9301745b9628e..8f8811dbfa38b 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
+- Remove the deprecated `SPELLING_CACHE` alias.
+ All usage should be migrated to use `CompletionChunk.SPELLING_CACHE` instead.
+ Note that this uses `CompletionChunkKind` as keys, instead of the enum values.
+
### OpenCL Potentially Breaking Changes
## What's New in Clang {{env.config.release}}?
More information about the cfe-commits
mailing list