Skip to content

Commit 94a0e02

Browse files
committed
Python: Port getCyclomaticComplexity function
1 parent 676c740 commit 94a0e02

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowDispatch.qll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2369,6 +2369,19 @@ module Reachability {
23692369
)
23702370
}
23712371

2372+
/**
2373+
* Holds if `node` is unlikely to raise an exception. This includes entry nodes
2374+
* and simple name lookups.
2375+
*/
2376+
private predicate unlikelyToRaise(ControlFlowNode node) {
2377+
exists(node.getAnExceptionalSuccessor()) and
2378+
(
2379+
node.getNode() instanceof Name
2380+
or
2381+
exists(Scope s | s.getEntryNode() = node)
2382+
)
2383+
}
2384+
23722385
/**
23732386
* Holds if it is highly unlikely for control to flow from `node` to `succ`.
23742387
*/
@@ -2381,6 +2394,10 @@ module Reachability {
23812394
succ = node.getASuccessor() and
23822395
not succ = node.getAnExceptionalSuccessor() and
23832396
not succ.getNode() instanceof Yield
2397+
or
2398+
// Exception edge from a node that is unlikely to raise
2399+
unlikelyToRaise(node) and
2400+
succ = node.getAnExceptionalSuccessor()
23842401
}
23852402

23862403
private predicate startBbLikelyReachable(BasicBlock b) {

0 commit comments

Comments
 (0)