Skip to content

Commit 811a7d0

Browse files
authored
Merge pull request github#14248 from RasmusWL/debug-queries
Python: Add debug queries
2 parents c45ca72 + fd8d186 commit 811a7d0

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import python
2+
3+
from string msg, int cnt, int sort
4+
where
5+
sort = 0 and
6+
msg = "Lines of code in DB" and
7+
cnt = sum(Module m | | m.getMetrics().getNumberOfLinesOfCode())
8+
or
9+
sort = 1 and
10+
msg = "Lines of code in repo" and
11+
cnt =
12+
sum(Module m | exists(m.getFile().getRelativePath()) | m.getMetrics().getNumberOfLinesOfCode())
13+
or
14+
sort = 2 and
15+
msg = "Files" and
16+
cnt = count(File f)
17+
or
18+
sort = 10 and msg = "----------" and cnt = 0
19+
or
20+
sort = 11 and
21+
msg = "Modules" and
22+
cnt = count(Module m)
23+
or
24+
sort = 12 and
25+
msg = "Classes" and
26+
cnt = count(Class c)
27+
or
28+
sort = 13 and
29+
msg = "Functions" and
30+
cnt = count(Function f)
31+
or
32+
sort = 14 and
33+
msg = "async functions" and
34+
cnt = count(Function f | f.isAsync())
35+
or
36+
sort = 15 and
37+
msg = "*args params" and
38+
cnt = count(Function f | f.hasVarArg())
39+
or
40+
sort = 16 and
41+
msg = "**kwargs params" and
42+
cnt = count(Function f | f.hasKwArg())
43+
or
44+
sort = 20 and msg = "----------" and cnt = 0
45+
or
46+
sort = 21 and
47+
msg = "call" and
48+
cnt = count(Call c)
49+
or
50+
sort = 22 and
51+
msg = "for loop" and
52+
cnt = count(For f)
53+
or
54+
sort = 23 and
55+
msg = "comprehension" and
56+
cnt = count(Comp c)
57+
or
58+
sort = 24 and
59+
msg = "attribute" and
60+
cnt = count(Attribute a)
61+
or
62+
sort = 25 and
63+
msg = "assignment" and
64+
cnt = count(Assign a)
65+
or
66+
sort = 26 and
67+
msg = "await" and
68+
cnt = count(Await a)
69+
or
70+
sort = 27 and
71+
msg = "yield" and
72+
cnt = count(Yield y)
73+
or
74+
sort = 28 and
75+
msg = "with" and
76+
cnt = count(With w)
77+
or
78+
sort = 29 and
79+
msg = "raise" and
80+
cnt = count(Raise r)
81+
or
82+
sort = 30 and
83+
msg = "return" and
84+
cnt = count(Return r)
85+
or
86+
sort = 31 and
87+
msg = "match" and
88+
cnt = count(MatchStmt m)
89+
or
90+
sort = 32 and
91+
msg = "from ... import ..." and
92+
cnt = count(Import i | i.isFromImport())
93+
or
94+
sort = 33 and
95+
msg = "import ..." and
96+
cnt = count(Import i | not i.isFromImport())
97+
or
98+
sort = 34 and
99+
msg = "import *" and
100+
cnt = count(ImportStar i)
101+
select sort, msg, cnt order by sort
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Fill in your class name and file path below, to inspect the class hierarchy.
3+
*/
4+
5+
import python
6+
import semmle.python.dataflow.new.internal.DataFlowPublic
7+
import semmle.python.dataflow.new.internal.DataFlowPrivate
8+
9+
predicate interestingClass(Class cls) {
10+
cls.getName() = "YourClassName"
11+
// and cls.getLocation().getFile().getAbsolutePath().matches("%/folder/file.py")
12+
}
13+
14+
query predicate superClasses(Class cls, Class super_) {
15+
interestingClass(cls) and
16+
super_ = getADirectSuperclass+(cls)
17+
}
18+
19+
query predicate subClasses(Class cls, Class super_) {
20+
interestingClass(cls) and
21+
super_ = getADirectSubclass+(cls)
22+
}
23+
24+
from Class cls
25+
where interestingClass(cls)
26+
select cls

0 commit comments

Comments
 (0)