mirror of
https://github.com/github/codeql.git
synced 2025-12-21 11:16:30 +01:00
Python: Adds modernized predicate and moves queries over to it
This commit is contained in:
@@ -16,6 +16,6 @@ import Raising
|
||||
import Exceptions.NotImplemented
|
||||
|
||||
from Raise r, ClassObject t
|
||||
where type_or_typeof(r, t, _) and not t.isLegalExceptionType() and not t.failedInference() and not use_of_not_implemented_in_raise_objectapi(r, _)
|
||||
where type_or_typeof(r, t, _) and not t.isLegalExceptionType() and not t.failedInference() and not use_of_not_implemented_in_raise(r, _)
|
||||
select r, "Illegal class '" + t.getName() + "' raised; will result in a TypeError being raised instead."
|
||||
|
||||
|
||||
@@ -9,3 +9,12 @@ predicate use_of_not_implemented_in_raise_objectapi(Raise raise, Expr notimpl) {
|
||||
notimpl = raise.getException().(Call).getFunc()
|
||||
)
|
||||
}
|
||||
|
||||
/** Holds if `notimpl` refers to `NotImplemented` or `NotImplemented()` in the `raise` statement */
|
||||
predicate use_of_not_implemented_in_raise(Raise raise, Expr notimpl) {
|
||||
notimpl.pointsTo(Value::named("NotImplemented")) and
|
||||
(
|
||||
notimpl = raise.getException() or
|
||||
notimpl = raise.getException().(Call).getFunc()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -14,6 +14,6 @@ import python
|
||||
import Exceptions.NotImplemented
|
||||
|
||||
from Expr notimpl
|
||||
where use_of_not_implemented_in_raise_objectapi(_, notimpl)
|
||||
where use_of_not_implemented_in_raise(_, notimpl)
|
||||
|
||||
select notimpl, "NotImplemented is not an Exception. Did you mean NotImplementedError?"
|
||||
|
||||
@@ -19,6 +19,6 @@ where f = c.getFunc() and f.pointsTo(v, origin) and t = v.getClass() and
|
||||
not t.isCallable() and not t.failedInference(_)
|
||||
and not t.hasAttribute("__get__")
|
||||
and not v = Value::named("None")
|
||||
and not use_of_not_implemented_in_raise_objectapi(_, f)
|
||||
and not use_of_not_implemented_in_raise(_, f)
|
||||
|
||||
select c, "Call to a $@ of $@.", origin, "non-callable", t, t.toString()
|
||||
|
||||
Reference in New Issue
Block a user