Skip to content

Commit 619ba92

Browse files
authored
[libclang/python] Change all global variables to snake case (#132378)
1 parent 4adefcf commit 619ba92

File tree

7 files changed

+59
-59
lines changed

7 files changed

+59
-59
lines changed

clang/bindings/python/clang/cindex.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2786,7 +2786,7 @@ class _CXUnsavedFile(Structure):
27862786
# Functions calls through the python interface are rather slow. Fortunately,
27872787
# for most symboles, we do not need to perform a function call. Their spelling
27882788
# never changes and is consequently provided by this spelling cache.
2789-
SpellingCache = {
2789+
spelling_cache = {
27902790
# 0: CompletionChunk.Kind("Optional"),
27912791
# 1: CompletionChunk.Kind("TypedText"),
27922792
# 2: CompletionChunk.Kind("Text"),
@@ -2832,8 +2832,8 @@ def __repr__(self):
28322832

28332833
@CachedProperty
28342834
def spelling(self):
2835-
if self.__kindNumber in SpellingCache:
2836-
return SpellingCache[self.__kindNumber]
2835+
if self.__kindNumber in spelling_cache:
2836+
return spelling_cache[self.__kindNumber]
28372837
return _CXString.from_result(
28382838
conf.lib.clang_getCompletionChunkText(self.cs, self.key)
28392839
)
@@ -3830,7 +3830,7 @@ def set_property(self, property, value):
38303830
fields_visit_callback = CFUNCTYPE(c_int, Cursor, py_object)
38313831

38323832
# Functions strictly alphabetical order.
3833-
functionList: list[LibFunc] = [
3833+
function_list: list[LibFunc] = [
38343834
(
38353835
"clang_annotateTokens",
38363836
[TranslationUnit, POINTER(Token), c_uint, POINTER(Cursor)],
@@ -4108,7 +4108,7 @@ def register_functions(lib: CDLL, ignore_errors: bool) -> None:
41084108
def register(item: LibFunc) -> None:
41094109
register_function(lib, item, ignore_errors)
41104110

4111-
for f in functionList:
4111+
for f in function_list:
41124112
register(f)
41134113

41144114

clang/bindings/python/tests/cindex/test_cdb.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import sys
1111
from pathlib import Path
1212

13-
kInputsDir = os.path.join(os.path.dirname(__file__), "INPUTS")
13+
inputs_dir = os.path.join(os.path.dirname(__file__), "INPUTS")
1414

1515

1616
@unittest.skipIf(sys.platform == "win32", "TODO: Fix these tests on Windows")
@@ -34,23 +34,23 @@ def test_create_fail(self):
3434

3535
def test_create(self):
3636
"""Check we can load a compilation database"""
37-
CompilationDatabase.fromDirectory(kInputsDir)
37+
CompilationDatabase.fromDirectory(inputs_dir)
3838

3939
def test_lookup_succeed(self):
4040
"""Check we get some results if the file exists in the db"""
41-
cdb = CompilationDatabase.fromDirectory(kInputsDir)
41+
cdb = CompilationDatabase.fromDirectory(inputs_dir)
4242
cmds = cdb.getCompileCommands("/home/john.doe/MyProject/project.cpp")
4343
self.assertNotEqual(len(cmds), 0)
4444

4545
def test_lookup_succeed_pathlike(self):
4646
"""Same as test_lookup_succeed, but with PathLikes"""
47-
cdb = CompilationDatabase.fromDirectory(Path(kInputsDir))
47+
cdb = CompilationDatabase.fromDirectory(Path(inputs_dir))
4848
cmds = cdb.getCompileCommands(Path("/home/john.doe/MyProject/project.cpp"))
4949
self.assertNotEqual(len(cmds), 0)
5050

5151
def test_all_compilecommand(self):
5252
"""Check we get all results from the db"""
53-
cdb = CompilationDatabase.fromDirectory(kInputsDir)
53+
cdb = CompilationDatabase.fromDirectory(inputs_dir)
5454
cmds = cdb.getAllCompileCommands()
5555
self.assertEqual(len(cmds), 3)
5656
expected = [
@@ -100,7 +100,7 @@ def test_all_compilecommand(self):
100100

101101
def test_1_compilecommand(self):
102102
"""Check file with single compile command"""
103-
cdb = CompilationDatabase.fromDirectory(kInputsDir)
103+
cdb = CompilationDatabase.fromDirectory(inputs_dir)
104104
file = "/home/john.doe/MyProject/project.cpp"
105105
cmds = cdb.getCompileCommands(file)
106106
self.assertEqual(len(cmds), 1)
@@ -119,7 +119,7 @@ def test_1_compilecommand(self):
119119

120120
def test_2_compilecommand(self):
121121
"""Check file with 2 compile commands"""
122-
cdb = CompilationDatabase.fromDirectory(kInputsDir)
122+
cdb = CompilationDatabase.fromDirectory(inputs_dir)
123123
cmds = cdb.getCompileCommands("/home/john.doe/MyProject/project2.cpp")
124124
self.assertEqual(len(cmds), 2)
125125
expected = [
@@ -154,23 +154,23 @@ def test_2_compilecommand(self):
154154

155155
def test_compilecommand_iterator_stops(self):
156156
"""Check that iterator stops after the correct number of elements"""
157-
cdb = CompilationDatabase.fromDirectory(kInputsDir)
157+
cdb = CompilationDatabase.fromDirectory(inputs_dir)
158158
count = 0
159159
for cmd in cdb.getCompileCommands("/home/john.doe/MyProject/project2.cpp"):
160160
count += 1
161161
self.assertLessEqual(count, 2)
162162

163163
def test_compilationDB_references(self):
164164
"""Ensure CompilationsCommands are independent of the database"""
165-
cdb = CompilationDatabase.fromDirectory(kInputsDir)
165+
cdb = CompilationDatabase.fromDirectory(inputs_dir)
166166
cmds = cdb.getCompileCommands("/home/john.doe/MyProject/project.cpp")
167167
del cdb
168168
gc.collect()
169169
cmds[0].directory
170170

171171
def test_compilationCommands_references(self):
172172
"""Ensure CompilationsCommand keeps a reference to CompilationCommands"""
173-
cdb = CompilationDatabase.fromDirectory(kInputsDir)
173+
cdb = CompilationDatabase.fromDirectory(inputs_dir)
174174
cmds = cdb.getCompileCommands("/home/john.doe/MyProject/project.cpp")
175175
del cdb
176176
cmd0 = cmds[0]

clang/bindings/python/tests/cindex/test_cursor.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
from .util import get_cursor, get_cursors, get_tu
2323

24-
kInput = """\
24+
children_test = """\
2525
struct s0 {
2626
int a;
2727
int b;
@@ -41,23 +41,23 @@
4141
}
4242
"""
4343

44-
kParentTest = """\
44+
parent_test = """\
4545
class C {
4646
void f();
4747
}
4848
4949
void C::f() { }
5050
"""
5151

52-
kTemplateArgTest = """\
52+
template_arg_test = """\
5353
template <int kInt, typename T, bool kBool>
5454
void foo();
5555
5656
template<>
5757
void foo<-7, float, true>();
5858
"""
5959

60-
kBinops = """\
60+
binops = """\
6161
struct C {
6262
int m;
6363
};
@@ -118,7 +118,7 @@ class C {
118118

119119
class TestCursor(unittest.TestCase):
120120
def test_get_children(self):
121-
tu = get_tu(kInput)
121+
tu = get_tu(children_test)
122122

123123
it = tu.cursor.get_children()
124124
tu_nodes = list(it)
@@ -613,15 +613,15 @@ def test_underlying_type(self):
613613
self.assertEqual(underlying.kind, TypeKind.INT)
614614

615615
def test_semantic_parent(self):
616-
tu = get_tu(kParentTest, "cpp")
616+
tu = get_tu(parent_test, "cpp")
617617
curs = get_cursors(tu, "f")
618618
decl = get_cursor(tu, "C")
619619
self.assertEqual(len(curs), 2)
620620
self.assertEqual(curs[0].semantic_parent, curs[1].semantic_parent)
621621
self.assertEqual(curs[0].semantic_parent, decl)
622622

623623
def test_lexical_parent(self):
624-
tu = get_tu(kParentTest, "cpp")
624+
tu = get_tu(parent_test, "cpp")
625625
curs = get_cursors(tu, "f")
626626
decl = get_cursor(tu, "C")
627627
self.assertEqual(len(curs), 2)
@@ -865,13 +865,13 @@ def test_get_arguments(self):
865865
self.assertEqual(arguments[1].spelling, "j")
866866

867867
def test_get_num_template_arguments(self):
868-
tu = get_tu(kTemplateArgTest, lang="cpp")
868+
tu = get_tu(template_arg_test, lang="cpp")
869869
foos = get_cursors(tu, "foo")
870870

871871
self.assertEqual(foos[1].get_num_template_arguments(), 3)
872872

873873
def test_get_template_argument_kind(self):
874-
tu = get_tu(kTemplateArgTest, lang="cpp")
874+
tu = get_tu(template_arg_test, lang="cpp")
875875
foos = get_cursors(tu, "foo")
876876

877877
self.assertEqual(
@@ -885,20 +885,20 @@ def test_get_template_argument_kind(self):
885885
)
886886

887887
def test_get_template_argument_type(self):
888-
tu = get_tu(kTemplateArgTest, lang="cpp")
888+
tu = get_tu(template_arg_test, lang="cpp")
889889
foos = get_cursors(tu, "foo")
890890

891891
self.assertEqual(foos[1].get_template_argument_type(1).kind, TypeKind.FLOAT)
892892

893893
def test_get_template_argument_value(self):
894-
tu = get_tu(kTemplateArgTest, lang="cpp")
894+
tu = get_tu(template_arg_test, lang="cpp")
895895
foos = get_cursors(tu, "foo")
896896

897897
self.assertEqual(foos[1].get_template_argument_value(0), -7)
898898
self.assertEqual(foos[1].get_template_argument_value(2), True)
899899

900900
def test_get_template_argument_unsigned_value(self):
901-
tu = get_tu(kTemplateArgTest, lang="cpp")
901+
tu = get_tu(template_arg_test, lang="cpp")
902902
foos = get_cursors(tu, "foo")
903903

904904
self.assertEqual(foos[1].get_template_argument_unsigned_value(0), 2**32 - 7)
@@ -930,7 +930,7 @@ def test_mangled_name(self):
930930
)
931931

932932
def test_binop(self):
933-
tu = get_tu(kBinops, lang="cpp")
933+
tu = get_tu(binops, lang="cpp")
934934

935935
operators = {
936936
# not exposed yet

clang/bindings/python/tests/cindex/test_index.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import unittest
99

10-
kInputsDir = os.path.join(os.path.dirname(__file__), "INPUTS")
10+
inputs_dir = os.path.join(os.path.dirname(__file__), "INPUTS")
1111

1212

1313
class TestIndex(unittest.TestCase):
@@ -19,7 +19,7 @@ def test_create(self):
1919
def test_parse(self):
2020
index = Index.create()
2121
self.assertIsInstance(index, Index)
22-
tu = index.parse(os.path.join(kInputsDir, "hello.cpp"))
22+
tu = index.parse(os.path.join(inputs_dir, "hello.cpp"))
2323
self.assertIsInstance(tu, TranslationUnit)
24-
tu = index.parse(None, ["-c", os.path.join(kInputsDir, "hello.cpp")])
24+
tu = index.parse(None, ["-c", os.path.join(inputs_dir, "hello.cpp")])
2525
self.assertIsInstance(tu, TranslationUnit)

clang/bindings/python/tests/cindex/test_location.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from .util import get_cursor, get_tu
1818

19-
baseInput = "int one;\nint two;\n"
19+
base_input = "int one;\nint two;\n"
2020

2121

2222
class TestLocation(unittest.TestCase):
@@ -26,7 +26,7 @@ def assert_location(self, loc, line, column, offset):
2626
self.assertEqual(loc.offset, offset)
2727

2828
def test_location(self):
29-
tu = get_tu(baseInput)
29+
tu = get_tu(base_input)
3030
one = get_cursor(tu, "one")
3131
two = get_cursor(tu, "two")
3232

@@ -37,7 +37,7 @@ def test_location(self):
3737
self.assert_location(two.location, line=2, column=5, offset=13)
3838

3939
# adding a linebreak at top should keep columns same
40-
tu = get_tu("\n" + baseInput)
40+
tu = get_tu("\n" + base_input)
4141
one = get_cursor(tu, "one")
4242
two = get_cursor(tu, "two")
4343

@@ -48,7 +48,7 @@ def test_location(self):
4848
self.assert_location(two.location, line=3, column=5, offset=14)
4949

5050
# adding a space should affect column on first line only
51-
tu = get_tu(" " + baseInput)
51+
tu = get_tu(" " + base_input)
5252
one = get_cursor(tu, "one")
5353
two = get_cursor(tu, "two")
5454

@@ -57,7 +57,7 @@ def test_location(self):
5757

5858
# define the expected location ourselves and see if it matches
5959
# the returned location
60-
tu = get_tu(baseInput)
60+
tu = get_tu(base_input)
6161

6262
file = File.from_name(tu, "t.c")
6363
location = SourceLocation.from_position(tu, file, 1, 5)
@@ -83,20 +83,20 @@ def test_location(self):
8383
self.assertTrue(verified)
8484

8585
def test_extent(self):
86-
tu = get_tu(baseInput)
86+
tu = get_tu(base_input)
8787
one = get_cursor(tu, "one")
8888
two = get_cursor(tu, "two")
8989

9090
self.assert_location(one.extent.start, line=1, column=1, offset=0)
9191
self.assert_location(one.extent.end, line=1, column=8, offset=7)
9292
self.assertEqual(
93-
baseInput[one.extent.start.offset : one.extent.end.offset], "int one"
93+
base_input[one.extent.start.offset : one.extent.end.offset], "int one"
9494
)
9595

9696
self.assert_location(two.extent.start, line=2, column=1, offset=9)
9797
self.assert_location(two.extent.end, line=2, column=8, offset=16)
9898
self.assertEqual(
99-
baseInput[two.extent.start.offset : two.extent.end.offset], "int two"
99+
base_input[two.extent.start.offset : two.extent.end.offset], "int two"
100100
)
101101

102102
file = File.from_name(tu, "t.c")

0 commit comments

Comments
 (0)