Skip to content

Commit 24a29f4

Browse files
committed
Python: Fix all metrics-related compilation failures
In hindsight, having a `.getMetrics()` method that just returns `this` is somewhat weird. It's possible that it predates the existence of the inline cast, however.
1 parent c75329d commit 24a29f4

34 files changed

+82
-51
lines changed

python/ql/src/Functions/OverlyComplexDelMethod.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ from FunctionValue method
1818
where
1919
exists(ClassValue c |
2020
c.declaredAttribute("__del__") = method and
21-
method.getScope().getMetrics().getCyclomaticComplexity() > 3
21+
method.getScope().(FunctionMetrics).getCyclomaticComplexity() > 3
2222
)
2323
select method, "Overly complex '__del__' method."

python/ql/src/Metrics/CLinesOfCode.ql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
import python
13+
private import LegacyPointsTo
1314

14-
from Function f
15-
select f, f.getMetrics().getNumberOfLinesOfCode() as n order by n desc
15+
from FunctionMetrics f
16+
select f, f.getNumberOfLinesOfCode() as n order by n desc

python/ql/src/Metrics/ClassAfferentCoupling.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212

1313
import python
14+
private import LegacyPointsTo
1415

1516
from ClassMetrics cls
1617
select cls, cls.getAfferentCoupling() as n order by n desc

python/ql/src/Metrics/ClassEfferentCoupling.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212

1313
import python
14+
private import LegacyPointsTo
1415

1516
from ClassMetrics cls
1617
select cls, cls.getEfferentCoupling() as n order by n desc

python/ql/src/Metrics/CommentRatio.ql

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
*/
1313

1414
import python
15+
private import LegacyPointsTo
1516

16-
from Module m, ModuleMetrics mm
17-
where mm = m.getMetrics() and mm.getNumberOfLines() > 0
18-
select m, 100.0 * (mm.getNumberOfLinesOfComments().(float) / mm.getNumberOfLines().(float)) as ratio
17+
from ModuleMetrics mm
18+
where mm.getNumberOfLines() > 0
19+
select mm,
20+
100.0 * (mm.getNumberOfLinesOfComments().(float) / mm.getNumberOfLines().(float)) as ratio
1921
order by ratio desc

python/ql/src/Metrics/CyclomaticComplexity.ql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
*/
1414

1515
import python
16+
private import LegacyPointsTo
1617

17-
from Function func, int complexity
18-
where complexity = func.getMetrics().getCyclomaticComplexity()
18+
from FunctionMetrics func, int complexity
19+
where complexity = func.getCyclomaticComplexity()
1920
select func, complexity order by complexity desc

python/ql/src/Metrics/DocStringRatio.ql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
*/
1212

1313
import python
14+
private import LegacyPointsTo
1415

15-
from Module m, ModuleMetrics mm
16-
where mm = m.getMetrics() and mm.getNumberOfLines() > 0
17-
select m,
16+
from ModuleMetrics mm
17+
where mm.getNumberOfLines() > 0
18+
select mm,
1819
100.0 * (mm.getNumberOfLinesOfDocStrings().(float) / mm.getNumberOfLines().(float)) as ratio
1920
order by ratio desc

python/ql/src/Metrics/FLines.ql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
*/
1010

1111
import python
12+
private import LegacyPointsTo
1213

13-
from Module m, int n
14-
where n = m.getMetrics().getNumberOfLines()
14+
from ModuleMetrics m, int n
15+
where n = m.getNumberOfLines()
1516
select m, n order by n desc

python/ql/src/Metrics/FLinesOfCode.ql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
*/
1212

1313
import python
14+
private import LegacyPointsTo
1415

15-
from Module m, int n
16-
where n = m.getMetrics().getNumberOfLinesOfCode()
16+
from ModuleMetrics m, int n
17+
where n = m.getNumberOfLinesOfCode()
1718
select m, n order by n desc

python/ql/src/Metrics/FLinesOfComments.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
*/
1111

1212
import python
13+
private import LegacyPointsTo
1314

14-
from Module m, int n
15-
where
16-
n = m.getMetrics().getNumberOfLinesOfComments() + m.getMetrics().getNumberOfLinesOfDocStrings()
15+
from ModuleMetrics m, int n
16+
where n = m.getNumberOfLinesOfComments() + m.getNumberOfLinesOfDocStrings()
1717
select m, n order by n desc

0 commit comments

Comments
 (0)