Skip to content

Commit a529a03

Browse files
yoffCopilot
andcommitted
Add captured call target diagnostic
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 972e03e commit a529a03

3 files changed

Lines changed: 61 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| test.py:14:13:14:38 | Attribute() | test.py:3:5:3:25 | Function compile | CallTypeStaticMethod |
2+
| test.py:14:13:14:38 | Attribute() | test.py:9:5:9:25 | Function compile | CallTypeStaticMethod |
3+
| test.py:23:16:23:21 | func() | test.py:29:1:29:12 | Function first | CallTypePlainFunction |
4+
| test.py:23:16:23:21 | func() | test.py:34:1:34:13 | Function second | CallTypePlainFunction |
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import python
2+
private import semmle.python.controlflow.internal.Cfg as Cfg
3+
private import semmle.python.dataflow.new.internal.DataFlowDispatch as Dispatch
4+
5+
from Call call, Function target, Dispatch::CallType callType
6+
where
7+
exists(Cfg::CallNode cfgCall |
8+
cfgCall.getNode() = call and
9+
Dispatch::resolveCall(cfgCall, target, callType)
10+
) and
11+
call.getLocation().getFile().getRelativePath() = "test.py" and
12+
target.getLocation().getFile().getRelativePath() = "test.py" and
13+
(
14+
call.getFunc().(Name).getId() = "func"
15+
or
16+
call.getFunc().(Attribute).getName() = "compile"
17+
)
18+
select call, target, callType.toString()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
class RegexRule:
2+
@staticmethod
3+
def compile(pattern):
4+
return pattern
5+
6+
7+
class GlobRule:
8+
@staticmethod
9+
def compile(pattern):
10+
return pattern
11+
12+
13+
def compile_rules(rule_type, patterns):
14+
return [rule_type.compile(pattern) for pattern in patterns]
15+
16+
17+
compile_rules(RegexRule, ["x"])
18+
compile_rules(GlobRule, ["*"])
19+
20+
21+
def decorate(func):
22+
def wrapper():
23+
return func()
24+
25+
return wrapper
26+
27+
28+
@decorate
29+
def first():
30+
return 1
31+
32+
33+
@decorate
34+
def second():
35+
return 2
36+
37+
38+
first()
39+
second()

0 commit comments

Comments
 (0)