[clang] [libclang/python] Ignore our own DeprecationWarnings in CMake targets (PR #178631)
Jannick Kremer via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 30 05:28:00 PST 2026
https://github.com/DeinAlptraum updated https://github.com/llvm/llvm-project/pull/178631
>From 6774f38dd16c5d2865b5a1e2ee250c45654ffbec Mon Sep 17 00:00:00 2001
From: Jannick Kremer <jannick.kremer at mailbox.org>
Date: Thu, 29 Jan 2026 19:49:22 +0900
Subject: [PATCH 1/2] Ignore our own DeprecationWarnings in CMake targets
---
clang/bindings/python/tests/CMakeLists.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/bindings/python/tests/CMakeLists.txt b/clang/bindings/python/tests/CMakeLists.txt
index 21fe6fb79793f..316a5beeb4afa 100644
--- a/clang/bindings/python/tests/CMakeLists.txt
+++ b/clang/bindings/python/tests/CMakeLists.txt
@@ -6,7 +6,7 @@ add_custom_target(check-clang-python
COMMAND ${CMAKE_COMMAND} -E env
CLANG_NO_DEFAULT_CONFIG=1
LIBCLANG_LIBRARY_PATH=$<TARGET_FILE_DIR:libclang>
- "${Python3_EXECUTABLE}" -m unittest discover
+ "${Python3_EXECUTABLE}" -W ignore:DeprecationWarning::clang -m unittest discover
DEPENDS libclang
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/..)
>From 9cabdbeafcb8e20dfed472ed739ec997039a49b5 Mon Sep 17 00:00:00 2001
From: Jannick Kremer <jannick.kremer at mailbox.org>
Date: Fri, 30 Jan 2026 22:27:32 +0900
Subject: [PATCH 2/2] Use context manager instead of interpreter flag
---
clang/bindings/python/tests/CMakeLists.txt | 2 +-
.../tests/cindex/test_code_completion.py | 20 ++++++++++++-------
2 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/clang/bindings/python/tests/CMakeLists.txt b/clang/bindings/python/tests/CMakeLists.txt
index 316a5beeb4afa..21fe6fb79793f 100644
--- a/clang/bindings/python/tests/CMakeLists.txt
+++ b/clang/bindings/python/tests/CMakeLists.txt
@@ -6,7 +6,7 @@ add_custom_target(check-clang-python
COMMAND ${CMAKE_COMMAND} -E env
CLANG_NO_DEFAULT_CONFIG=1
LIBCLANG_LIBRARY_PATH=$<TARGET_FILE_DIR:libclang>
- "${Python3_EXECUTABLE}" -W ignore:DeprecationWarning::clang -m unittest discover
+ "${Python3_EXECUTABLE}" -m unittest discover
DEPENDS libclang
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/..)
diff --git a/clang/bindings/python/tests/cindex/test_code_completion.py b/clang/bindings/python/tests/cindex/test_code_completion.py
index e3a340c061434..b0832e9fc98b1 100644
--- a/clang/bindings/python/tests/cindex/test_code_completion.py
+++ b/clang/bindings/python/tests/cindex/test_code_completion.py
@@ -9,6 +9,7 @@
import unittest
from pathlib import Path
+import warnings
class TestCodeCompletion(unittest.TestCase):
@@ -16,7 +17,8 @@ def check_completion_results(self, cr, expected):
self.assertIsNotNone(cr)
self.assertEqual(len(cr.diagnostics), 0)
- completions = [str(c) for c in cr.results]
+ with warnings.catch_warnings(record=True):
+ completions = [str(c) for c in cr.results]
for c in expected:
self.assertIn(c, completions)
@@ -180,7 +182,8 @@ def test_compat_str(self):
}
for id, string in kindStringMap.items():
kind = CompletionString.AvailabilityKindCompat.from_id(id)
- self.assertEqual(str(kind), string)
+ with warnings.catch_warnings(record=True):
+ self.assertEqual(str(kind), string)
def test_completion_chunk_kind_compatibility(self):
value_to_old_str = {
@@ -210,12 +213,14 @@ def test_completion_chunk_kind_compatibility(self):
# Check that all new kinds correspond to an old kind
for new_kind in CompletionChunkKind:
old_str = value_to_old_str[new_kind.value]
- self.assertEqual(old_str, str(new_kind))
+ with warnings.catch_warnings(record=True):
+ self.assertEqual(old_str, str(new_kind))
# 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)
- self.assertEqual(old_str, str(new_kind))
+ with warnings.catch_warnings(record=True):
+ self.assertEqual(old_str, str(new_kind))
def test_spelling_cache_missing_attribute(self):
# Test that accessing missing attributes on SpellingCacheAlias raises
@@ -227,9 +232,10 @@ def test_spelling_cache_alias(self):
kind_keys = list(CompletionChunk.SPELLING_CACHE)
self.assertEqual(len(kind_keys), 13)
for kind_key in kind_keys:
- self.assertEqual(
- SPELLING_CACHE[kind_key.value], CompletionChunk.SPELLING_CACHE[kind_key]
- )
+ with warnings.catch_warnings(record=True):
+ self.assertEqual(
+ SPELLING_CACHE[kind_key.value], CompletionChunk.SPELLING_CACHE[kind_key]
+ )
def test_spelling_cache_missing_attribute(self):
# Test that accessing missing attributes on SpellingCacheAlias raises
More information about the cfe-commits
mailing list