mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Python examples: Modernize snippets.
This commit is contained in:
@@ -9,6 +9,6 @@
|
||||
|
||||
import python
|
||||
|
||||
from Expr e
|
||||
where e.refersTo(builtin_object(_))
|
||||
from Expr e, string name
|
||||
where e.pointsTo(Value::named(name)) and not name.charAt(_) = "."
|
||||
select e
|
||||
|
||||
@@ -8,6 +8,6 @@
|
||||
|
||||
import python
|
||||
|
||||
from FunctionObject len, CallNode call
|
||||
from Value len, CallNode call
|
||||
where len.getName() = "len" and len.getACall() = call
|
||||
select call
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
import python
|
||||
|
||||
from ExceptStmt ex, ClassObject cls
|
||||
from ExceptStmt ex, ClassValue cls
|
||||
where
|
||||
cls.getName() = "MyExceptionClass" and
|
||||
ex.getType().refersTo(cls)
|
||||
ex.getType().pointsTo(cls)
|
||||
select ex
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import python
|
||||
|
||||
from AstNode call, FunctionObject method
|
||||
from AstNode call, PythonFunctionValue method
|
||||
where
|
||||
method.getQualifiedName() = "MyClass.methodName" and
|
||||
method.getACall().getNode() = call
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
import python
|
||||
|
||||
from Call new, ClassObject cls
|
||||
from Call new, ClassValue cls
|
||||
where
|
||||
cls.getName() = "MyClass" and
|
||||
new.getFunc().refersTo(cls)
|
||||
new.getFunc().pointsTo(cls)
|
||||
select new
|
||||
|
||||
@@ -13,5 +13,5 @@ where
|
||||
print instanceof Print
|
||||
or
|
||||
/* Python 3 or with `from __future__ import print_function` */
|
||||
print.(Call).getFunc().refersTo(thePrintFunction())
|
||||
print.(Call).getFunc().pointsTo(Value::named("print"))
|
||||
select print
|
||||
|
||||
@@ -9,12 +9,10 @@
|
||||
|
||||
import python
|
||||
|
||||
from Raise raise, ClassObject ex
|
||||
from Raise raise, ClassValue ex
|
||||
where
|
||||
ex.getName() = "AnException" and
|
||||
(
|
||||
raise.getException().refersTo(ex.getAnImproperSuperType())
|
||||
or
|
||||
raise.getException().refersTo(_, ex.getAnImproperSuperType(), _)
|
||||
raise.getException().pointsTo(ex.getASuperType())
|
||||
)
|
||||
select raise, "Don't raise instances of 'AnException'"
|
||||
|
||||
@@ -8,6 +8,6 @@
|
||||
|
||||
import python
|
||||
|
||||
from FunctionObject f
|
||||
where f.getACallee() = f
|
||||
from PythonFunctionValue f
|
||||
where f.getACall().getScope() = f.getScope()
|
||||
select f
|
||||
|
||||
@@ -14,5 +14,5 @@ import python
|
||||
from SubscriptNode store
|
||||
where
|
||||
store.isStore() and
|
||||
store.getIndex().refersTo(theNoneObject())
|
||||
store.getIndex().pointsTo(Value::named("None"))
|
||||
select store
|
||||
|
||||
Reference in New Issue
Block a user