[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 08:18:28 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/5] 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/5] 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
>From c5c9f667f21b308606ec207f945382cb2dc5fb0b Mon Sep 17 00:00:00 2001
From: Jannick Kremer <jannick.kremer at mailbox.org>
Date: Fri, 30 Jan 2026 22:31:07 +0900
Subject: [PATCH 3/5] Fix formatting
---
clang/bindings/python/tests/cindex/test_code_completion.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/clang/bindings/python/tests/cindex/test_code_completion.py b/clang/bindings/python/tests/cindex/test_code_completion.py
index b0832e9fc98b1..c949666af7122 100644
--- a/clang/bindings/python/tests/cindex/test_code_completion.py
+++ b/clang/bindings/python/tests/cindex/test_code_completion.py
@@ -234,7 +234,8 @@ def test_spelling_cache_alias(self):
for kind_key in kind_keys:
with warnings.catch_warnings(record=True):
self.assertEqual(
- SPELLING_CACHE[kind_key.value], CompletionChunk.SPELLING_CACHE[kind_key]
+ SPELLING_CACHE[kind_key.value],
+ CompletionChunk.SPELLING_CACHE[kind_key]
)
def test_spelling_cache_missing_attribute(self):
>From 6e6507eabbcbbc636a2f7d1cbcec7d5f4b99da24 Mon Sep 17 00:00:00 2001
From: Jannick Kremer <jannick.kremer at mailbox.org>
Date: Fri, 30 Jan 2026 22:41:40 +0900
Subject: [PATCH 4/5] Fix formatting again
---
clang/bindings/python/tests/cindex/test_code_completion.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/bindings/python/tests/cindex/test_code_completion.py b/clang/bindings/python/tests/cindex/test_code_completion.py
index c949666af7122..eecd3bb0714a0 100644
--- a/clang/bindings/python/tests/cindex/test_code_completion.py
+++ b/clang/bindings/python/tests/cindex/test_code_completion.py
@@ -235,7 +235,7 @@ def test_spelling_cache_alias(self):
with warnings.catch_warnings(record=True):
self.assertEqual(
SPELLING_CACHE[kind_key.value],
- CompletionChunk.SPELLING_CACHE[kind_key]
+ CompletionChunk.SPELLING_CACHE[kind_key],
)
def test_spelling_cache_missing_attribute(self):
>From 9e2152aa2a61fe2c5c646d99fb541e886707b877 Mon Sep 17 00:00:00 2001
From: Jannick Kremer <jannick.kremer at mailbox.org>
Date: Sat, 31 Jan 2026 01:17:58 +0900
Subject: [PATCH 5/5] Assert deprecation warnings
---
.../tests/cindex/test_code_completion.py | 21 ++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/clang/bindings/python/tests/cindex/test_code_completion.py b/clang/bindings/python/tests/cindex/test_code_completion.py
index eecd3bb0714a0..91faebfec66c0 100644
--- a/clang/bindings/python/tests/cindex/test_code_completion.py
+++ b/clang/bindings/python/tests/cindex/test_code_completion.py
@@ -17,8 +17,11 @@ def check_completion_results(self, cr, expected):
self.assertIsNotNone(cr)
self.assertEqual(len(cr.diagnostics), 0)
- with warnings.catch_warnings(record=True):
+ with warnings.catch_warnings(record=True) as log:
completions = [str(c) for c in cr.results]
+ self.assertEqual(len(log), 2)
+ for warning in log:
+ self.assertIsInstance(warning.message, DeprecationWarning)
for c in expected:
self.assertIn(c, completions)
@@ -182,8 +185,10 @@ def test_compat_str(self):
}
for id, string in kindStringMap.items():
kind = CompletionString.AvailabilityKindCompat.from_id(id)
- with warnings.catch_warnings(record=True):
+ 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 = {
@@ -213,14 +218,18 @@ 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]
- with warnings.catch_warnings(record=True):
+ 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):
+ 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
@@ -232,11 +241,13 @@ 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):
+ 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
More information about the cfe-commits
mailing list