Skip to content

Commit e481ddf

Browse files
committed
Python: Adds modernized predicate and moves queries over to it
1 parent c058e17 commit e481ddf

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

python/ql/src/Exceptions/IllegalRaise.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ import Raising
1616
import Exceptions.NotImplemented
1717

1818
from Raise r, ClassObject t
19-
where type_or_typeof(r, t, _) and not t.isLegalExceptionType() and not t.failedInference() and not use_of_not_implemented_in_raise_objectapi(r, _)
19+
where type_or_typeof(r, t, _) and not t.isLegalExceptionType() and not t.failedInference() and not use_of_not_implemented_in_raise(r, _)
2020
select r, "Illegal class '" + t.getName() + "' raised; will result in a TypeError being raised instead."
2121

python/ql/src/Exceptions/NotImplemented.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,12 @@ predicate use_of_not_implemented_in_raise_objectapi(Raise raise, Expr notimpl) {
99
notimpl = raise.getException().(Call).getFunc()
1010
)
1111
}
12+
13+
/** Holds if `notimpl` refers to `NotImplemented` or `NotImplemented()` in the `raise` statement */
14+
predicate use_of_not_implemented_in_raise(Raise raise, Expr notimpl) {
15+
notimpl.pointsTo(Value::named("NotImplemented")) and
16+
(
17+
notimpl = raise.getException() or
18+
notimpl = raise.getException().(Call).getFunc()
19+
)
20+
}

python/ql/src/Exceptions/NotImplementedIsNotAnException.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ import python
1414
import Exceptions.NotImplemented
1515

1616
from Expr notimpl
17-
where use_of_not_implemented_in_raise_objectapi(_, notimpl)
17+
where use_of_not_implemented_in_raise(_, notimpl)
1818

1919
select notimpl, "NotImplemented is not an Exception. Did you mean NotImplementedError?"

python/ql/src/Expressions/NonCallableCalled.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ where f = c.getFunc() and f.pointsTo(v, origin) and t = v.getClass() and
1919
not t.isCallable() and not t.failedInference(_)
2020
and not t.hasAttribute("__get__")
2121
and not v = Value::named("None")
22-
and not use_of_not_implemented_in_raise_objectapi(_, f)
22+
and not use_of_not_implemented_in_raise(_, f)
2323

2424
select c, "Call to a $@ of $@.", origin, "non-callable", t, t.toString()

0 commit comments

Comments
 (0)