Skip to content

Commit 9960bc6

Browse files
helper to find Protocol ClassDefs
1 parent ed43b7e commit 9960bc6

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

python/ql/src/Statements/StatementNoEffect.ql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import python
1616
private import LegacyPointsTo
17+
import semmle.python.ApiGraphs
1718

1819
predicate understood_attribute(Attribute attr, ClassValue cls, ClassValue attr_cls) {
1920
exists(string name | attr.getName() = name |
@@ -94,6 +95,20 @@ private string special_method() {
9495
result = any(BinaryExpr b).getOp().getSpecialMethodName()
9596
}
9697

98+
ClassDef getAProtocolDef() {
99+
exists(Expr e |
100+
e =
101+
API::moduleImport("typing")
102+
.getMember("Protocol")
103+
.getASubclass*()
104+
.getAValueReachableFromSource()
105+
.asExpr()
106+
|
107+
e instanceof ClassExpr and
108+
e = result.getValue()
109+
)
110+
}
111+
97112
predicate is_notebook(File f) {
98113
exists(Comment c | c.getLocation().getFile() = f |
99114
c.getText().regexpMatch("#\\s*<nbformat>.+</nbformat>\\s*")

0 commit comments

Comments
 (0)