Repository: llvm/llvm-project
Pull request #132378: [libclang/python] Change all global variables to snake case
Author: login: DeinAlptraum
Labels: name: clang
description: Clang issues not falling into any other category
name: clang:as-a-library
description: libclang and C++ API
Created: 2025-03-21T12:04:33Z | Merged: 2025-03-22T01:40:20Z



Diff:
diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py
index 879a0a3c5c58c..e881bf131d6c4 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -2786,7 +2786,7 @@ class _CXUnsavedFile(Structure):
 # Functions calls through the python interface are rather slow. Fortunately,
 # for most symboles, we do not need to perform a function call. Their spelling
 # never changes and is consequently provided by this spelling cache.
-SpellingCache = {
+spelling_cache = {
     # 0: CompletionChunk.Kind("Optional"),
     # 1: CompletionChunk.Kind("TypedText"),
     # 2: CompletionChunk.Kind("Text"),
@@ -2832,8 +2832,8 @@ def __repr__(self):
 
     @CachedProperty
     def spelling(self):
-        if self.__kindNumber in SpellingCache:
-            return SpellingCache[self.__kindNumber]
+        if self.__kindNumber in spelling_cache:
+            return spelling_cache[self.__kindNumber]
         return _CXString.from_result(
             conf.lib.clang_getCompletionChunkText(self.cs, self.key)
         )
@@ -3830,7 +3830,7 @@ def set_property(self, property, value):
 fields_visit_callback = CFUNCTYPE(c_int, Cursor, py_object)
 
 # Functions strictly alphabetical order.
-functionList: list[LibFunc] = [
+function_list: list[LibFunc] = [
     (
         "clang_annotateTokens",
         [TranslationUnit, POINTER(Token), c_uint, POINTER(Cursor)],
@@ -4108,7 +4108,7 @@ def register_functions(lib: CDLL, ignore_errors: bool) -> None:
     def register(item: LibFunc) -> None:
         register_function(lib, item, ignore_errors)
 
-    for f in functionList:
+    for f in function_list:
         register(f)
 
 
diff --git a/clang/bindings/python/tests/cindex/test_cdb.py b/clang/bindings/python/tests/cindex/test_cdb.py
index 342a544c86337..6e31119206168 100644
--- a/clang/bindings/python/tests/cindex/test_cdb.py
+++ b/clang/bindings/python/tests/cindex/test_cdb.py
@@ -10,7 +10,7 @@
 import sys
 from pathlib import Path
 
-kInputsDir = os.path.join(os.path.dirname(__file__), "INPUTS")
+inputs_dir = os.path.join(os.path.dirname(__file__), "INPUTS")
 
 
 @unittest.skipIf(sys.platform == "win32", "TODO: Fix these tests on Windows")
@@ -34,23 +34,23 @@ def test_create_fail(self):
 
     def test_create(self):
         """Check we can load a compilation database"""
-        CompilationDatabase.fromDirectory(kInputsDir)
+        CompilationDatabase.fromDirectory(inputs_dir)
 
     def test_lookup_succeed(self):
         """Check we get some results if the file exists in the db"""
-        cdb = CompilationDatabase.fromDirectory(kInputsDir)
+        cdb = CompilationDatabase.fromDirectory(inputs_dir)
         cmds = cdb.getCompileCommands("/home/john.doe/MyProject/project.cpp")
         self.assertNotEqual(len(cmds), 0)
 
     def test_lookup_succeed_pathlike(self):
         """Same as test_lookup_succeed, but with PathLikes"""
-        cdb = CompilationDatabase.fromDirectory(Path(kInputsDir))
+        cdb = CompilationDatabase.fromDirectory(Path(inputs_dir))
         cmds = cdb.getCompileCommands(Path("/home/john.doe/MyProject/project.cpp"))
         self.assertNotEqual(len(cmds), 0)
 
     def test_all_compilecommand(self):
         """Check we get all results from the db"""
-        cdb = CompilationDatabase.fromDirectory(kInputsDir)
+        cdb = CompilationDatabase.fromDirectory(inputs_dir)
         cmds = cdb.getAllCompileCommands()
         self.assertEqual(len(cmds), 3)
         expected = [
@@ -100,7 +100,7 @@ def test_all_compilecommand(self):
 
     def test_1_compilecommand(self):
         """Check file with single compile command"""
-        cdb = CompilationDatabase.fromDirectory(kInputsDir)
+        cdb = CompilationDatabase.fromDirectory(inputs_dir)
         file = "/home/john.doe/MyProject/project.cpp"
         cmds = cdb.getCompileCommands(file)
         self.assertEqual(len(cmds), 1)
@@ -119,7 +119,7 @@ def test_1_compilecommand(self):
 
     def test_2_compilecommand(self):
         """Check file with 2 compile commands"""
-        cdb = CompilationDatabase.fromDirectory(kInputsDir)
+        cdb = CompilationDatabase.fromDirectory(inputs_dir)
         cmds = cdb.getCompileCommands("/home/john.doe/MyProject/project2.cpp")
         self.assertEqual(len(cmds), 2)
         expected = [
@@ -154,7 +154,7 @@ def test_2_compilecommand(self):
 
     def test_compilecommand_iterator_stops(self):
         """Check that iterator stops after the correct number of elements"""
-        cdb = CompilationDatabase.fromDirectory(kInputsDir)
+        cdb = CompilationDatabase.fromDirectory(inputs_dir)
         count = 0
         for cmd in cdb.getCompileCommands("/home/john.doe/MyProject/project2.cpp"):
             count += 1
@@ -162,7 +162,7 @@ def test_compilecommand_iterator_stops(self):
 
     def test_compilationDB_references(self):
         """Ensure CompilationsCommands are independent of the database"""
-        cdb = CompilationDatabase.fromDirectory(kInputsDir)
+        cdb = CompilationDatabase.fromDirectory(inputs_dir)
         cmds = cdb.getCompileCommands("/home/john.doe/MyProject/project.cpp")
         del cdb
         gc.collect()
@@ -170,7 +170,7 @@ def test_compilationDB_references(self):
 
     def test_compilationCommands_references(self):
         """Ensure CompilationsCommand keeps a reference to CompilationCommands"""
-        cdb = CompilationDatabase.fromDirectory(kInputsDir)
+        cdb = CompilationDatabase.fromDirectory(inputs_dir)
         cmds = cdb.getCompileCommands("/home/john.doe/MyProject/project.cpp")
         del cdb
         cmd0 = cmds[0]
diff --git a/clang/bindings/python/tests/cindex/test_cursor.py b/clang/bindings/python/tests/cindex/test_cursor.py
index c6aa65ce3c29f..beecfadd00858 100644
--- a/clang/bindings/python/tests/cindex/test_cursor.py
+++ b/clang/bindings/python/tests/cindex/test_cursor.py
@@ -21,7 +21,7 @@
 
 from .util import get_cursor, get_cursors, get_tu
 
-kInput = """\
+children_test = """\
 struct s0 {
   int a;
   int b;
@@ -41,7 +41,7 @@
 }
 """
 
-kParentTest = """\
+parent_test = """\
         class C {
             void f();
         }
@@ -49,7 +49,7 @@ class C {
         void C::f() { }
     """
 
-kTemplateArgTest = """\
+template_arg_test = """\
         template <int kInt, typename T, bool kBool>
         void foo();
 
@@ -57,7 +57,7 @@ class C {
         void foo<-7, float, true>();
     """
 
-kBinops = """\
+binops = """\
 struct C {
    int m;
  };
@@ -118,7 +118,7 @@ class C {
 
 class TestCursor(unittest.TestCase):
     def test_get_children(self):
-        tu = get_tu(kInput)
+        tu = get_tu(children_test)
 
         it = tu.cursor.get_children()
         tu_nodes = list(it)
@@ -613,7 +613,7 @@ def test_underlying_type(self):
         self.assertEqual(underlying.kind, TypeKind.INT)
 
     def test_semantic_parent(self):
-        tu = get_tu(kParentTest, "cpp")
+        tu = get_tu(parent_test, "cpp")
         curs = get_cursors(tu, "f")
         decl = get_cursor(tu, "C")
         self.assertEqual(len(curs), 2)
@@ -621,7 +621,7 @@ def test_semantic_parent(self):
         self.assertEqual(curs[0].semantic_parent, decl)
 
     def test_lexical_parent(self):
-        tu = get_tu(kParentTest, "cpp")
+        tu = get_tu(parent_test, "cpp")
         curs = get_cursors(tu, "f")
         decl = get_cursor(tu, "C")
         self.assertEqual(len(curs), 2)
@@ -865,13 +865,13 @@ def test_get_arguments(self):
         self.assertEqual(arguments[1].spelling, "j")
 
     def test_get_num_template_arguments(self):
-        tu = get_tu(kTemplateArgTest, lang="cpp")
+        tu = get_tu(template_arg_test, lang="cpp")
         foos = get_cursors(tu, "foo")
 
         self.assertEqual(foos[1].get_num_template_arguments(), 3)
 
     def test_get_template_argument_kind(self):
-        tu = get_tu(kTemplateArgTest, lang="cpp")
+        tu = get_tu(template_arg_test, lang="cpp")
         foos = get_cursors(tu, "foo")
 
         self.assertEqual(
@@ -885,20 +885,20 @@ def test_get_template_argument_kind(self):
         )
 
     def test_get_template_argument_type(self):
-        tu = get_tu(kTemplateArgTest, lang="cpp")
+        tu = get_tu(template_arg_test, lang="cpp")
         foos = get_cursors(tu, "foo")
 
         self.assertEqual(foos[1].get_template_argument_type(1).kind, TypeKind.FLOAT)
 
     def test_get_template_argument_value(self):
-        tu = get_tu(kTemplateArgTest, lang="cpp")
+        tu = get_tu(template_arg_test, lang="cpp")
         foos = get_cursors(tu, "foo")
 
         self.assertEqual(foos[1].get_template_argument_value(0), -7)
         self.assertEqual(foos[1].get_template_argument_value(2), True)
 
     def test_get_template_argument_unsigned_value(self):
-        tu = get_tu(kTemplateArgTest, lang="cpp")
+        tu = get_tu(template_arg_test, lang="cpp")
         foos = get_cursors(tu, "foo")
 
         self.assertEqual(foos[1].get_template_argument_unsigned_value(0), 2**32 - 7)
@@ -930,7 +930,7 @@ def test_mangled_name(self):
         )
 
     def test_binop(self):
-        tu = get_tu(kBinops, lang="cpp")
+        tu = get_tu(binops, lang="cpp")
 
         operators = {
             # not exposed yet
diff --git a/clang/bindings/python/tests/cindex/test_index.py b/clang/bindings/python/tests/cindex/test_index.py
index 756f4bd9c7dfb..46ae2da18aa04 100644
--- a/clang/bindings/python/tests/cindex/test_index.py
+++ b/clang/bindings/python/tests/cindex/test_index.py
@@ -7,7 +7,7 @@
 
 import unittest
 
-kInputsDir = os.path.join(os.path.dirname(__file__), "INPUTS")
+inputs_dir = os.path.join(os.path.dirname(__file__), "INPUTS")
 
 
 class TestIndex(unittest.TestCase):
@@ -19,7 +19,7 @@ def test_create(self):
     def test_parse(self):
         index = Index.create()
         self.assertIsInstance(index, Index)
-        tu = index.parse(os.path.join(kInputsDir, "hello.cpp"))
+        tu = index.parse(os.path.join(inputs_dir, "hello.cpp"))
         self.assertIsInstance(tu, TranslationUnit)
-        tu = index.parse(None, ["-c", os.path.join(kInputsDir, "hello.cpp")])
+        tu = index.parse(None, ["-c", os.path.join(inputs_dir, "hello.cpp")])
         self.assertIsInstance(tu, TranslationUnit)
diff --git a/clang/bindings/python/tests/cindex/test_location.py b/clang/bindings/python/tests/cindex/test_location.py
index bbf79126ab1f8..19867877ea227 100644
--- a/clang/bindings/python/tests/cindex/test_location.py
+++ b/clang/bindings/python/tests/cindex/test_location.py
@@ -16,7 +16,7 @@
 
 from .util import get_cursor, get_tu
 
-baseInput = "int one;\nint two;\n"
+base_input = "int one;\nint two;\n"
 
 
 class TestLocation(unittest.TestCase):
@@ -26,7 +26,7 @@ def assert_location(self, loc, line, column, offset):
         self.assertEqual(loc.offset, offset)
 
     def test_location(self):
-        tu = get_tu(baseInput)
+        tu = get_tu(base_input)
         one = get_cursor(tu, "one")
         two = get_cursor(tu, "two")
 
@@ -37,7 +37,7 @@ def test_location(self):
         self.assert_location(two.location, line=2, column=5, offset=13)
 
         # adding a linebreak at top should keep columns same
-        tu = get_tu("\n" + baseInput)
+        tu = get_tu("\n" + base_input)
         one = get_cursor(tu, "one")
         two = get_cursor(tu, "two")
 
@@ -48,7 +48,7 @@ def test_location(self):
         self.assert_location(two.location, line=3, column=5, offset=14)
 
         # adding a space should affect column on first line only
-        tu = get_tu(" " + baseInput)
+        tu = get_tu(" " + base_input)
         one = get_cursor(tu, "one")
         two = get_cursor(tu, "two")
 
@@ -57,7 +57,7 @@ def test_location(self):
 
         # define the expected location ourselves and see if it matches
         # the returned location
-        tu = get_tu(baseInput)
+        tu = get_tu(base_input)
 
         file = File.from_name(tu, "t.c")
         location = SourceLocation.from_position(tu, file, 1, 5)
@@ -83,20 +83,20 @@ def test_location(self):
         self.assertTrue(verified)
 
     def test_extent(self):
-        tu = get_tu(baseInput)
+        tu = get_tu(base_input)
         one = get_cursor(tu, "one")
         two = get_cursor(tu, "two")
 
         self.assert_location(one.extent.start, line=1, column=1, offset=0)
         self.assert_location(one.extent.end, line=1, column=8, offset=7)
         self.assertEqual(
-            baseInput[one.extent.start.offset : one.extent.end.offset], "int one"
+            base_input[one.extent.start.offset : one.extent.end.offset], "int one"
         )
 
         self.assert_location(two.extent.start, line=2, column=1, offset=9)
         self.assert_location(two.extent.end, line=2, column=8, offset=16)
         self.assertEqual(
-            baseInput[two.extent.start.offset : two.extent.end.offset], "int two"
+            base_input[two.extent.start.offset : two.extent.end.offset], "int two"
         )
 
         file = File.from_name(tu, "t.c")
diff --git a/clang/bindings/python/tests/cindex/test_translation_unit.py b/clang/bindings/python/tests/cindex/test_translation_unit.py
index 56bf374241755..9387358f88ea2 100644
--- a/clang/bindings/python/tests/cindex/test_translation_unit.py
+++ b/clang/bindings/python/tests/cindex/test_translation_unit.py
@@ -24,7 +24,7 @@
 
 from .util import get_cursor, get_tu
 
-kInputsDir = os.path.join(os.path.dirname(__file__), "INPUTS")
+inputs_dir = os.path.join(os.path.dirname(__file__), "INPUTS")
 
 
 @contextmanager
@@ -51,26 +51,26 @@ def save_tu_pathlike(tu):
 
 class TestTranslationUnit(unittest.TestCase):
     def test_spelling(self):
-        path = os.path.join(kInputsDir, "hello.cpp")
+        path = os.path.join(inputs_dir, "hello.cpp")
         tu = TranslationUnit.from_source(path)
         self.assertEqual(tu.spelling, path)
 
     def test_cursor(self):
-        path = os.path.join(kInputsDir, "hello.cpp")
+        path = os.path.join(inputs_dir, "hello.cpp")
         tu = get_tu(path)
         c = tu.cursor
         self.assertIsInstance(c, Cursor)
         self.assertIs(c.kind, CursorKind.TRANSLATION_UNIT)
 
     def test_parse_arguments(self):
-        path = os.path.join(kInputsDir, "parse_arguments.c")
+        path = os.path.join(inputs_dir, "parse_arguments.c")
         tu = TranslationUnit.from_source(path, ["-DDECL_ONE=hello", "-DDECL_TWO=hi"])
         spellings = [c.spelling for c in tu.cursor.get_children()]
         self.assertEqual(spellings[-2], "hello")
         self.assertEqual(spellings[-1], "hi")
 
     def test_reparse_arguments(self):
-        path = os.path.join(kInputsDir, "parse_arguments.c")
+        path = os.path.join(inputs_dir, "parse_arguments.c")
         tu = TranslationUnit.from_source(path, ["-DDECL_ONE=hello", "-DDECL_TWO=hi"])
         tu.reparse()
         spellings = [c.spelling for c in tu.cursor.get_children()]
@@ -150,10 +150,10 @@ def eq(expected, actual):
             else:
                 self.assert_normpaths_equal(expected[1], actual.include.name)
 
-        src = os.path.join(kInputsDir, "include.cpp")
-        h1 = os.path.join(kInputsDir, "header1.h")
-        h2 = os.path.join(kInputsDir, "header2.h")
-        h3 = os.path.join(kInputsDir, "header3.h")
+        src = os.path.join(inputs_dir, "include.cpp")
+        h1 = os.path.join(inputs_dir, "header1.h")
+        h2 = os.path.join(inputs_dir, "header2.h")
+        h3 = os.path.join(inputs_dir, "header3.h")
         inc = [(src, h1), (h1, h3), (src, h2), (h2, h3)]
 
         tu = TranslationUnit.from_source(src)
@@ -161,10 +161,10 @@ def eq(expected, actual):
             eq(i[0], i[1])
 
     def test_inclusion_directive(self):
-        src = os.path.join(kInputsDir, "include.cpp")
-        h1 = os.path.join(kInputsDir, "header1.h")
-        h2 = os.path.join(kInputsDir, "header2.h")
-        h3 = os.path.join(kInputsDir, "header3.h")
+        src = os.path.join(inputs_dir, "include.cpp")
+        h1 = os.path.join(inputs_dir, "header1.h")
+        h2 = os.path.join(inputs_dir, "header2.h")
+        h3 = os.path.join(inputs_dir, "header3.h")
         inc = [h1, h3, h2, h3, h1]
 
         tu = TranslationUnit.from_source(
@@ -244,7 +244,7 @@ def test_load_pathlike(self):
             del tu2
 
     def test_index_parse(self):
-        path = os.path.join(kInputsDir, "hello.cpp")
+        path = os.path.join(inputs_dir, "hello.cpp")
         index = Index.create()
         tu = index.parse(path)
         self.assertIsInstance(tu, TranslationUnit)
@@ -341,7 +341,7 @@ def test_get_tokens_gc(self):
         gc.collect()  # Just in case.
 
     def test_fail_from_source(self):
-        path = os.path.join(kInputsDir, "non-existent.cpp")
+        path = os.path.join(inputs_dir, "non-existent.cpp")
         try:
             tu = TranslationUnit.from_source(path)
         except TranslationUnitLoadError:
@@ -349,7 +349,7 @@ def test_fail_from_source(self):
         self.assertEqual(tu, None)
 
     def test_fail_from_ast_file(self):
-        path = os.path.join(kInputsDir, "non-existent.ast")
+        path = os.path.join(inputs_dir, "non-existent.ast")
         try:
             tu = TranslationUnit.from_ast_file(path)
         except TranslationUnitLoadError:
diff --git a/clang/bindings/python/tests/cindex/test_type.py b/clang/bindings/python/tests/cindex/test_type.py
index bc893d509524e..7b929065dec04 100644
--- a/clang/bindings/python/tests/cindex/test_type.py
+++ b/clang/bindings/python/tests/cindex/test_type.py
@@ -18,7 +18,7 @@
 
 from .util import get_cursor, get_cursors, get_tu
 
-kInput = """\
+struct_input = """\
 
 typedef int I;
 
@@ -36,7 +36,7 @@
 """
 
 
-constarrayInput = """
+constarray_input = """
 struct teststruct {
   void *A[2];
 };
@@ -45,7 +45,7 @@
 
 class TestType(unittest.TestCase):
     def test_a_struct(self):
-        tu = get_tu(kInput)
+        tu = get_tu(struct_input)
 
         teststruct = get_cursor(tu, "teststruct")
         self.assertIsNotNone(teststruct, "Could not find teststruct.")
@@ -143,7 +143,7 @@ def test_references(self):
         t.get_declaration()
 
     def testConstantArray(self):
-        tu = get_tu(constarrayInput)
+        tu = get_tu(constarray_input)
 
         teststruct = get_cursor(tu, "teststruct")
         self.assertIsNotNone(teststruct, "Didn't find teststruct??")


Reviews:
user: login: Endilll
body: LGTM otherwise
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-22T00:14:15Z
user: login: DeinAlptraum
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-22T00:23:53Z
user: login: Endilll
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-22T01:21:56Z
user: login: Endilll
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-03-22T01:22:16Z

Review comments:
diff_hunk: @@ -10,7 +10,7 @@
 import sys
 from pathlib import Path
 
-kInputsDir = os.path.join(os.path.dirname(__file__), "INPUTS")
+k_inputs_dir = os.path.join(os.path.dirname(__file__), "INPUTS")
path: clang/bindings/python/tests/cindex/test_cdb.py
user: login: Endilll
body: Can you also drop `k_` prefix? According to PEP 8, naming convention for global variables is the same as for functions, and we don't prefix functions with `k_`.
created_at: 2025-03-22T00:13:22Z
author_association: CONTRIBUTOR
diff_hunk: @@ -10,7 +10,7 @@
 import sys
 from pathlib import Path
 
-kInputsDir = os.path.join(os.path.dirname(__file__), "INPUTS")
+k_inputs_dir = os.path.join(os.path.dirname(__file__), "INPUTS")
path: clang/bindings/python/tests/cindex/test_cdb.py
user: login: DeinAlptraum
body: Sounds good. I've been wondering the entire time what the `k` us supposed to stand for.
created_at: 2025-03-22T00:23:53Z
author_association: CONTRIBUTOR
diff_hunk: @@ -10,7 +10,7 @@
 import sys
 from pathlib import Path
 
-kInputsDir = os.path.join(os.path.dirname(__file__), "INPUTS")
+k_inputs_dir = os.path.join(os.path.dirname(__file__), "INPUTS")
path: clang/bindings/python/tests/cindex/test_cdb.py
user: login: Endilll
body: "Konstant", I guess
created_at: 2025-03-22T01:21:56Z
author_association: CONTRIBUTOR

PR comments:
user: login: llvmbot
created_at: 2025-03-21T12:05:05Z
body: 
<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Jannick Kremer (DeinAlptraum)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/132378.diff


7 Files Affected:

- (modified) clang/bindings/python/clang/cindex.py (+5-5) 
- (modified) clang/bindings/python/tests/cindex/test_cdb.py (+10-10) 
- (modified) clang/bindings/python/tests/cindex/test_cursor.py (+13-13) 
- (modified) clang/bindings/python/tests/cindex/test_index.py (+3-3) 
- (modified) clang/bindings/python/tests/cindex/test_location.py (+8-8) 
- (modified) clang/bindings/python/tests/cindex/test_translation_unit.py (+16-16) 
- (modified) clang/bindings/python/tests/cindex/test_type.py (+4-4) 


``````````diff
diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py
index 879a0a3c5c58c..e881bf131d6c4 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -2786,7 +2786,7 @@ class _CXUnsavedFile(Structure):
 # Functions calls through the python interface are rather slow. Fortunately,
 # for most symboles, we do not need to perform a function call. Their spelling
 # never changes and is consequently provided by this spelling cache.
-SpellingCache = {
+spelling_cache = {
     # 0: CompletionChunk.Kind("Optional"),
     # 1: CompletionChunk.Kind("TypedText"),
     # 2: CompletionChunk.Kind("Text"),
@@ -2832,8 +2832,8 @@ def __repr__(self):
 
     @CachedProperty
     def spelling(self):
-        if self.__kindNumber in SpellingCache:
-            return SpellingCache[self.__kindNumber]
+        if self.__kindNumber in spelling_cache:
+            return spelling_cache[self.__kindNumber]
         return _CXString.from_result(
             conf.lib.clang_getCompletionChunkText(self.cs, self.key)
         )
@@ -3830,7 +3830,7 @@ def set_property(self, property, value):
 fields_visit_callback = CFUNCTYPE(c_int, Cursor, py_object)
 
 # Functions strictly alphabetical order.
-functionList: list[LibFunc] = [
+function_list: list[LibFunc] = [
     (
         "clang_annotateTokens",
         [TranslationUnit, POINTER(Token), c_uint, POINTER(Cursor)],
@@ -4108,7 +4108,7 @@ def register_functions(lib: CDLL, ignore_errors: bool) -> None:
     def register(item: LibFunc) -> None:
         register_function(lib, item, ignore_errors)
 
-    for f in functionList:
+    for f in function_list:
         register(f)
 
 
diff --git a/clang/bindings/python/tests/cindex/test_cdb.py b/clang/bindings/python/tests/cindex/test_cdb.py
index 342a544c86337..c7727b729ad33 100644
--- a/clang/bindings/python/tests/cindex/test_cdb.py
+++ b/clang/bindings/python/tests/cindex/test_cdb.py
@@ -10,7 +10,7 @@
 import sys
 from pathlib import Path
 
-kInputsDir = os.path.join(os.path.dirname(__file__), "INPUTS")
+k_inputs_dir = os.path.join(os.path.dirname(__file__), "INPUTS")
 
 
 @unittest.skipIf(sys.platform == "win32", "TODO: Fix these tests on Windows")
@@ -34,23 +34,23 @@ def test_create_fail(self):
 
     def test_create(self):
         """Check we can load a compilation database"""
-        CompilationDatabase.fromDirectory(kInputsDir)
+        CompilationDatabase.fromDirectory(k_inputs_dir)
 
     def test_lookup_succeed(self):
         """Check we get some results if the file exists in the db"""
-        cdb = CompilationDatabase.fromDirectory(kInputsDir)
+        cdb = CompilationDatabase.fromDirectory(k_inputs_dir)
         cmds = cdb.getCompileCommands("/home/john.doe/MyProject/project.cpp")
         self.assertNotEqual(len(cmds), 0)
 
     def test_lookup_succeed_pathlike(self):
         """Same as test_lookup_succeed, but with PathLikes"""
-        cdb = CompilationDatabase.fromDirectory(Path(kInputsDir))
+        cdb = CompilationDatabase.fromDirectory(Path(k_inputs_dir))
         cmds = cdb.getCompileCommands(Path("/home/john.doe/MyProject/project.cpp"))
         self.assertNotEqual(len(cmds), 0)
 
     def test_all_compilecommand(self):
         """Check we get all results from the db"""
-        cdb = CompilationDatabase.fromDirectory(kInputsDir)
+        cdb = CompilationDatabase.fromDirectory(k_inputs_dir)
         cmds = cdb.getAllCompileCommands()
         self.assertEqual(len(cmds), 3)
         expected = [
@@ -100,7 +100,7 @@ def test_all_compilecommand(self):
 
     def test_1_compilecommand(self):
         """Check file with single compile command"""
-        cdb = CompilationDatabase.fromDirectory(kInputsDir)
+        cdb = CompilationDatabase.fromDirectory(k_inputs_dir)
         file = "/home/john.doe/MyProject/project.cpp"
         cmds = cdb.getCompileCommands(file)
         self.assertEqual(len(cmds), 1)
@@ -119,7 +119,7 @@ def test_1_compilecommand(self):
 
     def test_2_compilecommand(self):
         """Check file with 2 compile commands"""
-        cdb = CompilationDatabase.fromDirectory(kInputsDir)
+        cdb = CompilationDatabase.fromDirectory(k_inputs_dir)
         cmds = cdb.getCompileCommands("/home/john.doe/MyProject/project2.cpp")
         self.assertEqual(len(cmds), 2)
         expected = [
@@ -154,7 +154,7 @@ def test_2_compilecommand(self):
 
     def test_compilecommand_iterator_stops(self):
         """Check that iterator stops after the correct number of elements"""
-        cdb = CompilationDatabase.fromDirectory(kInputsDir)
+        cdb = CompilationDatabase.fromDirectory(k_inputs_dir)
         count = 0
         for cmd in cdb.getCompileCommands("/home/john.doe/MyProject/project2.cpp"):
             count += 1
@@ -162,7 +162,7 @@ def test_compilecommand_iterator_stops(self):
 
     def test_compilationDB_references(self):
         """Ensure CompilationsCommands are independent of the database"""
-        cdb = CompilationDatabase.fromDirectory(kInputsDir)
+        cdb = CompilationDatabase.fromDirectory(k_inputs_dir)
         cmds = cdb.getCompileCommands("/home/john.doe/MyProject/project.cpp")
         del cdb
         gc.collect()
@@ -170,7 +170,7 @@ def test_compilationDB_references(self):
 
     def test_compilationCommands_references(self):
         """Ensure CompilationsCommand keeps a reference to CompilationCommands"""
-        cdb = CompilationDatabase.fromDirectory(kInputsDir)
+        cdb = CompilationDatabase.fromDirectory(k_inputs_dir)
         cmds = cdb.getCompileCommands("/home/john.doe/MyProject/project.cpp")
         del cdb
         cmd0 = cmds[0]
diff --git a/clang/bindings/python/tests/cindex/test_cursor.py b/clang/bindings/python/tests/cindex/test_cursor.py
index c6aa65ce3c29f..5686aba83fe24 100644
--- a/clang/bindings/python/tests/cindex/test_cursor.py
+++ b/clang/bindings/python/tests/cindex/test_cursor.py
@@ -21,7 +21,7 @@
 
 from .util import get_cursor, get_cursors, get_tu
 
-kInput = """\
+k_input = """\
 struct s0 {
   int a;
   int b;
@@ -41,7 +41,7 @@
 }
 """
 
-kParentTest = """\
+k_parent_test = """\
         class C {
             void f();
         }
@@ -49,7 +49,7 @@ class C {
         void C::f() { }
     """
 
-kTemplateArgTest = """\
+k_template_arg_test = """\
         template <int kInt, typename T, bool kBool>
         void foo();
 
@@ -57,7 +57,7 @@ class C {
         void foo<-7, float, true>();
     """
 
-kBinops = """\
+k_binops = """\
 struct C {
    int m;
  };
@@ -118,7 +118,7 @@ class C {
 
 class TestCursor(unittest.TestCase):
     def test_get_children(self):
-        tu = get_tu(kInput)
+        tu = get_tu(k_input)
 
         it = tu.cursor.get_children()
         tu_nodes = list(it)
@@ -613,7 +613,7 @@ def test_underlying_type(self):
         self.assertEqual(underlying.kind, TypeKind.INT)
 
     def test_semantic_parent(self):
-        tu = get_tu(kParentTest, "cpp")
+        tu = get_tu(k_parent_test, "cpp")
         curs = get_cursors(tu, "f")
         decl = get_cursor(tu, "C")
         self.assertEqual(len(curs), 2)
@@ -621,7 +621,7 @@ def test_semantic_parent(self):
         self.assertEqual(curs[0].semantic_parent, decl)
 
     def test_lexical_parent(self):
-        tu = get_tu(kParentTest, "cpp")
+        tu = get_tu(k_parent_test, "cpp")
         curs = get_cursors(tu, "f")
         decl = get_cursor(tu, "C")
         self.assertEqual(len(curs), 2)
@@ -865,13 +865,13 @@ def test_get_arguments(self):
         self.assertEqual(arguments[1].spelling, "j")
 
     def test_get_num_template_arguments(self):
-        tu = get_tu(kTemplateArgTest, lang="cpp")
+        tu = get_tu(k_template_arg_test, lang="cpp")
         foos = get_cursors(tu, "foo")
 
         self.assertEqual(foos[1].get_num_template_arguments(), 3)
 
     def test_get_template_argument_kind(self):
-        tu = get_tu(kTemplateArgTest, lang="cpp")
+        tu = get_tu(k_template_arg_test, lang="cpp")
         foos = get_cursors(tu, "foo")
 
         self.assertEqual(
@@ -885,20 +885,20 @@ def test_get_template_argument_kind(self):
         )
 
     def test_get_template_argument_type(self):
-        tu = get_tu(kTemplateArgTest, lang="cpp")
+        tu = get_tu(k_template_arg_test, lang="cpp")
         foos = get_cursors(tu, "foo")
 
         self.assertEqual(foos[1].get_template_argument_type(1).kind, TypeKind.FLOAT)
 
     def test_get_template_argument_value(self):
-        tu = get_tu(kTemplateArgTest, lang="cpp")
+        tu = get_tu(k_template_arg_test, lang="cpp")
         foos = get_cursors(tu, "foo")
 
         self.assertEqual(foos[1].get_template_argument_value(0), -7)
         self.assertEqual(foos[1].get_template_argument_value(2), True)
 
     def test_get_template_argument_unsigned_value(self):
-        tu = get_tu(kTemplateArgTest, lang="cpp")
+        tu = get_tu(k_template_arg_test, lang="cpp")
         foos = get_cursors(tu, "foo")
 
         self.assertEqual(foos[1].get_template_argument_unsigned_value(0), 2**32 - 7)
@@ -930,7 +930,7 @@ def test_mangled_name(self):
         )
 
     def test_binop(self):
-        tu = get_tu(kBinops, lang="cpp")
+        tu = get_tu(k_binops, lang="cpp")
 
         operators = {
             # not exposed yet
diff --git a/clang/bindings/python/tests/cindex/test_index.py b/clang/bindings/python/tests/cindex/test_index.py
index 756f4bd9c7dfb..a799c48b4d65d 100644
--- a/clang/bindings/python/tests/cindex/test_index.py
+++ b/clang/bindings/python/tests/cindex/test_index.py
@@ -7,7 +7,7 @@
 
 import unittest
 
-kInputsDir = os.path.join(os.path.dirname(__file__), "INPUTS")
+k_inputs_dir = os.path.join(os.path.dirname(__file__), "INPUTS")
 
 
 class TestIndex(unittest.TestCase):
@@ -19,7 +19,7 @@ def test_create(self):
     def test_parse(self):
         index = Index.create()
         self.assertIsInstance(index, Index)
-        tu = index.parse(os.path.join(kInputsDir, "hello.cpp"))
+        tu = index.parse(os.path.join(k_inputs_dir, "hello.cpp"))
         self.assertIsInstance(tu, TranslationUnit)
-        tu = index.parse(None, ["-c", os.path.join(kInputsDir, "hello.cpp")])
+        tu = index.parse(None, ["-c", os.path.join(k_inputs_dir, "hello.cpp")])
         self.assertIsInstance(tu, TranslationUnit)
diff --git a/clang/bindings/python/tests/cindex/test_location.py b/clang/bindings/python/tests/cindex/test_location.py
index bbf79126ab1f8..19867877ea227 100644
--- a/clang/bindings/python/tests/cindex/test_location.py
+++ b/clang/bindings/python/tests/cindex/test_location.py
@@ -16,7 +16,7 @@
 
 from .util import get_cursor, get_tu
 
-baseInput = "int one;\nint two;\n"
+base_input = "int one;\nint two;\n"
 
 
 class TestLocation(unittest.TestCase):
@@ -26,7 +26,7 @@ def assert_location(self, loc, line, column, offset):
         self.assertEqual(loc.offset, offset)
 
     def test_location(self):
-        tu = get_tu(baseInput)
+        tu = get_tu(base_input)
         one = get_cursor(tu, "one")
         two = get_cursor(tu, "two")
 
@@ -37,7 +37,7 @@ def test_location(self):
         self.assert_location(two.location, line=2, column=5, offset=13)
 
         # adding a linebreak at top should keep columns same
-        tu = get_tu("\n" + baseInput)
+        tu = get_tu("\n" + base_input)
         one = get_cursor(tu, "one")
         two = get_cursor(tu, "two")
 
@@ -48,7 +48,7 @@ def test_location(self):
         self.assert_location(two.location, line=3, column=5, offset=14)
 
         # adding a space should affect column on first line only
-        tu = get_tu(" " + baseInput)
+        tu = get_tu(" " + base_input)
         one = get_cursor(tu, "one")
         two = get_cursor(tu, "two")
 
@@ -57,7 +57,7 @@ def test_location(self):
 
         # define the expected location ourselves and see if it matches
         # the returned location
-        tu = get_tu(baseInput)
+        tu = get_tu(base_input)
 
         file = File.from_name(tu, "t.c")
         location = SourceLocation.from_position(tu, file, 1, 5)
@@ -83,20 +83,20 @@ def test_location(self):
         self.assertTrue(verified)
 
     def test_extent(self):
-        tu = get_tu(baseInput)
+        tu = get_tu(base_input)
         one = get_cursor(tu, "one")
         two = get_cursor(tu, "two")
 
         self.assert_location(one.extent.start, line=1, column=1, offset=0)
         self.assert_location(one.extent.end, line=1, column=8, offset=7)
         self.assertEqual(
-            baseInput[one.extent.start.offset : one.extent.end.offset], "int one"
+            base_input[one.extent.start.offset : one.extent.end.offset], "int one"
         )
 
         self.assert_location(two.extent.start, line=2, column=1, offset=9)
         self.assert_location(two.extent.end, line=2, column=8, offset=16)
         self.assertEqual(
-            baseInput[two.extent.start.offset : two.extent.end.offset], "int two"
+            base_input[two.extent.start.offset : two.extent.end.offset], "int two"
         )
 
         file = File.from_name(tu, "t.c")
diff --git a/clang/bindings/python/tests/cindex/test_translation_unit.py b/clang/bindings/python/tests/cindex/test_translation_unit.py
index 56bf374241755..e886815f5ac3c 100644
--- a/clang/bindings/python/tests/cindex/test_translation_unit.py
+++ b/clang/bindings/python/tests/cindex/test_translation_unit.py
@@ -24,7 +24,7 @@
 
 from .util import get_cursor, get_tu
 
-kInputsDir = os.path.join(os.path.dirname(__file__), "INPUTS")
+k_inputs_dir = os.path.join(os.path.dirname(__file__), "INPUTS")
 
 
 @contextmanager
@@ -51,26 +51,26 @@ def save_tu_pathlike(tu):
 
 class TestTranslationUnit(unittest.TestCase):
     def test_spelling(self):
-        path = os.path.join(kInputsDir, "hello.cpp")
+        path = os.path.join(k_inputs_dir, "hello.cpp")
         tu = TranslationUnit.from_source(path)
         self.assertEqual(tu.spelling, path)
 
     def test_cursor(self):
-        path = os.path.join(kInputsDir, "hello.cpp")
+        path = os.path.join(k_inputs_dir, "hello.cpp")
         tu = get_tu(path)
         c = tu.cursor
         self.assertIsInstance(c, Cursor)
         self.assertIs(c.kind, CursorKind.TRANSLATION_UNIT)
 
     def test_parse_arguments(self):
-        path = os.path.join(kInputsDir, "parse_arguments.c")
+        path = os.path.join(k_inputs_dir, "parse_arguments.c")
         tu = TranslationUnit.from_source(path, ["-DDECL_ONE=hello", "-DDECL_TWO=hi"])
         spellings = [c.spelling for c in tu.cursor.get_children()]
         self.assertEqual(spellings[-2], "hello")
         self.assertEqual(spellings[-1], "hi")
 
     def test_reparse_arguments(self):
-        path = os.path.join(kInputsDir, "parse_arguments.c")
+        path = os.path.join(k_inputs_dir, "parse_arguments.c")
         tu = TranslationUnit.from_source(path, ["-DDECL_ONE=hello", "-DDECL_TWO=hi"])
         tu.reparse()
         spellings = [c.spelling for c in tu.cursor.get_children()]
@@ -150,10 +150,10 @@ def eq(expected, actual):
             else:
                 self.assert_normpaths_equal(expected[1], actual.include.name)
 
-        src = os.path.join(kInputsDir, "include.cpp")
-        h1 = os.path.join(kInputsDir, "header1.h")
-        h2 = os.path.join(kInputsDir, "header2.h")
-        h3 = os.path.join(kInputsDir, "header3.h")
+        src = os.path.join(k_inputs_dir, "include.cpp")
+        h1 = os.path.join(k_inputs_dir, "header1.h")
+        h2 = os.path.join(k_inputs_dir, "header2.h")
+        h3 = os.path.join(k_inputs_dir, "header3.h")
         inc = [(src, h1), (h1, h3), (src, h2), (h2, h3)]
 
         tu = TranslationUnit.from_source(src)
@@ -161,10 +161,10 @@ def eq(expected, actual):
             eq(i[0], i[1])
 
     def test_inclusion_directive(self):
-        src = os.path.join(kInputsDir, "include.cpp")
-        h1 = os.path.join(kInputsDir, "header1.h")
-        h2 = os.path.join(kInputsDir, "header2.h")
-        h3 = os.path.join(kInputsDir, "header3.h")
+        src = os.path.join(k_inputs_dir, "include.cpp")
+        h1 = os.path.join(k_inputs_dir, "header1.h")
+        h2 = os.path.join(k_inputs_dir, "header2.h")
+        h3 = os.path.join(k_inputs_dir, "header3.h")
         inc = [h1, h3, h2, h3, h1]
 
         tu = TranslationUnit.from_source(
@@ -244,7 +244,7 @@ def test_load_pathlike(self):
             del tu2
 
     def test_index_parse(self):
-        path = os.path.join(kInputsDir, "hello.cpp")
+        path = os.path.join(k_inputs_dir, "hello.cpp")
         index = Index.create()
         tu = index.parse(path)
         self.assertIsInstance(tu, TranslationUnit)
@@ -341,7 +341,7 @@ def test_get_tokens_gc(self):
         gc.collect()  # Just in case.
 
     def test_fail_from_source(self):
-        path = os.path.join(kInputsDir, "non-existent.cpp")
+        path = os.path.join(k_inputs_dir, "non-existent.cpp")
         try:
             tu = TranslationUnit.from_source(path)
         except TranslationUnitLoadError:
@@ -349,7 +349,7 @@ def test_fail_from_source(self):
         self.assertEqual(tu, None)
 
     def test_fail_from_ast_file(self):
-        path = os.path.join(kInputsDir, "non-existent.ast")
+        path = os.path.join(k_inputs_dir, "non-existent.ast")
         try:
             tu = TranslationUnit.from_ast_file(path)
         except TranslationUnitLoadError:
diff --git a/clang/bindings/python/tests/cindex/test_type.py b/clang/bindings/python/tests/cindex/test_type.py
index bc893d509524e..ab70aeb18c70b 100644
--- a/clang/bindings/python/tests/cindex/test_type.py
+++ b/clang/bindings/python/tests/cindex/test_type.py
@@ -18,7 +18,7 @@
 
 from .util import get_cursor, get_cursors, get_tu
 
-kInput = """\
+k_input = """\
 
 typedef int I;
 
@@ -36,7 +36,7 @@
 """
 
 
-constarrayInput = """
+constarray_input = """
 struct teststruct {
   void *A[2];
 };
@@ -45,7 +45,7 @@
 
 class TestType(unittest.TestCase):
     def test_a_struct(self):
-        tu = get_tu(kInput)
+        tu = get_tu(k_input)
 
         teststruct = get_cursor(tu, "teststruct")
         self.assertIsNotNone(teststruct, "Could not find teststruct.")
@@ -143,7 +143,7 @@ def test_references(self):
         t.get_declaration()
 
     def testConstantArray(self):
-        tu = get_tu(constarrayInput)
+        tu = get_tu(constarray_input)
 
         teststruct = get_cursor(tu, "teststruct")
         self.assertIsNotNone(teststruct, "Didn't find teststruct??")

``````````

</details>

author_association: MEMBER
user: login: Endilll
created_at: 2025-03-24T18:52:22Z
body: I was pointed out that there is a separate rule that constants are supposed to be in `SCREAMING_CAPS` (https://peps.python.org/pep-0008/#constants). We should've changed the names (`k` prefix is out of place anyway), but not to `snake_case` as I implied.
author_association: CONTRIBUTOR
user: login: Endilll
created_at: 2025-03-24T18:52:28Z
body: Sorry for the churn
author_association: CONTRIBUTOR
user: login: DeinAlptraum
created_at: 2025-03-24T23:12:21Z
body: That sounds more familiar, okay :D Will do a PR this week
author_association: CONTRIBUTOR