Python: Add 3-only library tests.

This commit is contained in:
Mark Shannon
2019-02-08 14:39:27 +00:00
parent 0558b58193
commit 49307a72b4
138 changed files with 3118 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
| 8 | ControlFlowNode for ExceptStmt | builtin-class AttributeError |
| 10 | ControlFlowNode for ExceptStmt | builtin-class IndexError |
| 12 | ControlFlowNode for ExceptStmt | builtin-class KeyError |
| 14 | ControlFlowNode for ExceptStmt | builtin-class BaseException |
| 23 | ControlFlowNode for ExceptStmt | builtin-class AttributeError |
| 25 | ControlFlowNode for ExceptStmt | builtin-class IndexError |
| 27 | ControlFlowNode for ExceptStmt | builtin-class KeyError |
| 38 | ControlFlowNode for ExceptStmt | builtin-class AttributeError |
| 40 | ControlFlowNode for ExceptStmt | builtin-class IndexError |
| 42 | ControlFlowNode for ExceptStmt | builtin-class KeyError |
| 57 | ControlFlowNode for ExceptStmt | builtin-class OSError |

View File

@@ -0,0 +1,6 @@
import python
from ExceptFlowNode ex, Object obj
where ex.handledException(obj, _, _)
select ex.getLocation().getStartLine(), ex.toString(), obj.toString()

View File

@@ -0,0 +1,15 @@
| 4 | ControlFlowNode for Subscript | builtin-class IndexError |
| 4 | ControlFlowNode for Subscript | builtin-class KeyError |
| 5 | ControlFlowNode for Attribute | builtin-class AttributeError |
| 7 | ControlFlowNode for Raise | builtin-class Exception |
| 19 | ControlFlowNode for Subscript | builtin-class IndexError |
| 19 | ControlFlowNode for Subscript | builtin-class KeyError |
| 20 | ControlFlowNode for Attribute | builtin-class AttributeError |
| 22 | ControlFlowNode for Raise | builtin-class Exception |
| 30 | ControlFlowNode for Pass | builtin-class Exception |
| 34 | ControlFlowNode for Subscript | builtin-class IndexError |
| 34 | ControlFlowNode for Subscript | builtin-class KeyError |
| 35 | ControlFlowNode for Attribute | builtin-class AttributeError |
| 37 | ControlFlowNode for Raise | builtin-class Exception |
| 53 | ControlFlowNode for Attribute() | builtin-class OSError |
| 54 | ControlFlowNode for Attribute() | builtin-class OSError |

View File

@@ -0,0 +1,5 @@
import python
from RaisingNode r
select r.getLocation().getStartLine(), r.toString(), r.getARaisedType().toString()

View File

@@ -0,0 +1,25 @@
| 4 | ControlFlowNode for Subscript | 10 | ControlFlowNode for ExceptStmt |
| 4 | ControlFlowNode for Subscript | 12 | ControlFlowNode for ExceptStmt |
| 5 | ControlFlowNode for Attribute | 8 | ControlFlowNode for ExceptStmt |
| 6 | ControlFlowNode for a() | 8 | ControlFlowNode for ExceptStmt |
| 6 | ControlFlowNode for a() | 10 | ControlFlowNode for ExceptStmt |
| 6 | ControlFlowNode for a() | 12 | ControlFlowNode for ExceptStmt |
| 6 | ControlFlowNode for a() | 14 | ControlFlowNode for ExceptStmt |
| 7 | ControlFlowNode for Raise | 14 | ControlFlowNode for ExceptStmt |
| 19 | ControlFlowNode for Subscript | 25 | ControlFlowNode for ExceptStmt |
| 19 | ControlFlowNode for Subscript | 27 | ControlFlowNode for ExceptStmt |
| 20 | ControlFlowNode for Attribute | 23 | ControlFlowNode for ExceptStmt |
| 21 | ControlFlowNode for a() | 23 | ControlFlowNode for ExceptStmt |
| 21 | ControlFlowNode for a() | 25 | ControlFlowNode for ExceptStmt |
| 21 | ControlFlowNode for a() | 27 | ControlFlowNode for ExceptStmt |
| 21 | ControlFlowNode for a() | 30 | ControlFlowNode for Pass |
| 22 | ControlFlowNode for Raise | 30 | ControlFlowNode for Pass |
| 34 | ControlFlowNode for Subscript | 40 | ControlFlowNode for ExceptStmt |
| 34 | ControlFlowNode for Subscript | 42 | ControlFlowNode for ExceptStmt |
| 35 | ControlFlowNode for Attribute | 38 | ControlFlowNode for ExceptStmt |
| 36 | ControlFlowNode for a() | 38 | ControlFlowNode for ExceptStmt |
| 36 | ControlFlowNode for a() | 40 | ControlFlowNode for ExceptStmt |
| 36 | ControlFlowNode for a() | 42 | ControlFlowNode for ExceptStmt |
| 53 | ControlFlowNode for Attribute() | 57 | ControlFlowNode for ExceptStmt |
| 54 | ControlFlowNode for Attribute() | 57 | ControlFlowNode for ExceptStmt |
| 56 | ControlFlowNode for Attribute() | 57 | ControlFlowNode for ExceptStmt |

View File

@@ -0,0 +1,7 @@
import python
from ControlFlowNode r, ControlFlowNode s
where s = r.getAnExceptionalSuccessor() and
not r.(RaisingNode).unlikelySuccessor(s)
select r.getLocation().getStartLine(), r.toString(), s.getLocation().getStartLine(), s.toString()

View File

@@ -0,0 +1,6 @@
| 6 | ControlFlowNode for a() |
| 21 | ControlFlowNode for a() |
| 36 | ControlFlowNode for a() |
| 51 | ControlFlowNode for open() |
| 56 | ControlFlowNode for Attribute() |
| 58 | ControlFlowNode for Attribute() |

View File

@@ -0,0 +1,6 @@
import python
from RaisingNode r
where r.raisesUnknownType()
select r.getLocation().getStartLine(), r.toString()

View File

@@ -0,0 +1,59 @@
def f(a, x):
try:
a[x]
a.b
a(x)
raise Exception()
except AttributeError:
pass
except IndexError:
pass
except KeyError:
pass
except:
pass
def g(a, x):
try:
a[x]
a.b
a(x)
raise Exception()
except AttributeError:
pass
except IndexError:
pass
except KeyError:
pass
finally:
pass
def h(a, x):
try:
a[x]
a.b
a(x)
raise Exception()
except AttributeError:
pass
except IndexError:
pass
except KeyError:
pass
#I/O stuff.
def doesnt_raise():
pass
def io():
f12 = open("filename")
try:
f12.read("IOError could occur")
f12.write("IOError could occur")
doesnt_raise("Potential false positive here")
f12.close()
except IOError:
f12.close()

View File

@@ -0,0 +1,202 @@
| 2 | ControlFlowNode for C | class C | 2 |
| 2 | ControlFlowNode for ClassExpr | class C | 2 |
| 2 | ControlFlowNode for object | builtin-class object | 2 |
| 4 | ControlFlowNode for None | NoneType None | 4 |
| 4 | ControlFlowNode for z | NoneType None | 4 |
| 5 | ControlFlowNode for IntegerLiteral | int 1 | 5 |
| 5 | ControlFlowNode for i | int 1 | 5 |
| 7 | ControlFlowNode for FunctionExpr | Function __init__ | 7 |
| 7 | ControlFlowNode for __init__ | Function __init__ | 7 |
| 8 | ControlFlowNode for self | self | 7 |
| 9 | ControlFlowNode for self | self | 7 |
| 10 | ControlFlowNode for Attribute | int 1 | 10 |
| 10 | ControlFlowNode for IntegerLiteral | int 1 | 10 |
| 10 | ControlFlowNode for self | self | 7 |
| 13 | ControlFlowNode for FunctionExpr | Function f | 13 |
| 13 | ControlFlowNode for f | Function f | 13 |
| 15 | ControlFlowNode for C | class C | 2 |
| 15 | ControlFlowNode for C() | C() | 15 |
| 15 | ControlFlowNode for c | C() | 15 |
| 16 | ControlFlowNode for c | C() | 15 |
| 17 | ControlFlowNode for Attribute | int 2 | 17 |
| 17 | ControlFlowNode for IntegerLiteral | int 2 | 17 |
| 17 | ControlFlowNode for c | C() | 15 |
| 19 | ControlFlowNode for c | C() | 15 |
| 20 | ControlFlowNode for c | C() | 15 |
| 21 | ControlFlowNode for Attribute | int 1 | 10 |
| 21 | ControlFlowNode for c | C() | 15 |
| 22 | ControlFlowNode for c | C() | 15 |
| 23 | ControlFlowNode for Attribute | int 2 | 17 |
| 23 | ControlFlowNode for c | C() | 15 |
| 26 | ControlFlowNode for FunctionExpr | Function g | 26 |
| 26 | ControlFlowNode for g | Function g | 26 |
| 28 | ControlFlowNode for None | NoneType None | 28 |
| 28 | ControlFlowNode for d1 | NoneType None | 28 |
| 30 | ControlFlowNode for List | List | 30 |
| 30 | ControlFlowNode for d1 | List | 30 |
| 31 | ControlFlowNode for FloatLiteral | float 0.7 | 31 |
| 31 | ControlFlowNode for Subscript | float 0.7 | 31 |
| 31 | ControlFlowNode for d1 | List | 30 |
| 31 | ControlFlowNode for d1 | NoneType None | 28 |
| 32 | ControlFlowNode for d1 | List | 30 |
| 32 | ControlFlowNode for d1 | NoneType None | 28 |
| 35 | ControlFlowNode for FunctionExpr | Function h | 35 |
| 35 | ControlFlowNode for h | Function h | 35 |
| 37 | ControlFlowNode for None | NoneType None | 37 |
| 37 | ControlFlowNode for d2 | NoneType None | 37 |
| 39 | ControlFlowNode for List | List | 39 |
| 39 | ControlFlowNode for d2 | List | 39 |
| 40 | ControlFlowNode for IntegerLiteral | int 3 | 40 |
| 40 | ControlFlowNode for Subscript | int 3 | 40 |
| 40 | ControlFlowNode for d2 | List | 39 |
| 40 | ControlFlowNode for d2 | NoneType None | 37 |
| 41 | ControlFlowNode for d2 | List | 39 |
| 41 | ControlFlowNode for d2 | NoneType None | 37 |
| 44 | ControlFlowNode for FunctionExpr | Function j | 44 |
| 44 | ControlFlowNode for j | Function j | 44 |
| 45 | ControlFlowNode for Attribute | Function __init__ | 7 |
| 45 | ControlFlowNode for C | class C | 2 |
| 46 | ControlFlowNode for Attribute | int 1 | 5 |
| 46 | ControlFlowNode for C | class C | 2 |
| 47 | ControlFlowNode for Attribute | NoneType None | 4 |
| 47 | ControlFlowNode for C | class C | 2 |
| 50 | ControlFlowNode for FunctionExpr | Function k | 50 |
| 50 | ControlFlowNode for k | Function k | 50 |
| 51 | ControlFlowNode for C | class C | 2 |
| 51 | ControlFlowNode for C() | C() | 51 |
| 51 | ControlFlowNode for c1 | C() | 51 |
| 52 | ControlFlowNode for C | class C | 2 |
| 52 | ControlFlowNode for C() | C() | 52 |
| 52 | ControlFlowNode for c2 | C() | 52 |
| 53 | ControlFlowNode for C | class C | 2 |
| 53 | ControlFlowNode for C() | C() | 53 |
| 53 | ControlFlowNode for c3 | C() | 53 |
| 54 | ControlFlowNode for Attribute | int 10 | 54 |
| 54 | ControlFlowNode for IntegerLiteral | int 10 | 54 |
| 54 | ControlFlowNode for c1 | C() | 51 |
| 56 | ControlFlowNode for Attribute | int 20 | 56 |
| 56 | ControlFlowNode for IntegerLiteral | int 20 | 56 |
| 56 | ControlFlowNode for c2 | C() | 52 |
| 57 | ControlFlowNode for Attribute | int 10 | 54 |
| 57 | ControlFlowNode for c1 | C() | 51 |
| 58 | ControlFlowNode for Attribute | int 1 | 10 |
| 58 | ControlFlowNode for Attribute | int 20 | 56 |
| 58 | ControlFlowNode for c2 | C() | 52 |
| 59 | ControlFlowNode for Attribute | int 1 | 10 |
| 59 | ControlFlowNode for c3 | C() | 53 |
| 60 | ControlFlowNode for Attribute | int 30 | 60 |
| 60 | ControlFlowNode for IntegerLiteral | int 30 | 60 |
| 60 | ControlFlowNode for c3 | C() | 53 |
| 62 | ControlFlowNode for ClassExpr | class D | 62 |
| 62 | ControlFlowNode for D | class D | 62 |
| 62 | ControlFlowNode for object | builtin-class object | 62 |
| 64 | ControlFlowNode for FunctionExpr | Function meth1 | 64 |
| 64 | ControlFlowNode for meth1 | Function meth1 | 64 |
| 65 | ControlFlowNode for Attribute | int 0 | 65 |
| 65 | ControlFlowNode for IntegerLiteral | int 0 | 65 |
| 65 | ControlFlowNode for self | self | 64 |
| 65 | ControlFlowNode for self | self | 70 |
| 66 | ControlFlowNode for Attribute | int 1 | 66 |
| 66 | ControlFlowNode for IntegerLiteral | int 1 | 66 |
| 66 | ControlFlowNode for self | self | 64 |
| 66 | ControlFlowNode for self | self | 70 |
| 67 | ControlFlowNode for Attribute | int 0 | 65 |
| 67 | ControlFlowNode for self | self | 64 |
| 67 | ControlFlowNode for self | self | 70 |
| 68 | ControlFlowNode for Attribute | int 1 | 66 |
| 68 | ControlFlowNode for self | self | 64 |
| 68 | ControlFlowNode for self | self | 70 |
| 70 | ControlFlowNode for FunctionExpr | Function meth2 | 70 |
| 70 | ControlFlowNode for meth2 | Function meth2 | 70 |
| 71 | ControlFlowNode for Attribute | float 7.0 | 71 |
| 71 | ControlFlowNode for FloatLiteral | float 7.0 | 71 |
| 71 | ControlFlowNode for self | self | 70 |
| 72 | ControlFlowNode for Attribute | int 2 | 72 |
| 72 | ControlFlowNode for IntegerLiteral | int 2 | 72 |
| 72 | ControlFlowNode for self | self | 70 |
| 73 | ControlFlowNode for Attribute() | NoneType None | 64 |
| 73 | ControlFlowNode for self | self | 70 |
| 74 | ControlFlowNode for Attribute | int 0 | 65 |
| 74 | ControlFlowNode for self | self | 70 |
| 75 | ControlFlowNode for Attribute | int 1 | 66 |
| 75 | ControlFlowNode for self | self | 70 |
| 76 | ControlFlowNode for Attribute | int 2 | 72 |
| 76 | ControlFlowNode for self | self | 70 |
| 78 | ControlFlowNode for ClassExpr | class E | 78 |
| 78 | ControlFlowNode for E | class E | 78 |
| 78 | ControlFlowNode for object | builtin-class object | 78 |
| 80 | ControlFlowNode for FunctionExpr | Function __init__ | 80 |
| 80 | ControlFlowNode for __init__ | Function __init__ | 80 |
| 82 | ControlFlowNode for Attribute | int 0 | 82 |
| 82 | ControlFlowNode for IntegerLiteral | int 0 | 82 |
| 82 | ControlFlowNode for self | self | 80 |
| 84 | ControlFlowNode for Attribute | int 1 | 84 |
| 84 | ControlFlowNode for IntegerLiteral | int 1 | 84 |
| 84 | ControlFlowNode for self | self | 80 |
| 86 | ControlFlowNode for E | class E | 78 |
| 86 | ControlFlowNode for E() | E() | 86 |
| 90 | ControlFlowNode for ClassExpr | class F | 90 |
| 90 | ControlFlowNode for F | class F | 90 |
| 90 | ControlFlowNode for object | builtin-class object | 90 |
| 92 | ControlFlowNode for FunctionExpr | Function meth1 | 92 |
| 92 | ControlFlowNode for meth1 | Function meth1 | 92 |
| 93 | ControlFlowNode for IntegerLiteral | int 0 | 93 |
| 93 | ControlFlowNode for Str | str u'a' | 93 |
| 93 | ControlFlowNode for self | self | 92 |
| 93 | ControlFlowNode for self | self | 98 |
| 93 | ControlFlowNode for setattr | Builtin-function setattr | 93 |
| 93 | ControlFlowNode for setattr() | NoneType None | 93 |
| 94 | ControlFlowNode for IntegerLiteral | int 1 | 94 |
| 94 | ControlFlowNode for Str | str u'b' | 94 |
| 94 | ControlFlowNode for self | self | 92 |
| 94 | ControlFlowNode for self | self | 98 |
| 94 | ControlFlowNode for setattr | Builtin-function setattr | 94 |
| 94 | ControlFlowNode for setattr() | NoneType None | 94 |
| 95 | ControlFlowNode for Str | str u'a' | 95 |
| 95 | ControlFlowNode for getattr | Builtin-function getattr | 95 |
| 95 | ControlFlowNode for getattr() | int 0 | 93 |
| 95 | ControlFlowNode for self | self | 92 |
| 95 | ControlFlowNode for self | self | 98 |
| 96 | ControlFlowNode for Str | str u'b' | 96 |
| 96 | ControlFlowNode for getattr | Builtin-function getattr | 96 |
| 96 | ControlFlowNode for getattr() | int 1 | 94 |
| 96 | ControlFlowNode for self | self | 92 |
| 96 | ControlFlowNode for self | self | 98 |
| 98 | ControlFlowNode for FunctionExpr | Function meth2 | 98 |
| 98 | ControlFlowNode for meth2 | Function meth2 | 98 |
| 99 | ControlFlowNode for FloatLiteral | float 7.0 | 99 |
| 99 | ControlFlowNode for Str | str u'a' | 99 |
| 99 | ControlFlowNode for self | self | 98 |
| 99 | ControlFlowNode for setattr | Builtin-function setattr | 99 |
| 99 | ControlFlowNode for setattr() | NoneType None | 99 |
| 100 | ControlFlowNode for IntegerLiteral | int 2 | 100 |
| 100 | ControlFlowNode for Str | str u'c' | 100 |
| 100 | ControlFlowNode for self | self | 98 |
| 100 | ControlFlowNode for setattr | Builtin-function setattr | 100 |
| 100 | ControlFlowNode for setattr() | NoneType None | 100 |
| 101 | ControlFlowNode for Attribute() | NoneType None | 92 |
| 101 | ControlFlowNode for self | self | 98 |
| 102 | ControlFlowNode for Str | str u'a' | 102 |
| 102 | ControlFlowNode for getattr | Builtin-function getattr | 102 |
| 102 | ControlFlowNode for getattr() | int 0 | 93 |
| 102 | ControlFlowNode for self | self | 98 |
| 103 | ControlFlowNode for Str | str u'b' | 103 |
| 103 | ControlFlowNode for getattr | Builtin-function getattr | 103 |
| 103 | ControlFlowNode for getattr() | int 1 | 94 |
| 103 | ControlFlowNode for self | self | 98 |
| 104 | ControlFlowNode for Str | str u'c' | 104 |
| 104 | ControlFlowNode for getattr | Builtin-function getattr | 104 |
| 104 | ControlFlowNode for getattr() | int 2 | 100 |
| 104 | ControlFlowNode for self | self | 98 |
| 106 | ControlFlowNode for ClassExpr | class G | 106 |
| 106 | ControlFlowNode for G | class G | 106 |
| 106 | ControlFlowNode for object | builtin-class object | 106 |
| 108 | ControlFlowNode for FunctionExpr | Function __init__ | 108 |
| 108 | ControlFlowNode for __init__ | Function __init__ | 108 |
| 109 | ControlFlowNode for IntegerLiteral | int 0 | 109 |
| 109 | ControlFlowNode for Str | str u'x' | 109 |
| 109 | ControlFlowNode for self | self | 108 |
| 109 | ControlFlowNode for setattr | Builtin-function setattr | 109 |
| 109 | ControlFlowNode for setattr() | NoneType None | 109 |
| 111 | ControlFlowNode for G | class G | 106 |
| 111 | ControlFlowNode for G() | G() | 111 |

View File

@@ -0,0 +1,7 @@
import python
from ControlFlowNode f, Object o, ControlFlowNode x
where f.refersTo(o, x)
select f.getLocation().getStartLine(), f.toString(), o.toString(), x.getLocation().getStartLine()

View File

@@ -0,0 +1,202 @@
| 2 | ControlFlowNode for C | class C | builtin-class type | 2 |
| 2 | ControlFlowNode for ClassExpr | class C | builtin-class type | 2 |
| 2 | ControlFlowNode for object | builtin-class object | builtin-class type | 2 |
| 4 | ControlFlowNode for None | NoneType None | builtin-class NoneType | 4 |
| 4 | ControlFlowNode for z | NoneType None | builtin-class NoneType | 4 |
| 5 | ControlFlowNode for IntegerLiteral | int 1 | builtin-class int | 5 |
| 5 | ControlFlowNode for i | int 1 | builtin-class int | 5 |
| 7 | ControlFlowNode for FunctionExpr | Function __init__ | builtin-class function | 7 |
| 7 | ControlFlowNode for __init__ | Function __init__ | builtin-class function | 7 |
| 8 | ControlFlowNode for self | self | class C | 7 |
| 9 | ControlFlowNode for self | self | class C | 7 |
| 10 | ControlFlowNode for Attribute | int 1 | builtin-class int | 10 |
| 10 | ControlFlowNode for IntegerLiteral | int 1 | builtin-class int | 10 |
| 10 | ControlFlowNode for self | self | class C | 7 |
| 13 | ControlFlowNode for FunctionExpr | Function f | builtin-class function | 13 |
| 13 | ControlFlowNode for f | Function f | builtin-class function | 13 |
| 15 | ControlFlowNode for C | class C | builtin-class type | 2 |
| 15 | ControlFlowNode for C() | C() | class C | 15 |
| 15 | ControlFlowNode for c | C() | class C | 15 |
| 16 | ControlFlowNode for c | C() | class C | 15 |
| 17 | ControlFlowNode for Attribute | int 2 | builtin-class int | 17 |
| 17 | ControlFlowNode for IntegerLiteral | int 2 | builtin-class int | 17 |
| 17 | ControlFlowNode for c | C() | class C | 15 |
| 19 | ControlFlowNode for c | C() | class C | 15 |
| 20 | ControlFlowNode for c | C() | class C | 15 |
| 21 | ControlFlowNode for Attribute | int 1 | builtin-class int | 10 |
| 21 | ControlFlowNode for c | C() | class C | 15 |
| 22 | ControlFlowNode for c | C() | class C | 15 |
| 23 | ControlFlowNode for Attribute | int 2 | builtin-class int | 17 |
| 23 | ControlFlowNode for c | C() | class C | 15 |
| 26 | ControlFlowNode for FunctionExpr | Function g | builtin-class function | 26 |
| 26 | ControlFlowNode for g | Function g | builtin-class function | 26 |
| 28 | ControlFlowNode for None | NoneType None | builtin-class NoneType | 28 |
| 28 | ControlFlowNode for d1 | NoneType None | builtin-class NoneType | 28 |
| 30 | ControlFlowNode for List | List | builtin-class list | 30 |
| 30 | ControlFlowNode for d1 | List | builtin-class list | 30 |
| 31 | ControlFlowNode for FloatLiteral | float 0.7 | builtin-class float | 31 |
| 31 | ControlFlowNode for Subscript | float 0.7 | builtin-class float | 31 |
| 31 | ControlFlowNode for d1 | List | builtin-class list | 30 |
| 31 | ControlFlowNode for d1 | NoneType None | builtin-class NoneType | 28 |
| 32 | ControlFlowNode for d1 | List | builtin-class list | 30 |
| 32 | ControlFlowNode for d1 | NoneType None | builtin-class NoneType | 28 |
| 35 | ControlFlowNode for FunctionExpr | Function h | builtin-class function | 35 |
| 35 | ControlFlowNode for h | Function h | builtin-class function | 35 |
| 37 | ControlFlowNode for None | NoneType None | builtin-class NoneType | 37 |
| 37 | ControlFlowNode for d2 | NoneType None | builtin-class NoneType | 37 |
| 39 | ControlFlowNode for List | List | builtin-class list | 39 |
| 39 | ControlFlowNode for d2 | List | builtin-class list | 39 |
| 40 | ControlFlowNode for IntegerLiteral | int 3 | builtin-class int | 40 |
| 40 | ControlFlowNode for Subscript | int 3 | builtin-class int | 40 |
| 40 | ControlFlowNode for d2 | List | builtin-class list | 39 |
| 40 | ControlFlowNode for d2 | NoneType None | builtin-class NoneType | 37 |
| 41 | ControlFlowNode for d2 | List | builtin-class list | 39 |
| 41 | ControlFlowNode for d2 | NoneType None | builtin-class NoneType | 37 |
| 44 | ControlFlowNode for FunctionExpr | Function j | builtin-class function | 44 |
| 44 | ControlFlowNode for j | Function j | builtin-class function | 44 |
| 45 | ControlFlowNode for Attribute | Function __init__ | builtin-class function | 7 |
| 45 | ControlFlowNode for C | class C | builtin-class type | 2 |
| 46 | ControlFlowNode for Attribute | int 1 | builtin-class int | 5 |
| 46 | ControlFlowNode for C | class C | builtin-class type | 2 |
| 47 | ControlFlowNode for Attribute | NoneType None | builtin-class NoneType | 4 |
| 47 | ControlFlowNode for C | class C | builtin-class type | 2 |
| 50 | ControlFlowNode for FunctionExpr | Function k | builtin-class function | 50 |
| 50 | ControlFlowNode for k | Function k | builtin-class function | 50 |
| 51 | ControlFlowNode for C | class C | builtin-class type | 2 |
| 51 | ControlFlowNode for C() | C() | class C | 51 |
| 51 | ControlFlowNode for c1 | C() | class C | 51 |
| 52 | ControlFlowNode for C | class C | builtin-class type | 2 |
| 52 | ControlFlowNode for C() | C() | class C | 52 |
| 52 | ControlFlowNode for c2 | C() | class C | 52 |
| 53 | ControlFlowNode for C | class C | builtin-class type | 2 |
| 53 | ControlFlowNode for C() | C() | class C | 53 |
| 53 | ControlFlowNode for c3 | C() | class C | 53 |
| 54 | ControlFlowNode for Attribute | int 10 | builtin-class int | 54 |
| 54 | ControlFlowNode for IntegerLiteral | int 10 | builtin-class int | 54 |
| 54 | ControlFlowNode for c1 | C() | class C | 51 |
| 56 | ControlFlowNode for Attribute | int 20 | builtin-class int | 56 |
| 56 | ControlFlowNode for IntegerLiteral | int 20 | builtin-class int | 56 |
| 56 | ControlFlowNode for c2 | C() | class C | 52 |
| 57 | ControlFlowNode for Attribute | int 10 | builtin-class int | 54 |
| 57 | ControlFlowNode for c1 | C() | class C | 51 |
| 58 | ControlFlowNode for Attribute | int 1 | builtin-class int | 10 |
| 58 | ControlFlowNode for Attribute | int 20 | builtin-class int | 56 |
| 58 | ControlFlowNode for c2 | C() | class C | 52 |
| 59 | ControlFlowNode for Attribute | int 1 | builtin-class int | 10 |
| 59 | ControlFlowNode for c3 | C() | class C | 53 |
| 60 | ControlFlowNode for Attribute | int 30 | builtin-class int | 60 |
| 60 | ControlFlowNode for IntegerLiteral | int 30 | builtin-class int | 60 |
| 60 | ControlFlowNode for c3 | C() | class C | 53 |
| 62 | ControlFlowNode for ClassExpr | class D | builtin-class type | 62 |
| 62 | ControlFlowNode for D | class D | builtin-class type | 62 |
| 62 | ControlFlowNode for object | builtin-class object | builtin-class type | 62 |
| 64 | ControlFlowNode for FunctionExpr | Function meth1 | builtin-class function | 64 |
| 64 | ControlFlowNode for meth1 | Function meth1 | builtin-class function | 64 |
| 65 | ControlFlowNode for Attribute | int 0 | builtin-class int | 65 |
| 65 | ControlFlowNode for IntegerLiteral | int 0 | builtin-class int | 65 |
| 65 | ControlFlowNode for self | self | class D | 64 |
| 65 | ControlFlowNode for self | self | class D | 70 |
| 66 | ControlFlowNode for Attribute | int 1 | builtin-class int | 66 |
| 66 | ControlFlowNode for IntegerLiteral | int 1 | builtin-class int | 66 |
| 66 | ControlFlowNode for self | self | class D | 64 |
| 66 | ControlFlowNode for self | self | class D | 70 |
| 67 | ControlFlowNode for Attribute | int 0 | builtin-class int | 65 |
| 67 | ControlFlowNode for self | self | class D | 64 |
| 67 | ControlFlowNode for self | self | class D | 70 |
| 68 | ControlFlowNode for Attribute | int 1 | builtin-class int | 66 |
| 68 | ControlFlowNode for self | self | class D | 64 |
| 68 | ControlFlowNode for self | self | class D | 70 |
| 70 | ControlFlowNode for FunctionExpr | Function meth2 | builtin-class function | 70 |
| 70 | ControlFlowNode for meth2 | Function meth2 | builtin-class function | 70 |
| 71 | ControlFlowNode for Attribute | float 7.0 | builtin-class float | 71 |
| 71 | ControlFlowNode for FloatLiteral | float 7.0 | builtin-class float | 71 |
| 71 | ControlFlowNode for self | self | class D | 70 |
| 72 | ControlFlowNode for Attribute | int 2 | builtin-class int | 72 |
| 72 | ControlFlowNode for IntegerLiteral | int 2 | builtin-class int | 72 |
| 72 | ControlFlowNode for self | self | class D | 70 |
| 73 | ControlFlowNode for Attribute() | NoneType None | builtin-class NoneType | 64 |
| 73 | ControlFlowNode for self | self | class D | 70 |
| 74 | ControlFlowNode for Attribute | int 0 | builtin-class int | 65 |
| 74 | ControlFlowNode for self | self | class D | 70 |
| 75 | ControlFlowNode for Attribute | int 1 | builtin-class int | 66 |
| 75 | ControlFlowNode for self | self | class D | 70 |
| 76 | ControlFlowNode for Attribute | int 2 | builtin-class int | 72 |
| 76 | ControlFlowNode for self | self | class D | 70 |
| 78 | ControlFlowNode for ClassExpr | class E | builtin-class type | 78 |
| 78 | ControlFlowNode for E | class E | builtin-class type | 78 |
| 78 | ControlFlowNode for object | builtin-class object | builtin-class type | 78 |
| 80 | ControlFlowNode for FunctionExpr | Function __init__ | builtin-class function | 80 |
| 80 | ControlFlowNode for __init__ | Function __init__ | builtin-class function | 80 |
| 82 | ControlFlowNode for Attribute | int 0 | builtin-class int | 82 |
| 82 | ControlFlowNode for IntegerLiteral | int 0 | builtin-class int | 82 |
| 82 | ControlFlowNode for self | self | class E | 80 |
| 84 | ControlFlowNode for Attribute | int 1 | builtin-class int | 84 |
| 84 | ControlFlowNode for IntegerLiteral | int 1 | builtin-class int | 84 |
| 84 | ControlFlowNode for self | self | class E | 80 |
| 86 | ControlFlowNode for E | class E | builtin-class type | 78 |
| 86 | ControlFlowNode for E() | E() | class E | 86 |
| 90 | ControlFlowNode for ClassExpr | class F | builtin-class type | 90 |
| 90 | ControlFlowNode for F | class F | builtin-class type | 90 |
| 90 | ControlFlowNode for object | builtin-class object | builtin-class type | 90 |
| 92 | ControlFlowNode for FunctionExpr | Function meth1 | builtin-class function | 92 |
| 92 | ControlFlowNode for meth1 | Function meth1 | builtin-class function | 92 |
| 93 | ControlFlowNode for IntegerLiteral | int 0 | builtin-class int | 93 |
| 93 | ControlFlowNode for Str | str u'a' | builtin-class str | 93 |
| 93 | ControlFlowNode for self | self | class F | 92 |
| 93 | ControlFlowNode for self | self | class F | 98 |
| 93 | ControlFlowNode for setattr | Builtin-function setattr | builtin-class builtin_function_or_method | 93 |
| 93 | ControlFlowNode for setattr() | NoneType None | builtin-class NoneType | 93 |
| 94 | ControlFlowNode for IntegerLiteral | int 1 | builtin-class int | 94 |
| 94 | ControlFlowNode for Str | str u'b' | builtin-class str | 94 |
| 94 | ControlFlowNode for self | self | class F | 92 |
| 94 | ControlFlowNode for self | self | class F | 98 |
| 94 | ControlFlowNode for setattr | Builtin-function setattr | builtin-class builtin_function_or_method | 94 |
| 94 | ControlFlowNode for setattr() | NoneType None | builtin-class NoneType | 94 |
| 95 | ControlFlowNode for Str | str u'a' | builtin-class str | 95 |
| 95 | ControlFlowNode for getattr | Builtin-function getattr | builtin-class builtin_function_or_method | 95 |
| 95 | ControlFlowNode for getattr() | int 0 | builtin-class int | 93 |
| 95 | ControlFlowNode for self | self | class F | 92 |
| 95 | ControlFlowNode for self | self | class F | 98 |
| 96 | ControlFlowNode for Str | str u'b' | builtin-class str | 96 |
| 96 | ControlFlowNode for getattr | Builtin-function getattr | builtin-class builtin_function_or_method | 96 |
| 96 | ControlFlowNode for getattr() | int 1 | builtin-class int | 94 |
| 96 | ControlFlowNode for self | self | class F | 92 |
| 96 | ControlFlowNode for self | self | class F | 98 |
| 98 | ControlFlowNode for FunctionExpr | Function meth2 | builtin-class function | 98 |
| 98 | ControlFlowNode for meth2 | Function meth2 | builtin-class function | 98 |
| 99 | ControlFlowNode for FloatLiteral | float 7.0 | builtin-class float | 99 |
| 99 | ControlFlowNode for Str | str u'a' | builtin-class str | 99 |
| 99 | ControlFlowNode for self | self | class F | 98 |
| 99 | ControlFlowNode for setattr | Builtin-function setattr | builtin-class builtin_function_or_method | 99 |
| 99 | ControlFlowNode for setattr() | NoneType None | builtin-class NoneType | 99 |
| 100 | ControlFlowNode for IntegerLiteral | int 2 | builtin-class int | 100 |
| 100 | ControlFlowNode for Str | str u'c' | builtin-class str | 100 |
| 100 | ControlFlowNode for self | self | class F | 98 |
| 100 | ControlFlowNode for setattr | Builtin-function setattr | builtin-class builtin_function_or_method | 100 |
| 100 | ControlFlowNode for setattr() | NoneType None | builtin-class NoneType | 100 |
| 101 | ControlFlowNode for Attribute() | NoneType None | builtin-class NoneType | 92 |
| 101 | ControlFlowNode for self | self | class F | 98 |
| 102 | ControlFlowNode for Str | str u'a' | builtin-class str | 102 |
| 102 | ControlFlowNode for getattr | Builtin-function getattr | builtin-class builtin_function_or_method | 102 |
| 102 | ControlFlowNode for getattr() | int 0 | builtin-class int | 93 |
| 102 | ControlFlowNode for self | self | class F | 98 |
| 103 | ControlFlowNode for Str | str u'b' | builtin-class str | 103 |
| 103 | ControlFlowNode for getattr | Builtin-function getattr | builtin-class builtin_function_or_method | 103 |
| 103 | ControlFlowNode for getattr() | int 1 | builtin-class int | 94 |
| 103 | ControlFlowNode for self | self | class F | 98 |
| 104 | ControlFlowNode for Str | str u'c' | builtin-class str | 104 |
| 104 | ControlFlowNode for getattr | Builtin-function getattr | builtin-class builtin_function_or_method | 104 |
| 104 | ControlFlowNode for getattr() | int 2 | builtin-class int | 100 |
| 104 | ControlFlowNode for self | self | class F | 98 |
| 106 | ControlFlowNode for ClassExpr | class G | builtin-class type | 106 |
| 106 | ControlFlowNode for G | class G | builtin-class type | 106 |
| 106 | ControlFlowNode for object | builtin-class object | builtin-class type | 106 |
| 108 | ControlFlowNode for FunctionExpr | Function __init__ | builtin-class function | 108 |
| 108 | ControlFlowNode for __init__ | Function __init__ | builtin-class function | 108 |
| 109 | ControlFlowNode for IntegerLiteral | int 0 | builtin-class int | 109 |
| 109 | ControlFlowNode for Str | str u'x' | builtin-class str | 109 |
| 109 | ControlFlowNode for self | self | class G | 108 |
| 109 | ControlFlowNode for setattr | Builtin-function setattr | builtin-class builtin_function_or_method | 109 |
| 109 | ControlFlowNode for setattr() | NoneType None | builtin-class NoneType | 109 |
| 111 | ControlFlowNode for G | class G | builtin-class type | 106 |
| 111 | ControlFlowNode for G() | G() | class G | 111 |

View File

@@ -0,0 +1,7 @@
import python
from ControlFlowNode f, Object o, ClassObject c, ControlFlowNode x
where f.refersTo(o, c, x)
select f.getLocation().getStartLine(), f.toString(), o.toString(), c.toString(), x.getLocation().getStartLine()

View File

@@ -0,0 +1 @@
semmle-extractor-options: --max-import-depth=0

View File

@@ -0,0 +1,112 @@
from __future__ import unicode_literals
class C(object):
z = None
i = 1
def __init__(self, x, y):
self.x = x
self.y = y
self.z = 1
def f(x, y, z):
c = C(x, y)
c.a = z
c.b = 2
c.x
c.y
c.z
c.a
c.b
#Beware of cross talk, via some non-mapping global object (e.g. None)
def g(x, i, j):
if x:
d1 = None
else:
d1 = []
d1[i] = 0.7
d1[j]
def h(x, i, j):
if x:
d2 = None
else:
d2 = []
d2[i] = 3
d2[j]
#class attributes
def j():
C.__init__
C.i
C.z
#Locally redefined attribute
def k(cond):
c1 = C()
c2 = C()
c3 = C()
c1.z = 10
if cond:
c2.z = 20
c1.z
c2.z
c3.z
c3.z = 30
class D(object):
def meth1(self):
self.a = 0
self.b = 1
self.a
self.b
def meth2(self):
self.a = 7.0
self.c = 2
self.meth1()
self.a
self.b
self.c
class E(object):
def __init__(self, cond):
if cond:
self.x = 0
else:
self.x = 1
E().x
#Make sure that we handle getattr and setattr as well as they are needed for protobuf stubs.
class F(object):
def meth1(self):
setattr(self, "a", 0)
setattr(self, "b", 1)
getattr(self, "a")
getattr(self, "b")
def meth2(self):
setattr(self, "a", 7.0)
setattr(self, "c", 2)
self.meth1()
getattr(self, "a")
getattr(self, "b")
getattr(self, "c")
class G(object):
def __init__(self):
setattr(self, "x", 0)
G().x

View File

@@ -0,0 +1,47 @@
| module.py | 2 | ControlFlowNode for ImportExpr | import | true |
| module.py | 2 | ControlFlowNode for sys | import | true |
| module.py | 3 | ControlFlowNode for Compare | import | false |
| module.py | 3 | ControlFlowNode for IntegerLiteral | import | false |
| module.py | 3 | ControlFlowNode for IntegerLiteral | import | true |
| module.py | 3 | ControlFlowNode for PY2 | import | false |
| module.py | 3 | ControlFlowNode for Subscript | import | true |
| module.py | 3 | ControlFlowNode for sys | import | true |
| test.py | 2 | ControlFlowNode for ImportExpr | import | true |
| test.py | 2 | ControlFlowNode for sys | import | true |
| test.py | 3 | ControlFlowNode for Compare | import | true |
| test.py | 3 | ControlFlowNode for IntegerLiteral | import | false |
| test.py | 3 | ControlFlowNode for IntegerLiteral | import | true |
| test.py | 3 | ControlFlowNode for PY3 | import | true |
| test.py | 3 | ControlFlowNode for Subscript | import | true |
| test.py | 3 | ControlFlowNode for sys | import | true |
| test.py | 8 | ControlFlowNode for True | import | true |
| test.py | 8 | ControlFlowNode for k1 | import | true |
| test.py | 10 | ControlFlowNode for False | import | false |
| test.py | 10 | ControlFlowNode for v1 | import | false |
| test.py | 11 | ControlFlowNode for True | import | true |
| test.py | 11 | ControlFlowNode for v2 | import | true |
| test.py | 12 | ControlFlowNode for IntegerLiteral | import | true |
| test.py | 12 | ControlFlowNode for k1 | import | true |
| test.py | 14 | ControlFlowNode for False | import | false |
| test.py | 14 | ControlFlowNode for v1 | import | false |
| test.py | 15 | ControlFlowNode for True | import | true |
| test.py | 15 | ControlFlowNode for v2 | import | true |
| test.py | 16 | ControlFlowNode for FloatLiteral | import | true |
| test.py | 16 | ControlFlowNode for k1 | import | true |
| test.py | 21 | ControlFlowNode for None | import | false |
| test.py | 21 | ControlFlowNode for k2 | import | false |
| test.py | 23 | ControlFlowNode for False | import | false |
| test.py | 23 | ControlFlowNode for v3 | import | false |
| test.py | 24 | ControlFlowNode for True | import | true |
| test.py | 24 | ControlFlowNode for v4 | import | true |
| test.py | 25 | ControlFlowNode for False | import | false |
| test.py | 25 | ControlFlowNode for k2 | import | false |
| test.py | 33 | ControlFlowNode for k1 | import | true |
| test.py | 34 | ControlFlowNode for k2 | import | false |
| test.py | 36 | ControlFlowNode for ImportExpr | import | true |
| test.py | 36 | ControlFlowNode for ImportMember | import | false |
| test.py | 36 | ControlFlowNode for PY2 | import | false |
| test.py | 38 | ControlFlowNode for PY2 | import | false |
| test.py | 41 | ControlFlowNode for PY3 | import | true |
| test.py | 44 | ControlFlowNode for PY3 | import | true |
| test.py | 47 | ControlFlowNode for PY3 | import | true |

View File

@@ -0,0 +1,14 @@
import python
import semmle.python.pointsto.PointsTo
from ControlFlowNode f, Context c, boolean b
where
exists(Object obj |
PointsTo::points_to(f, c, obj, _, _) and obj.booleanValue() = b
) and
not exists(Object obj |
PointsTo::points_to(f, c, obj, _, _) and not obj.booleanValue() = b
)
select f.getLocation().getFile().getShortName(), f.getLocation().getStartLine(), f.toString(), c.toString(), b

View File

@@ -0,0 +1,3 @@
import sys
PY2 = sys.version_info[0] < 3

View File

@@ -0,0 +1,48 @@
import sys
PY3 = sys.version_info[0] == 3
if unknown():
v1 = unknown()
#v2 undefined
k1 = True
elif unknown2():
v1 = False
v2 = True
k1 = 1
else:
v1 = False
v2 = True
k1 = 0.5
if unknown3():
v3 = unknown()
#v4 undefined
k2 = None
elif unknown4():
v3 = False
v4 = True
k2 = False
else:
raise PruneAnEdge()
v1
v2
v3
v4
k1
k2
from module import PY2
PY2
# Single input "phi"-nodes (due to splitting and pruning).
if PY3:
pass
if PY3:
pass
if PY3:
pass

View File

@@ -0,0 +1,2 @@
| 28 |
| 42 |

View File

@@ -0,0 +1,13 @@
/**
* @name Naive
* @description Insert description here...
* @kind problem
* @problem.severity warning
*/
import python
import semmle.python.pointsto.PointsTo
from ControlFlowNode f, Location l
where not PointsTo::Test::reachableBlock(f.getBasicBlock(), _) and l = f.getLocation() and l.getFile().getName().matches("%test.py")
select l.getStartLine()

View File

@@ -0,0 +1,5 @@
import sys
os_test = sys.platform == "linux"
version_test = sys.version_info < (3,)

View File

@@ -0,0 +1,52 @@
import sys
class C:
pass
class D:
pass
if x:
v1 = C
else:
v1 = D
version_test = sys.version_info < (3,)
from module import version_test as t3
if version_test:
class F: pass
else:
def F(): pass
f = F
if t2:
class G: pass
else:
def G(): pass
g = G
if t3:
class H: pass
else:
def H(): pass
h = H
#Check source origin of some builtins
x = None
x
t = sys.settrace
t

View File

@@ -0,0 +1,6 @@
| 9 | Function meth | 3 |
| 14 | Function meth | 8 |
| 22 | Function meth | 13 |
| 27 | Function meth | 8 |
| 27 | Function meth | 13 |
| 32 | Function meth | 26 |

View File

@@ -0,0 +1,8 @@
import python
from Call c, FunctionObject f
where f.getACall().getNode() = c
select c.getLocation().getStartLine(), f.toString(), f.getFunction().getLocation().getStartLine()

View File

@@ -0,0 +1,32 @@
class Base(object):
def meth(self):
pass
class Derived1(Base):
def meth(self):
return super().meth()
class Derived2(Derived1):
def meth(self):
return super().meth()
class Derived3(Derived1):
pass
class Derived4(Derived3, Derived2):
def meth(self):
return super().meth()
class Derived5(Derived1):
def meth(self):
return super().meth()
class Derived6(Derived5, Derived2):
def meth(self):
return super().meth()

View File

@@ -0,0 +1,6 @@
| class C1 | class Meta1 |
| class C2 | class Meta2 |
| class C3 | builtin-class type |
| class C4 | class Meta2 |
| class Meta1 | builtin-class type |
| class Meta2 | builtin-class type |

View File

@@ -0,0 +1,25 @@
class Meta1(type):
pass
class Meta2(type):
pass
class C1(metaclass=Meta1):
pass
class C2(metaclass=Meta2):
pass
#No explicit metaclass
class C3(object):
pass
#Multiple non-conflicting metaclasses:
class C4(C2, object):
pass
#Metaclass conflict
class C5(C2, C1):
pass

View File

@@ -0,0 +1,6 @@
import python
from ClassObject cls
where not cls.isC()
select cls.toString(), cls.getMetaClass().toString()

View File

@@ -0,0 +1,12 @@
| 3 | class DerivedFromBuiltin | append | Builtin-method append |
| 3 | class DerivedFromBuiltin | clear | Builtin-method clear |
| 3 | class DerivedFromBuiltin | copy | Builtin-method copy |
| 3 | class DerivedFromBuiltin | count | Builtin-method count |
| 3 | class DerivedFromBuiltin | extend | Builtin-method extend |
| 3 | class DerivedFromBuiltin | index | Builtin-method index |
| 3 | class DerivedFromBuiltin | insert | Builtin-method insert |
| 3 | class DerivedFromBuiltin | meth5 | Function meth5 |
| 3 | class DerivedFromBuiltin | pop | Builtin-method pop |
| 3 | class DerivedFromBuiltin | remove | Builtin-method remove |
| 3 | class DerivedFromBuiltin | reverse | Builtin-method reverse |
| 3 | class DerivedFromBuiltin | sort | Builtin-method sort |

View File

@@ -0,0 +1,13 @@
/**
* @name class_attr
* @kind test
* @problem.severity warning
*/
import python
from ClassObject cls, int line, string name, Object obj
where cls.hasLocationInfo(_, line, _, _, _)
and obj = cls.lookupAttribute(name) and
not cls.isC() and not name.matches("\\_\\_%\\_\\_")
select line, cls.toString(), name, obj.toString()

View File

@@ -0,0 +1,12 @@
| 3 | class DerivedFromBuiltin | append |
| 3 | class DerivedFromBuiltin | clear |
| 3 | class DerivedFromBuiltin | copy |
| 3 | class DerivedFromBuiltin | count |
| 3 | class DerivedFromBuiltin | extend |
| 3 | class DerivedFromBuiltin | index |
| 3 | class DerivedFromBuiltin | insert |
| 3 | class DerivedFromBuiltin | meth5 |
| 3 | class DerivedFromBuiltin | pop |
| 3 | class DerivedFromBuiltin | remove |
| 3 | class DerivedFromBuiltin | reverse |
| 3 | class DerivedFromBuiltin | sort |

View File

@@ -0,0 +1,13 @@
/**
* @name class_attr
* @kind test
* @problem.severity warning
*/
import python
from ClassObject cls, int line, string name
where cls.hasLocationInfo(_, line, _, _, _)
and cls.hasAttribute(name) and
not cls.isC() and not name.matches("\\_\\_%\\_\\_")
select line, cls.toString(), name

View File

@@ -0,0 +1,91 @@
| builtin-class list | __add__ | Builtin-method __add__ |
| builtin-class list | __class__ | Property __class__ |
| builtin-class list | __contains__ | Builtin-method __contains__ |
| builtin-class list | __delattr__ | Builtin-method __delattr__ |
| builtin-class list | __delitem__ | Builtin-method __delitem__ |
| builtin-class list | __dir__ | Builtin-method __dir__ |
| builtin-class list | __doc__ | str u'list() -> new empty list\nlist(iterable) -> new list initialized from iterable's items' |
| builtin-class list | __eq__ | Builtin-method __eq__ |
| builtin-class list | __format__ | Builtin-method __format__ |
| builtin-class list | __ge__ | Builtin-method __ge__ |
| builtin-class list | __getattribute__ | Builtin-method __getattribute__ |
| builtin-class list | __getitem__ | Builtin-method __getitem__ |
| builtin-class list | __gt__ | Builtin-method __gt__ |
| builtin-class list | __hash__ | NoneType None |
| builtin-class list | __iadd__ | Builtin-method __iadd__ |
| builtin-class list | __imul__ | Builtin-method __imul__ |
| builtin-class list | __init__ | Builtin-method __init__ |
| builtin-class list | __iter__ | Builtin-method __iter__ |
| builtin-class list | __le__ | Builtin-method __le__ |
| builtin-class list | __len__ | Builtin-method __len__ |
| builtin-class list | __lt__ | Builtin-method __lt__ |
| builtin-class list | __mul__ | Builtin-method __mul__ |
| builtin-class list | __ne__ | Builtin-method __ne__ |
| builtin-class list | __new__ | Builtin-method __new__ |
| builtin-class list | __reduce__ | Builtin-method __reduce__ |
| builtin-class list | __reduce_ex__ | Builtin-method __reduce_ex__ |
| builtin-class list | __repr__ | Builtin-method __repr__ |
| builtin-class list | __reversed__ | Builtin-method __reversed__ |
| builtin-class list | __rmul__ | Builtin-method __rmul__ |
| builtin-class list | __setattr__ | Builtin-method __setattr__ |
| builtin-class list | __setitem__ | Builtin-method __setitem__ |
| builtin-class list | __sizeof__ | Builtin-method __sizeof__ |
| builtin-class list | __str__ | Builtin-method __str__ |
| builtin-class list | __subclasshook__ | classmethod_descriptor __subclasshook__ |
| builtin-class list | append | Builtin-method append |
| builtin-class list | clear | Builtin-method clear |
| builtin-class list | copy | Builtin-method copy |
| builtin-class list | count | Builtin-method count |
| builtin-class list | extend | Builtin-method extend |
| builtin-class list | index | Builtin-method index |
| builtin-class list | insert | Builtin-method insert |
| builtin-class list | pop | Builtin-method pop |
| builtin-class list | remove | Builtin-method remove |
| builtin-class list | reverse | Builtin-method reverse |
| builtin-class list | sort | Builtin-method sort |
| class DerivedFromBuiltin | __add__ | Builtin-method __add__ |
| class DerivedFromBuiltin | __class__ | Property __class__ |
| class DerivedFromBuiltin | __contains__ | Builtin-method __contains__ |
| class DerivedFromBuiltin | __delattr__ | Builtin-method __delattr__ |
| class DerivedFromBuiltin | __delitem__ | Builtin-method __delitem__ |
| class DerivedFromBuiltin | __dir__ | Builtin-method __dir__ |
| class DerivedFromBuiltin | __doc__ | str u'list() -> new empty list\nlist(iterable) -> new list initialized from iterable's items' |
| class DerivedFromBuiltin | __eq__ | Builtin-method __eq__ |
| class DerivedFromBuiltin | __format__ | Builtin-method __format__ |
| class DerivedFromBuiltin | __ge__ | Builtin-method __ge__ |
| class DerivedFromBuiltin | __getattribute__ | Builtin-method __getattribute__ |
| class DerivedFromBuiltin | __getitem__ | Builtin-method __getitem__ |
| class DerivedFromBuiltin | __gt__ | Builtin-method __gt__ |
| class DerivedFromBuiltin | __hash__ | NoneType None |
| class DerivedFromBuiltin | __iadd__ | Builtin-method __iadd__ |
| class DerivedFromBuiltin | __imul__ | Builtin-method __imul__ |
| class DerivedFromBuiltin | __init__ | Builtin-method __init__ |
| class DerivedFromBuiltin | __iter__ | Builtin-method __iter__ |
| class DerivedFromBuiltin | __le__ | Builtin-method __le__ |
| class DerivedFromBuiltin | __len__ | Builtin-method __len__ |
| class DerivedFromBuiltin | __lt__ | Builtin-method __lt__ |
| class DerivedFromBuiltin | __mul__ | Builtin-method __mul__ |
| class DerivedFromBuiltin | __ne__ | Builtin-method __ne__ |
| class DerivedFromBuiltin | __new__ | Builtin-method __new__ |
| class DerivedFromBuiltin | __reduce__ | Builtin-method __reduce__ |
| class DerivedFromBuiltin | __reduce_ex__ | Builtin-method __reduce_ex__ |
| class DerivedFromBuiltin | __repr__ | Builtin-method __repr__ |
| class DerivedFromBuiltin | __reversed__ | Builtin-method __reversed__ |
| class DerivedFromBuiltin | __rmul__ | Builtin-method __rmul__ |
| class DerivedFromBuiltin | __setattr__ | Builtin-method __setattr__ |
| class DerivedFromBuiltin | __setitem__ | Builtin-method __setitem__ |
| class DerivedFromBuiltin | __sizeof__ | Builtin-method __sizeof__ |
| class DerivedFromBuiltin | __str__ | Builtin-method __str__ |
| class DerivedFromBuiltin | __subclasshook__ | classmethod_descriptor __subclasshook__ |
| class DerivedFromBuiltin | append | Builtin-method append |
| class DerivedFromBuiltin | clear | Builtin-method clear |
| class DerivedFromBuiltin | copy | Builtin-method copy |
| class DerivedFromBuiltin | count | Builtin-method count |
| class DerivedFromBuiltin | extend | Builtin-method extend |
| class DerivedFromBuiltin | index | Builtin-method index |
| class DerivedFromBuiltin | insert | Builtin-method insert |
| class DerivedFromBuiltin | meth5 | Function meth5 |
| class DerivedFromBuiltin | pop | Builtin-method pop |
| class DerivedFromBuiltin | remove | Builtin-method remove |
| class DerivedFromBuiltin | reverse | Builtin-method reverse |
| class DerivedFromBuiltin | sort | Builtin-method sort |

View File

@@ -0,0 +1,16 @@
/**
* @name class_attr
* @kind test
* @problem.severity warning
*/
import python
from ClassObject cls, string name, Object what
where
(cls.getName() = "list" or
cls.getASuperType().getName() = "list"
)
and
cls.lookupAttribute(name) = what
select cls.toString(), name, what.toString()

View File

@@ -0,0 +1,6 @@
class DerivedFromBuiltin(list):
def meth5(self):
pass

View File

@@ -0,0 +1 @@
| ClassExpr | Meta |

View File

@@ -0,0 +1,4 @@
import python
from ClassExpr cls
select cls.toString(), cls.getMetaClass().toString()

View File

@@ -0,0 +1,2 @@
| class HasMeta | class Meta |
| class Meta | builtin-class type |

View File

@@ -0,0 +1,5 @@
import python
from ClassObject cls
where not cls.isC()
select cls.toString(), cls.getAnInferredType().toString()

View File

@@ -0,0 +1,6 @@
class Meta(type):
pass
class HasMeta(object, metaclass=Meta):
pass

View File

@@ -0,0 +1,21 @@
| class Meta | builtin-class type | builtin-class object |
| class Meta | class Meta | builtin-class type |
| class NewStyle | class NewStyle | builtin-class object |
| class NewStyleDerived | class NewStyle | builtin-class object |
| class NewStyleDerived | class NewStyleDerived | class NewStyle |
| class O | class O | builtin-class object |
| class Oddities | class Oddities | builtin-class object |
| class OldStyle | class OldStyle | builtin-class object |
| class OldStyleDerived | class OldStyle | builtin-class object |
| class OldStyleDerived | class OldStyleDerived | class OldStyle |
| class Sub | class Oddities | class Unhashable |
| class Sub | class Sub | class Oddities |
| class Sub | class Unhashable | builtin-class object |
| class Unhashable | class Unhashable | builtin-class object |
| class W | class W | class Y |
| class W | class X | builtin-class object |
| class W | class Y | class X |
| class WithMeta | class WithMeta | builtin-class object |
| class X | class X | builtin-class object |
| class Y | class X | builtin-class object |
| class Y | class Y | class X |

View File

@@ -0,0 +1,12 @@
/**
* @name class_attr
* @kind test
* @problem.severity warning
*/
import python
from ClassObject cls, ClassObject l, ClassObject r
where not cls.isC() and
r = cls.nextInMro(l)
select cls.toString(), l.toString(), r.toString()

View File

@@ -0,0 +1,34 @@
| class Meta | 0 | class Meta |
| class Meta | 1 | builtin-class type |
| class Meta | 2 | builtin-class object |
| class NewStyle | 0 | class NewStyle |
| class NewStyle | 1 | builtin-class object |
| class NewStyleDerived | 0 | class NewStyleDerived |
| class NewStyleDerived | 1 | class NewStyle |
| class NewStyleDerived | 2 | builtin-class object |
| class O | 0 | class O |
| class O | 1 | builtin-class object |
| class Oddities | 0 | class Oddities |
| class Oddities | 1 | builtin-class object |
| class OldStyle | 0 | class OldStyle |
| class OldStyle | 1 | builtin-class object |
| class OldStyleDerived | 0 | class OldStyleDerived |
| class OldStyleDerived | 1 | class OldStyle |
| class OldStyleDerived | 2 | builtin-class object |
| class Sub | 0 | class Sub |
| class Sub | 1 | class Oddities |
| class Sub | 2 | class Unhashable |
| class Sub | 3 | builtin-class object |
| class Unhashable | 0 | class Unhashable |
| class Unhashable | 1 | builtin-class object |
| class W | 0 | class W |
| class W | 1 | class Y |
| class W | 2 | class X |
| class W | 3 | builtin-class object |
| class WithMeta | 0 | class WithMeta |
| class WithMeta | 1 | builtin-class object |
| class X | 0 | class X |
| class X | 1 | builtin-class object |
| class Y | 0 | class Y |
| class Y | 1 | class X |
| class Y | 2 | builtin-class object |

View File

@@ -0,0 +1,12 @@
/**
* @name class_attr
* @kind test
* @problem.severity warning
*/
import python
from ClassObject cls, ClassObject sup, int index
where sup = cls.getMroItem(index) and
not cls.isC()
select cls.toString(), index, sup.toString()

View File

@@ -0,0 +1,114 @@
from undefined import unknown
k = 1
l = []
class OldStyle:
def meth1(self):
pass
a1 = k
a2 = l
a3 = unknown
l = l
class OldStyleDerived(OldStyle):
def meth2(self):
pass
class NewStyle(object):
def meth3(self):
pass
a1 = k
a2 = l
a3 = unknown
l = l
class NewStyleDerived(NewStyle):
def meth4(self):
pass
class Meta(type):
def __init__(cls, name, bases, dct):
type.__init__(cls, name, bases, dct)
cls.defined_in_meta = 1
def meth5(self):
pass
class WithMeta(object):
def meth6(self):
pass
a1 = k
a2 = l
a3 = unknown
l = l
#MRO tests
#Inconsistent MRO
class X(object):
pass
class Y(X):
pass
#Inconsistent MRO
class Z(X, Y):
pass
#Ok
class W(Y, X):
pass
class O:
pass
#This class has an invalid MRO.
class N(object, O):
pass
#
# Assign builtin objects to class atttibutes
len = len
ord = 10
class Unhashable(object):
__hash__ = None
class Oddities(object):
int = int
float = float
l = len
h = hash
class Sub(Oddities, Unhashable):
pass

View File

@@ -0,0 +1,53 @@
| 0 | 0 | 0 | 0 | Module test |
| 3 | 1 | 5 | 44 | Function func |
| 3 | 1 | 5 | 44 | FunctionDef |
| 3 | 1 | 5 | 44 | FunctionExpr |
| 3 | 5 | 3 | 8 | func |
| 3 | 10 | 3 | 20 | callee_type |
| 3 | 23 | 3 | 34 | CallableType |
| 4 | 10 | 4 | 25 | formal_to_actual |
| 4 | 28 | 4 | 31 | List |
| 4 | 28 | 4 | 42 | Subscript |
| 4 | 33 | 4 | 36 | List |
| 4 | 33 | 4 | 41 | Subscript |
| 4 | 38 | 4 | 40 | int |
| 5 | 10 | 5 | 15 | strict |
| 5 | 18 | 5 | 21 | bool |
| 5 | 25 | 5 | 28 | True |
| 5 | 34 | 5 | 37 | List |
| 5 | 34 | 5 | 43 | Subscript |
| 5 | 39 | 5 | 42 | Type |
| 6 | 5 | 6 | 8 | Pass |
| 9 | 1 | 14 | 45 | Function func |
| 9 | 1 | 14 | 45 | FunctionDef |
| 9 | 1 | 14 | 45 | FunctionExpr |
| 9 | 5 | 9 | 8 | func |
| 9 | 10 | 9 | 13 | self |
| 10 | 10 | 10 | 13 | name |
| 10 | 16 | 10 | 18 | str |
| 11 | 10 | 11 | 13 | args |
| 11 | 16 | 11 | 19 | List |
| 11 | 16 | 11 | 24 | Subscript |
| 11 | 21 | 11 | 23 | str |
| 13 | 10 | 13 | 12 | cwd |
| 13 | 15 | 13 | 17 | str |
| 13 | 21 | 13 | 24 | None |
| 14 | 10 | 14 | 12 | env |
| 14 | 15 | 14 | 18 | Dict |
| 14 | 15 | 14 | 28 | Subscript |
| 14 | 20 | 14 | 22 | str |
| 14 | 20 | 14 | 27 | Tuple |
| 14 | 25 | 14 | 27 | str |
| 14 | 32 | 14 | 35 | None |
| 14 | 41 | 14 | 44 | None |
| 15 | 5 | 15 | 8 | Pass |
| 17 | 1 | 17 | 54 | Function specials |
| 17 | 1 | 17 | 54 | FunctionDef |
| 17 | 1 | 17 | 54 | FunctionExpr |
| 17 | 5 | 17 | 12 | specials |
| 17 | 14 | 17 | 17 | self |
| 17 | 21 | 17 | 27 | varargs |
| 17 | 30 | 17 | 34 | vanno |
| 17 | 39 | 17 | 44 | kwargs |
| 17 | 47 | 17 | 52 | kwanno |
| 18 | 5 | 18 | 8 | Pass |

View File

@@ -0,0 +1,6 @@
import python
from AstNode a, Location l
where a.getLocation() = l
select l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn(), a.toString()

View File

@@ -0,0 +1,19 @@
#PEP 484 style annotations.
def func(callee_type: CallableType,
formal_to_actual: List[List[int]],
strict: bool = True) -> List[Type]:
pass
def func(self,
name: str,
args: List[str],
*,
cwd: str = None,
env: Dict[str, str] = None) -> None:
pass
def specials(self, *varargs: vanno, **kwargs: kwanno):
pass

View File

@@ -0,0 +1,16 @@
/**
* @name All must have locations
* @description
* @kind problem
* @problem.severity error
*/
import python
from string classname
where
exists(AstNode node | not exists(node.getLocation()) and classname = node.getAQlClass())
or
exists(ControlFlowNode node | not exists(node.getLocation()) and classname = node.getAQlClass())
select classname

View File

@@ -0,0 +1,320 @@
| Assert | 8 | 9 | 8 | 21 |
| AssignStmt | 9 | 9 | 9 | 13 |
| AssignStmt | 42 | 9 | 42 | 16 |
| AssignStmt | 43 | 9 | 43 | 16 |
| AssignStmt | 44 | 9 | 44 | 17 |
| AssignStmt | 45 | 9 | 45 | 23 |
| Attribute | 43 | 13 | 43 | 16 |
| Attribute | 54 | 20 | 54 | 22 |
| Attribute | 54 | 25 | 54 | 28 |
| AugAssign | 10 | 9 | 10 | 14 |
| AugAssign | 14 | 13 | 14 | 18 |
| BinaryExpr | 10 | 9 | 10 | 14 |
| BinaryExpr | 14 | 13 | 14 | 18 |
| BinaryExpr | 31 | 13 | 31 | 15 |
| BinaryExpr | 44 | 13 | 44 | 17 |
| BinaryExpr | 53 | 20 | 53 | 24 |
| BinaryExpr | 55 | 11 | 55 | 18 |
| BinaryExpr | 101 | 1 | 101 | 13 |
| BinaryExpr | 101 | 1 | 101 | 23 |
| BinaryExpr | 102 | 1 | 102 | 3 |
| BinaryExpr | 102 | 1 | 102 | 7 |
| BinaryExpr | 103 | 1 | 103 | 7 |
| BinaryExpr | 103 | 4 | 103 | 6 |
| Break | 12 | 13 | 12 | 17 |
| Bytes | 45 | 13 | 45 | 23 |
| Call | 17 | 9 | 17 | 11 |
| Call | 21 | 13 | 21 | 20 |
| Call | 28 | 14 | 28 | 25 |
| Call | 37 | 19 | 37 | 29 |
| Call | 46 | 9 | 46 | 56 |
| Call | 55 | 29 | 55 | 34 |
| Call | 83 | 2 | 83 | 5 |
| Call | 102 | 5 | 102 | 7 |
| ClassDef | 4 | 1 | 4 | 8 |
| ClassExpr | 4 | 1 | 4 | 8 |
| ClassMetrics | 4 | 1 | 4 | 8 |
| Compare | 8 | 16 | 8 | 21 |
| Compare | 13 | 15 | 13 | 19 |
| Compare | 47 | 9 | 47 | 13 |
| Compare | 52 | 15 | 52 | 19 |
| Continue | 15 | 13 | 15 | 20 |
| Delete | 33 | 13 | 33 | 17 |
| Delete | 35 | 13 | 35 | 17 |
| Dict | 46 | 54 | 46 | 55 |
| Dict | 48 | 9 | 48 | 19 |
| DictUnpacking | 46 | 52 | 46 | 55 |
| Ellipsis | 7 | 7 | 7 | 9 |
| Ellipsis | 50 | 14 | 50 | 16 |
| ExceptStmt | 32 | 9 | 32 | 31 |
| ExprStmt | 2 | 1 | 2 | 4 |
| ExprStmt | 3 | 1 | 3 | 6 |
| ExprStmt | 4 | 1 | 4 | 7 |
| ExprStmt | 5 | 1 | 5 | 9 |
| ExprStmt | 6 | 1 | 6 | 13 |
| ExprStmt | 7 | 1 | 7 | 14 |
| ExprStmt | 17 | 9 | 17 | 11 |
| ExprStmt | 21 | 13 | 21 | 20 |
| ExprStmt | 31 | 13 | 31 | 15 |
| ExprStmt | 46 | 9 | 46 | 56 |
| ExprStmt | 47 | 9 | 47 | 13 |
| ExprStmt | 48 | 9 | 48 | 19 |
| ExprStmt | 50 | 9 | 50 | 20 |
| ExprStmt | 51 | 9 | 51 | 22 |
| ExprStmt | 51 | 10 | 51 | 10 |
| ExprStmt | 52 | 9 | 52 | 27 |
| ExprStmt | 53 | 9 | 53 | 24 |
| ExprStmt | 54 | 9 | 54 | 30 |
| ExprStmt | 55 | 9 | 55 | 36 |
| ExprStmt | 55 | 11 | 55 | 18 |
| ExprStmt | 60 | 9 | 60 | 13 |
| ExprStmt | 61 | 9 | 61 | 12 |
| ExprStmt | 62 | 9 | 62 | 15 |
| ExprStmt | 63 | 9 | 63 | 19 |
| ExprStmt | 66 | 1 | 67 | 23 |
| ExprStmt | 69 | 1 | 71 | 9 |
| ExprStmt | 73 | 1 | 75 | 3 |
| ExprStmt | 77 | 1 | 80 | 3 |
| ExprStmt | 93 | 1 | 98 | 1 |
| ExprStmt | 93 | 2 | 95 | 3 |
| ExprStmt | 94 | 3 | 94 | 3 |
| ExprStmt | 101 | 1 | 101 | 23 |
| ExprStmt | 102 | 1 | 102 | 7 |
| ExprStmt | 103 | 1 | 103 | 7 |
| FastLocalsFunction | 6 | 5 | 6 | 22 |
| FastLocalsFunction | 41 | 5 | 41 | 22 |
| FastLocalsFunction | 51 | 10 | 51 | 21 |
| FastLocalsFunction | 53 | 9 | 53 | 24 |
| FastLocalsFunction | 55 | 9 | 55 | 36 |
| FastLocalsFunction | 84 | 1 | 84 | 8 |
| FastLocalsFunction | 88 | 1 | 88 | 12 |
| FastLocalsFunction | 89 | 5 | 89 | 16 |
| FastLocalsFunction | 93 | 1 | 98 | 1 |
| FastLocalsFunction | 93 | 2 | 95 | 3 |
| For | 18 | 9 | 18 | 19 |
| For | 51 | 10 | 51 | 21 |
| For | 55 | 9 | 55 | 36 |
| For | 93 | 1 | 98 | 1 |
| For | 93 | 2 | 95 | 3 |
| FunctionDef | 6 | 5 | 6 | 22 |
| FunctionDef | 41 | 5 | 41 | 22 |
| FunctionDef | 84 | 1 | 84 | 8 |
| FunctionDef | 88 | 1 | 88 | 12 |
| FunctionDef | 89 | 5 | 89 | 16 |
| FunctionExpr | 6 | 5 | 6 | 22 |
| FunctionExpr | 41 | 5 | 41 | 22 |
| FunctionExpr | 84 | 1 | 84 | 8 |
| FunctionExpr | 88 | 1 | 88 | 12 |
| FunctionExpr | 89 | 5 | 89 | 16 |
| FunctionMetrics | 6 | 5 | 6 | 22 |
| FunctionMetrics | 41 | 5 | 41 | 22 |
| FunctionMetrics | 51 | 10 | 51 | 21 |
| FunctionMetrics | 53 | 9 | 53 | 24 |
| FunctionMetrics | 55 | 9 | 55 | 36 |
| FunctionMetrics | 84 | 1 | 84 | 8 |
| FunctionMetrics | 88 | 1 | 88 | 12 |
| FunctionMetrics | 89 | 5 | 89 | 16 |
| FunctionMetrics | 93 | 1 | 98 | 1 |
| FunctionMetrics | 93 | 2 | 95 | 3 |
| GeneratorExp | 51 | 10 | 51 | 21 |
| Global | 7 | 9 | 7 | 16 |
| If | 20 | 9 | 20 | 13 |
| If | 36 | 9 | 36 | 13 |
| IfExp | 52 | 9 | 52 | 27 |
| Import | 22 | 9 | 22 | 16 |
| Import | 23 | 9 | 23 | 23 |
| Import | 24 | 9 | 24 | 21 |
| Import | 25 | 9 | 25 | 25 |
| ImportExpr | 22 | 16 | 22 | 16 |
| ImportExpr | 23 | 16 | 23 | 18 |
| ImportExpr | 24 | 16 | 24 | 16 |
| ImportExpr | 25 | 14 | 25 | 16 |
| ImportMember | 25 | 25 | 25 | 25 |
| ImportingStmt | 22 | 9 | 22 | 16 |
| ImportingStmt | 23 | 9 | 23 | 23 |
| ImportingStmt | 24 | 9 | 24 | 21 |
| ImportingStmt | 25 | 9 | 25 | 25 |
| IntegerLiteral | 2 | 3 | 2 | 3 |
| IntegerLiteral | 3 | 3 | 3 | 3 |
| IntegerLiteral | 3 | 5 | 3 | 5 |
| IntegerLiteral | 4 | 3 | 4 | 3 |
| IntegerLiteral | 4 | 6 | 4 | 6 |
| IntegerLiteral | 5 | 3 | 5 | 3 |
| IntegerLiteral | 5 | 6 | 5 | 6 |
| IntegerLiteral | 5 | 8 | 5 | 8 |
| IntegerLiteral | 6 | 3 | 6 | 3 |
| IntegerLiteral | 6 | 5 | 6 | 5 |
| IntegerLiteral | 6 | 8 | 6 | 9 |
| IntegerLiteral | 6 | 11 | 6 | 12 |
| IntegerLiteral | 7 | 3 | 7 | 4 |
| IntegerLiteral | 7 | 12 | 7 | 13 |
| IntegerLiteral | 8 | 21 | 8 | 21 |
| IntegerLiteral | 9 | 13 | 9 | 13 |
| IntegerLiteral | 10 | 14 | 10 | 14 |
| IntegerLiteral | 13 | 19 | 13 | 19 |
| IntegerLiteral | 14 | 18 | 14 | 18 |
| IntegerLiteral | 31 | 13 | 31 | 13 |
| IntegerLiteral | 31 | 15 | 31 | 15 |
| IntegerLiteral | 42 | 16 | 42 | 16 |
| IntegerLiteral | 44 | 13 | 44 | 13 |
| IntegerLiteral | 44 | 17 | 44 | 17 |
| IntegerLiteral | 48 | 10 | 48 | 10 |
| IntegerLiteral | 48 | 12 | 48 | 12 |
| IntegerLiteral | 48 | 15 | 48 | 15 |
| IntegerLiteral | 48 | 18 | 48 | 18 |
| IntegerLiteral | 50 | 19 | 50 | 19 |
| IntegerLiteral | 52 | 9 | 52 | 10 |
| IntegerLiteral | 52 | 26 | 52 | 27 |
| IntegerLiteral | 54 | 11 | 54 | 11 |
| IntegerLiteral | 54 | 14 | 54 | 14 |
| IntegerLiteral | 61 | 11 | 61 | 11 |
| IntegerLiteral | 62 | 13 | 62 | 13 |
| IntegerLiteral | 63 | 18 | 63 | 18 |
| IntegerLiteral | 102 | 1 | 102 | 1 |
| IntegerLiteral | 102 | 3 | 102 | 3 |
| IntegerLiteral | 103 | 1 | 103 | 1 |
| IntegerLiteral | 103 | 4 | 103 | 4 |
| IntegerLiteral | 103 | 6 | 103 | 6 |
| KeyValuePair | 48 | 10 | 48 | 12 |
| KeyValuePair | 48 | 15 | 48 | 18 |
| Keyword | 46 | 26 | 46 | 35 |
| Keyword | 46 | 38 | 46 | 44 |
| Lambda | 53 | 9 | 53 | 24 |
| List | 54 | 9 | 54 | 30 |
| ListComp | 55 | 9 | 55 | 36 |
| ListComp | 93 | 1 | 98 | 1 |
| ListComp | 93 | 2 | 95 | 3 |
| ModuleMetrics | 0 | 0 | 0 | 0 |
| Name | 2 | 1 | 2 | 1 |
| Name | 3 | 1 | 3 | 1 |
| Name | 4 | 1 | 4 | 1 |
| Name | 4 | 7 | 4 | 7 |
| Name | 5 | 1 | 5 | 1 |
| Name | 6 | 1 | 6 | 1 |
| Name | 6 | 9 | 6 | 13 |
| Name | 6 | 15 | 6 | 16 |
| Name | 6 | 19 | 6 | 20 |
| Name | 7 | 1 | 7 | 1 |
| Name | 8 | 16 | 8 | 16 |
| Name | 9 | 9 | 9 | 9 |
| Name | 10 | 9 | 10 | 9 |
| Name | 13 | 15 | 13 | 15 |
| Name | 14 | 13 | 14 | 13 |
| Name | 17 | 9 | 17 | 9 |
| Name | 18 | 13 | 18 | 13 |
| Name | 18 | 18 | 18 | 18 |
| Name | 20 | 12 | 20 | 12 |
| Name | 21 | 13 | 21 | 17 |
| Name | 21 | 19 | 21 | 19 |
| Name | 22 | 16 | 22 | 16 |
| Name | 23 | 23 | 23 | 23 |
| Name | 24 | 21 | 24 | 21 |
| Name | 25 | 25 | 25 | 25 |
| Name | 28 | 14 | 28 | 17 |
| Name | 28 | 30 | 28 | 30 |
| Name | 32 | 16 | 32 | 24 |
| Name | 32 | 29 | 32 | 30 |
| Name | 33 | 17 | 33 | 17 |
| Name | 35 | 17 | 35 | 17 |
| Name | 36 | 12 | 36 | 12 |
| Name | 37 | 19 | 37 | 27 |
| Name | 41 | 9 | 41 | 13 |
| Name | 41 | 15 | 41 | 16 |
| Name | 41 | 19 | 41 | 20 |
| Name | 42 | 9 | 42 | 10 |
| Name | 43 | 9 | 43 | 9 |
| Name | 43 | 13 | 43 | 14 |
| Name | 44 | 9 | 44 | 9 |
| Name | 45 | 9 | 45 | 9 |
| Name | 46 | 9 | 46 | 12 |
| Name | 46 | 14 | 46 | 17 |
| Name | 46 | 20 | 46 | 23 |
| Name | 46 | 44 | 46 | 44 |
| Name | 47 | 9 | 47 | 9 |
| Name | 47 | 13 | 47 | 13 |
| Name | 50 | 9 | 50 | 9 |
| Name | 50 | 11 | 50 | 11 |
| Name | 51 | 10 | 51 | 10 |
| Name | 51 | 10 | 51 | 21 |
| Name | 51 | 16 | 51 | 16 |
| Name | 51 | 21 | 51 | 21 |
| Name | 52 | 15 | 52 | 15 |
| Name | 52 | 19 | 52 | 19 |
| Name | 53 | 16 | 53 | 16 |
| Name | 53 | 20 | 53 | 20 |
| Name | 53 | 24 | 53 | 24 |
| Name | 54 | 17 | 54 | 17 |
| Name | 54 | 20 | 54 | 20 |
| Name | 54 | 25 | 54 | 26 |
| Name | 55 | 9 | 55 | 36 |
| Name | 55 | 11 | 55 | 11 |
| Name | 55 | 24 | 55 | 24 |
| Name | 55 | 29 | 55 | 31 |
| Name | 55 | 33 | 55 | 33 |
| Name | 61 | 9 | 61 | 9 |
| Name | 62 | 9 | 62 | 9 |
| Name | 62 | 11 | 62 | 11 |
| Name | 63 | 10 | 63 | 11 |
| Name | 63 | 14 | 63 | 15 |
| Name | 83 | 2 | 83 | 5 |
| Name | 84 | 5 | 84 | 5 |
| Name | 88 | 5 | 88 | 9 |
| Name | 89 | 9 | 89 | 13 |
| Name | 93 | 1 | 98 | 1 |
| Name | 93 | 2 | 95 | 3 |
| Name | 94 | 3 | 94 | 3 |
| Name | 94 | 9 | 94 | 9 |
| Name | 94 | 14 | 94 | 14 |
| Name | 97 | 7 | 97 | 7 |
| Name | 97 | 12 | 97 | 12 |
| Name | 102 | 5 | 102 | 5 |
| Pass | 19 | 13 | 19 | 16 |
| Pass | 29 | 13 | 29 | 16 |
| Pass | 85 | 5 | 85 | 8 |
| Pass | 90 | 9 | 90 | 12 |
| Raise | 37 | 13 | 37 | 29 |
| Return | 39 | 13 | 39 | 18 |
| Return | 53 | 20 | 53 | 24 |
| SelfAttributeStore | 42 | 9 | 42 | 12 |
| Slice | 3 | 3 | 3 | 5 |
| Slice | 5 | 6 | 5 | 8 |
| Slice | 6 | 3 | 6 | 5 |
| Slice | 6 | 8 | 6 | 12 |
| Starred | 46 | 47 | 46 | 49 |
| Subscript | 2 | 1 | 2 | 4 |
| Subscript | 3 | 1 | 3 | 6 |
| Subscript | 4 | 1 | 4 | 7 |
| Subscript | 5 | 1 | 5 | 9 |
| Subscript | 6 | 1 | 6 | 13 |
| Subscript | 7 | 1 | 7 | 14 |
| Subscript | 50 | 9 | 50 | 20 |
| Subscript | 61 | 9 | 61 | 12 |
| Subscript | 62 | 9 | 62 | 15 |
| Subscript | 62 | 11 | 62 | 14 |
| True | 11 | 15 | 11 | 18 |
| Try | 30 | 9 | 30 | 12 |
| Tuple | 4 | 3 | 4 | 6 |
| Tuple | 5 | 3 | 5 | 8 |
| Tuple | 6 | 3 | 6 | 12 |
| Tuple | 7 | 3 | 7 | 13 |
| Tuple | 46 | 48 | 46 | 49 |
| Tuple | 50 | 11 | 50 | 19 |
| Tuple | 63 | 10 | 63 | 18 |
| Unicode | 28 | 19 | 28 | 24 |
| Unicode | 46 | 32 | 46 | 35 |
| Unicode | 55 | 15 | 55 | 18 |
| Unicode | 60 | 9 | 60 | 13 |
| Unicode | 66 | 1 | 67 | 23 |
| Unicode | 69 | 1 | 71 | 9 |
| Unicode | 73 | 1 | 75 | 3 |
| Unicode | 77 | 1 | 80 | 3 |
| Unicode | 101 | 1 | 101 | 7 |
| Unicode | 101 | 11 | 101 | 13 |
| Unicode | 101 | 17 | 101 | 23 |
| While | 11 | 9 | 11 | 19 |
| While | 13 | 9 | 13 | 20 |
| With | 28 | 9 | 28 | 31 |
| Yield | 51 | 10 | 51 | 10 |
| Yield | 55 | 11 | 55 | 18 |
| Yield | 93 | 2 | 95 | 3 |
| Yield | 94 | 3 | 94 | 3 |

View File

@@ -0,0 +1,6 @@
import python
from AstNode ast, Location l
where ast.getLocation() = l
select ast.getAQlClass(), l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn()

View File

@@ -0,0 +1,12 @@
| 28 | file | " |
| 45 | h4tpvhsa | b' |
| 46 | Hi | " |
| 55 | Hi | " |
| 60 | Hi | u" |
| 66 | \nSingle quotes string | ''' |
| 69 | \nDouble-quotes\nstring | """ |
| 73 | \nBytes\n | r''' |
| 77 | \nRaw\nUnicode\n | U""" |
| 101 | | " |
| 101 | Hello | " |
| 101 | world | " |

View File

@@ -0,0 +1,5 @@
import python
from StrConst s
select s.getLocation().getStartLine(), s.getText(), s.getPrefix()

View File

@@ -0,0 +1,8 @@
v[0]
w[1:2]
x[3, 4]
y[5, 6:7]
z[8:9, 10:11]
z[12, ..., 13]

View File

@@ -0,0 +1,104 @@
#AST nodes: Classes, Functions, Modules, expr, stmts
class C:
def stmts(p0, p1):
global x
assert x == 2
y = 3
y += 4
while True:
break
while x > 0:
x -= 1
continue
f()
for x in y:
pass
if x:
print(y)
import a
import a.b as c
import a as b
from a.b import c
with open("file") as f:
pass
try:
1/0
except Exception as ex:
del y
finally:
del x
if x:
raise Exception()
else:
return
def exprs(p2, p3):
p2.x = 2
a = p3.y
x = 1 + 2
y = b'h4tpvhsa'
call(arg0, arg1, name0="Hi", name1=y, *(), **{})
x < y
{1:1, 2: 2}
x[a, ..., 7]
(x for x in y)
17 if x < y else 16
lambda x : x * y
[ 1, 2, a, x.b, p1.c ]
[ a + "Hi" for a in str(y) ]
#a, *b = y
u"Hi"
x[0]
x[y[0]]
(p2, p3, 7)
#Some multiline strings
'''
Single quotes string'''
"""
Double-quotes
string"""
r'''
Bytes
'''
U"""
Raw
Unicode
"""
#Decorated function
@deco
def f():
pass
#Inner function (see ODASA-1774)
def outer():
def inner():
pass
#Oddly laid out comprehension
[[
x for x in y
]
for a in b
]
#Nested binary operations
"Hello" + " " + "world"
1+2+f()
1+(2+3)

View File

@@ -0,0 +1,3 @@
| 3 | 3 | 3 | 10 |
| 3 | 13 | 3 | 39 |
| 4 | 3 | 12 | 6 |

View File

@@ -0,0 +1,6 @@
import python
from Keyword k, Location l
where k.getLocation() = l
select l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn()

View File

@@ -0,0 +1,12 @@
#Keywords
f(name=val, spaced = val2)
f(multi
=
line)

View File

@@ -0,0 +1,3 @@
e = 5

View File

@@ -0,0 +1 @@
from .a import b as a

View File

@@ -0,0 +1,2 @@
b = 1

View File

@@ -0,0 +1,6 @@
class Wrong: pass
class CorrectIn3(object):
pass
d = Wrong()

View File

@@ -0,0 +1,15 @@
| Module confused_elements.__init__ | 1 | ImportExpr | 1 | bottom | relative | confused_elements.a |
| Module main | 1 | ImportExpr | 0 | top | absolute | package |
| Module main | 2 | ImportExpr | 0 | top | absolute | helper |
| Module main | 3 | ImportExpr | 0 | top | absolute | package |
| Module main | 5 | ImportExpr | 0 | bottom | absolute | confused_elements |
| Module main | 7 | ImportExpr | 0 | top | absolute | sys |
| Module package.__init__ | 7 | ImportExpr | 1 | bottom | relative | package.helper |
| Module package.__init__ | 10 | ImportExpr | 1 | bottom | relative | package.helper |
| Module package.__init__ | 12 | ImportExpr | 1 | bottom | relative | package.assistant |
| Module package.__init__ | 14 | ImportExpr | 1 | bottom | relative | package |
| Module package.helper | 1 | ImportExpr | 0 | bottom | absolute | __future__ |
| Module package.helper | 2 | ImportExpr | 0 | bottom | absolute | assistant |
| Module package.helper | 3 | ImportExpr | 0 | top | absolute | sys |
| Module package.helper | 10 | ImportExpr | 1 | bottom | relative | package |
| Module test_star | 1 | ImportExpr | 0 | bottom | absolute | package |

View File

@@ -0,0 +1,7 @@
import python
from ImportExpr ie, string m, string t, string r
where m = ie.getImportedModuleName() and
(if ie.isTop() then t = "top" else t = "bottom") and
(if ie.isRelative() then r= "relative" else r = "absolute")
select ie.getScope().toString(), ie.getLocation().getStartLine(), ie.toString(), ie.getLevel(), t, r, m

View File

@@ -0,0 +1,7 @@
import package
import helper
import package.assistant
#We expect that 'a' below will be 1 not a module.
from confused_elements import a
import sys

View File

@@ -0,0 +1,54 @@
| Module assistant | __name__ | str u'assistant' |
| Module assistant | e | int 5 |
| Module confused_elements | __name__ | str u'confused_elements' |
| Module confused_elements | a | int 1 |
| Module confused_elements.__init__ | __name__ | str u'confused_elements' |
| Module confused_elements.__init__ | a | int 1 |
| Module confused_elements.a | __name__ | str u'confused_elements.a' |
| Module confused_elements.a | b | int 1 |
| Module helper | CorrectIn3 | class CorrectIn3 |
| Module helper | Wrong | class Wrong |
| Module helper | __name__ | str u'helper' |
| Module helper | d | Wrong() |
| Module main | __name__ | str u'main' |
| Module main | a | int 1 |
| Module main | helper | Module helper |
| Module main | package | Module package |
| Module main | sys | Module sys |
| Module package | __name__ | str u'package' |
| Module package | a | int 1 |
| Module package | assistant | Module package.assistant |
| Module package | b | int 2 |
| Module package | c | int 3 |
| Module package | d | int 4 |
| Module package | f | int 1 |
| Module package | g | int 7 |
| Module package | helper | Module package.helper |
| Module package.__init__ | __name__ | str u'package' |
| Module package.__init__ | a | int 1 |
| Module package.__init__ | b | int 2 |
| Module package.__init__ | c | int 3 |
| Module package.__init__ | d | int 4 |
| Module package.__init__ | f | int 1 |
| Module package.__init__ | g | int 7 |
| Module package.__init__ | helper | Module package.helper |
| Module package.assistant | Wrong | class Wrong |
| Module package.assistant | __name__ | str u'package.assistant' |
| Module package.assistant | e | Wrong() |
| Module package.assistant | f | int 1 |
| Module package.helper | __name__ | str u'package.helper' |
| Module package.helper | absolute_import | _Feature() |
| Module package.helper | assistant | Module package.assistant |
| Module package.helper | d | int 4 |
| Module package.helper | e | int 5 |
| Module package.helper | g | int 7 |
| Module package.helper | sys | Module sys |
| Module test_star | __name__ | str u'test_star' |
| Module test_star | a | int 1 |
| Module test_star | assistant | Module package.assistant |
| Module test_star | b | int 2 |
| Module test_star | c | int 3 |
| Module test_star | d | int 4 |
| Module test_star | f | int 1 |
| Module test_star | g | int 7 |
| Module test_star | helper | Module package.helper |

View File

@@ -0,0 +1,6 @@
import python
from ModuleObject m, string name
where not m.isC() and not m.getName() = "__future__"
select m.toString(), name, m.getAttribute(name).toString()

View File

@@ -0,0 +1,14 @@
a = 1
b = 2
c = 3
#Explicit relative import
from .helper import d
#Explicit relative import
from .helper import g
from .assistant import f
from . import helper

View File

@@ -0,0 +1,7 @@
class Wrong(object):
pass
e = Wrong()
f = 1

View File

@@ -0,0 +1,10 @@
from __future__ import absolute_import
from assistant import e
import sys
d = 4
g = 7
from . import assistant

View File

@@ -0,0 +1 @@
from package import *

View File

@@ -0,0 +1 @@
semmle-extractor-options: --max-import-depth=3

View File

@@ -0,0 +1,58 @@
| Module test | __name__ | str u'test' |
| Module test | _private | int 1 |
| Module test | module2 | Module test_package.module2 |
| Module test | sys | Module sys |
| Module test | test_package | Module test_package |
| Module test_package | __name__ | str u'test_package' |
| Module test_package | a | int 1 |
| Module test_package | b | int 2 |
| Module test_package | c | int 3 |
| Module test_package | module1 | Module test_package.module1 |
| Module test_package | module2 | Module test_package.module2 |
| Module test_package | module3 | Module test_package.module3 |
| Module test_package | module4 | Module test_package.module4 |
| Module test_package | p | str u'p' |
| Module test_package | q | str u'q' |
| Module test_package | r | str u'r' |
| Module test_package | sys | Module sys |
| Module test_package.__init__ | __name__ | str u'test_package' |
| Module test_package.__init__ | a | int 1 |
| Module test_package.__init__ | b | int 2 |
| Module test_package.__init__ | c | int 3 |
| Module test_package.__init__ | p | str u'p' |
| Module test_package.__init__ | q | str u'q' |
| Module test_package.__init__ | r | str u'r' |
| Module test_package.__init__ | sys | Module sys |
| Module test_package.module1 | __all__ | List |
| Module test_package.module1 | __name__ | str u'test_package.module1' |
| Module test_package.module1 | a | int 1 |
| Module test_package.module1 | b | int 2 |
| Module test_package.module1 | c | int 3 |
| Module test_package.module1 | d | int 4 |
| Module test_package.module2 | __all__ | List |
| Module test_package.module2 | __name__ | str u'test_package.module2' |
| Module test_package.module2 | w | str u'w' |
| Module test_package.module2 | x | str u'x' |
| Module test_package.module2 | y | str u'y' |
| Module test_package.module2 | z | str u'z' |
| Module test_package.module3 | __name__ | str u'test_package.module3' |
| Module test_package.module3 | sys | Module sys |
| Module test_package.module4 | __all__ | List |
| Module test_package.module4 | __name__ | str u'test_package.module4' |
| Module test_package.module4 | p | str u'p' |
| Module test_package.module4 | q | str u'q' |
| Module test_package.module4 | r | str u'r' |
| Module test_package.module4 | s | str u's' |
| Module test_package.module5 | __name__ | str u'test_package.module5' |
| Module test_star | __name__ | str u'test_star' |
| Module test_star | a | int 1 |
| Module test_star | b | int 2 |
| Module test_star | c | int 3 |
| Module test_star | module1 | Module test_package.module1 |
| Module test_star | module2 | Module test_package.module2 |
| Module test_star | module3 | Module test_package.module3 |
| Module test_star | module4 | Module test_package.module4 |
| Module test_star | p | str u'p' |
| Module test_star | q | str u'q' |
| Module test_star | r | str u'r' |
| Module test_star | sys | Module sys |

View File

@@ -0,0 +1,5 @@
import python
from ModuleObject m, string name
where not m.isC()
select m.toString(), name, m.getAttribute(name).toString()

View File

@@ -0,0 +1,42 @@
| Module test | module2 |
| Module test | sys |
| Module test | test_package |
| Module test_package | a |
| Module test_package | b |
| Module test_package | c |
| Module test_package | module1 |
| Module test_package | module2 |
| Module test_package | module3 |
| Module test_package | module4 |
| Module test_package | p |
| Module test_package | q |
| Module test_package | r |
| Module test_package | sys |
| Module test_package.__init__ | a |
| Module test_package.__init__ | b |
| Module test_package.__init__ | c |
| Module test_package.__init__ | p |
| Module test_package.__init__ | q |
| Module test_package.__init__ | r |
| Module test_package.__init__ | sys |
| Module test_package.module1 | a |
| Module test_package.module1 | b |
| Module test_package.module1 | c |
| Module test_package.module2 | x |
| Module test_package.module2 | y |
| Module test_package.module2 | z |
| Module test_package.module3 | sys |
| Module test_package.module4 | p |
| Module test_package.module4 | q |
| Module test_package.module4 | r |
| Module test_star | a |
| Module test_star | b |
| Module test_star | c |
| Module test_star | module1 |
| Module test_star | module2 |
| Module test_star | module3 |
| Module test_star | module4 |
| Module test_star | p |
| Module test_star | q |
| Module test_star | r |
| Module test_star | sys |

View File

@@ -0,0 +1,5 @@
import python
from ModuleObject m, string name
where not m.isC() and m.exports(name)
select m.toString(), name

View File

@@ -0,0 +1,9 @@
| Module test | test |
| Module test_package | test_package |
| Module test_package.__init__ | test_package.__init__ |
| Module test_package.module1 | test_package.module1 |
| Module test_package.module2 | test_package.module2 |
| Module test_package.module3 | test_package.module3 |
| Module test_package.module4 | test_package.module4 |
| Module test_package.module5 | test_package.module5 |
| Module test_star | test_star |

View File

@@ -0,0 +1,5 @@
import python
from ModuleObject m, string name
where not m.isC() and m.importedAs(name)
select m.toString(), name

View File

@@ -0,0 +1 @@
semmle-extractor-options: --respect-init=true

View File

@@ -0,0 +1,31 @@
#Importing the package will execute its __init__.py module, filling in the namespace for the package.
import test_package
import sys
#These values now exist
test_package.a
test_package.b
test_package.c
#But this does not...
#test_package.d
#This doesn't exist either
#test_package.module2
#We can't do this as d is not a module
#from test_package import d
#When we do this test_package.module2 becomes defined
from test_package import module2
#Now these are defined
test_package.module2
module2
import test_package.module3
#Now this are defined
test_package.module3
_private = 1

View File

@@ -0,0 +1,3 @@
from .module1 import *
from .module4 import *
import sys

View File

@@ -0,0 +1,6 @@
__all__ = [ 'a', 'b', 'c' ]
a = 1
b = 2
c = 3
d = 4

View File

@@ -0,0 +1,6 @@
__all__ = [ 'x', 'y', 'z']
w = 'w'
x = 'x'
y = 'y'
z = 'z'

View File

@@ -0,0 +1 @@
import sys

View File

@@ -0,0 +1,6 @@
__all__ = [ 'p', 'q', 'r']
p = 'p'
q = 'q'
r = 'r'
s = 's'

View File

@@ -0,0 +1,3 @@
#Importing the package will execute its __init__.py module, filling in the namespace for the package.
from test_package import *

View File

@@ -0,0 +1 @@
automatic_locations: true

View File

@@ -0,0 +1,2 @@
semmle-extractor-options: --max-import-depth=3
optimize: true

View File

@@ -0,0 +1,3 @@
| six | Module six |
| six.moves | Module six.moves |
| six.moves.range | builtin-class range |

View File

@@ -0,0 +1,16 @@
import python
string longname(Expr e) {
result = e.(Name).getId()
or
exists(Attribute a |
a = e |
result = longname(a.getObject()) + "." + a.getName()
)
}
from Expr e, Object o
where e.refersTo(o) and e.getLocation().getFile().getShortName() = "test.py"
select longname(e), o.toString()

View File

@@ -0,0 +1,256 @@
| Module six | BytesIO | builtin-class _io.BytesIO |
| Module six | Iterator | builtin-class object |
| Module six | MAXSIZE | int 9223372036854775807 |
| Module six | PY2 | bool False |
| Module six | PY3 | bool True |
| Module six | StringIO | builtin-class _io.StringIO |
| Module six | __author__ | str u'Benjamin Peterson <benjamin@python.org>' |
| Module six | __name__ | str u'six' |
| Module six | __version__ | str u'1.5.2' |
| Module six | _add_doc | Function _add_doc |
| Module six | _func_closure | str u'__closure__' |
| Module six | _func_code | str u'__code__' |
| Module six | _func_defaults | str u'__defaults__' |
| Module six | _func_globals | str u'__globals__' |
| Module six | _import_module | Function _import_module |
| Module six | _iteritems | str u'items' |
| Module six | _iterkeys | str u'keys' |
| Module six | _iterlists | str u'lists' |
| Module six | _itervalues | str u'values' |
| Module six | _meth_func | str u'__func__' |
| Module six | _meth_self | str u'__self__' |
| Module six | add_metaclass | Function add_metaclass |
| Module six | add_move | Function add_move |
| Module six | advance_iterator | Builtin-function next |
| Module six | b | Function b |
| Module six | binary_type | builtin-class bytes |
| Module six | byte2int | Function byte2int |
| Module six | callable | Builtin-function callable |
| Module six | callable | Function callable |
| Module six | class_types | Tuple |
| Module six | get_function_closure | Attribute() |
| Module six | get_function_code | Attribute() |
| Module six | get_function_defaults | Attribute() |
| Module six | get_function_globals | Attribute() |
| Module six | get_method_function | Attribute() |
| Module six | get_method_self | Attribute() |
| Module six | get_unbound_function | Function get_unbound_function |
| Module six | indexbytes | Builtin-function getitem |
| Module six | int2byte | Function int2byte |
| Module six | integer_types | Tuple |
| Module six | io | Module io |
| Module six | iterbytes | Builtin-function iter |
| Module six | iteritems | Function iteritems |
| Module six | iterkeys | Function iterkeys |
| Module six | iterlists | Function iterlists |
| Module six | itervalues | Function itervalues |
| Module six | moves | Module six.moves |
| Module six | next | Builtin-function next |
| Module six | operator | Module operator |
| Module six | remove_move | Function remove_move |
| Module six | reraise | Function reraise |
| Module six | string_types | Tuple |
| Module six | sys | Module sys |
| Module six | text_type | builtin-class str |
| Module six | types | Module types |
| Module six | u | Function u |
| Module six | unichr | Builtin-function chr |
| Module six | with_metaclass | Function with_metaclass |
| Module six.__init__ | BytesIO | builtin-class _io.BytesIO |
| Module six.__init__ | Iterator | builtin-class object |
| Module six.__init__ | MAXSIZE | int 9223372036854775807 |
| Module six.__init__ | PY2 | bool False |
| Module six.__init__ | PY3 | bool True |
| Module six.__init__ | StringIO | builtin-class _io.StringIO |
| Module six.__init__ | __author__ | str u'Benjamin Peterson <benjamin@python.org>' |
| Module six.__init__ | __name__ | str u'six' |
| Module six.__init__ | __version__ | str u'1.5.2' |
| Module six.__init__ | _add_doc | Function _add_doc |
| Module six.__init__ | _func_closure | str u'__closure__' |
| Module six.__init__ | _func_code | str u'__code__' |
| Module six.__init__ | _func_defaults | str u'__defaults__' |
| Module six.__init__ | _func_globals | str u'__globals__' |
| Module six.__init__ | _import_module | Function _import_module |
| Module six.__init__ | _iteritems | str u'items' |
| Module six.__init__ | _iterkeys | str u'keys' |
| Module six.__init__ | _iterlists | str u'lists' |
| Module six.__init__ | _itervalues | str u'values' |
| Module six.__init__ | _meth_func | str u'__func__' |
| Module six.__init__ | _meth_self | str u'__self__' |
| Module six.__init__ | add_metaclass | Function add_metaclass |
| Module six.__init__ | add_move | Function add_move |
| Module six.__init__ | advance_iterator | Builtin-function next |
| Module six.__init__ | b | Function b |
| Module six.__init__ | binary_type | builtin-class bytes |
| Module six.__init__ | byte2int | Function byte2int |
| Module six.__init__ | callable | Builtin-function callable |
| Module six.__init__ | callable | Function callable |
| Module six.__init__ | class_types | Tuple |
| Module six.__init__ | get_function_closure | Attribute() |
| Module six.__init__ | get_function_code | Attribute() |
| Module six.__init__ | get_function_defaults | Attribute() |
| Module six.__init__ | get_function_globals | Attribute() |
| Module six.__init__ | get_method_function | Attribute() |
| Module six.__init__ | get_method_self | Attribute() |
| Module six.__init__ | get_unbound_function | Function get_unbound_function |
| Module six.__init__ | indexbytes | Builtin-function getitem |
| Module six.__init__ | int2byte | Function int2byte |
| Module six.__init__ | integer_types | Tuple |
| Module six.__init__ | io | Module io |
| Module six.__init__ | iterbytes | Builtin-function iter |
| Module six.__init__ | iteritems | Function iteritems |
| Module six.__init__ | iterkeys | Function iterkeys |
| Module six.__init__ | iterlists | Function iterlists |
| Module six.__init__ | itervalues | Function itervalues |
| Module six.__init__ | moves | Module six.moves |
| Module six.__init__ | next | Builtin-function next |
| Module six.__init__ | operator | Module operator |
| Module six.__init__ | remove_move | Function remove_move |
| Module six.__init__ | reraise | Function reraise |
| Module six.__init__ | string_types | Tuple |
| Module six.__init__ | sys | Module sys |
| Module six.__init__ | text_type | builtin-class str |
| Module six.__init__ | types | Module types |
| Module six.__init__ | u | Function u |
| Module six.__init__ | unichr | Builtin-function chr |
| Module six.__init__ | with_metaclass | Function with_metaclass |
| Module six.moves | BaseHTTPServer | Module http.server |
| Module six.moves | CGIHTTPServer | Module http.server |
| Module six.moves | PY2 | bool False |
| Module six.moves | PY3 | bool True |
| Module six.moves | SimpleHTTPServer | Module http.server |
| Module six.moves | StringIO | builtin-class _io.StringIO |
| Module six.moves | __name__ | str u'six.moves' |
| Module six.moves | _thread | Module _thread |
| Module six.moves | builtins | Module builtins |
| Module six.moves | cPickle | Module pickle |
| Module six.moves | cStringIO | builtin-class _io.StringIO |
| Module six.moves | configparser | Module configparser |
| Module six.moves | copyreg | Module copyreg |
| Module six.moves | dbm_gnu | Module dbm.gnu |
| Module six.moves | email_mime_base | Module email.mime.base |
| Module six.moves | email_mime_multipart | Module email.mime.multipart |
| Module six.moves | email_mime_text | Module email.mime.text |
| Module six.moves | filter | builtin-class filter |
| Module six.moves | filterfalse | builtin-class itertools.filterfalse |
| Module six.moves | html_entities | Module html.entities |
| Module six.moves | html_parser | Module html.parser |
| Module six.moves | http_client | Module http.client |
| Module six.moves | http_cookiejar | Module http.cookiejar |
| Module six.moves | http_cookies | Module http.cookies |
| Module six.moves | input | Builtin-function input |
| Module six.moves | map | builtin-class map |
| Module six.moves | queue | Module queue |
| Module six.moves | range | builtin-class range |
| Module six.moves | reload_module | Function reload |
| Module six.moves | reprlib | Module reprlib |
| Module six.moves | socketserver | Module socketserver |
| Module six.moves | tkinter | Module tkinter |
| Module six.moves | tkinter_colorchooser | Module tkinter.colorchooser |
| Module six.moves | tkinter_commondialog | Module tkinter.commondialog |
| Module six.moves | tkinter_constants | Module tkinter.constants |
| Module six.moves | tkinter_dialog | Module tkinter.dialog |
| Module six.moves | tkinter_dnd | Module tkinter.dnd |
| Module six.moves | tkinter_filedialog | Module tkinter.filedialog |
| Module six.moves | tkinter_font | Module tkinter.font |
| Module six.moves | tkinter_messagebox | Module tkinter.messagebox |
| Module six.moves | tkinter_scrolledtext | Module tkinter.scrolledtext |
| Module six.moves | tkinter_simpledialog | Module tkinter.simpledialog |
| Module six.moves | tkinter_tix | Module tkinter.tix |
| Module six.moves | tkinter_tkfiledialog | Module tkinter.filedialog |
| Module six.moves | tkinter_tksimpledialog | Module tkinter.simpledialog |
| Module six.moves | tkinter_ttk | Module tkinter.ttk |
| Module six.moves | urllib | Module six.moves.urllib |
| Module six.moves | urllib_error | Module six.moves.urllib_error |
| Module six.moves | urllib_parse | Module six.moves.urllib_parse |
| Module six.moves | urllib_request | Module six.moves.urllib_request |
| Module six.moves | urllib_response | Module six.moves.urllib_response |
| Module six.moves | urllib_robotparser | Module six.moves.urllib_robotparser |
| Module six.moves | xmlrpc_client | Module xmlrpc.client |
| Module six.moves | xrange | builtin-class range |
| Module six.moves | zip | builtin-class zip |
| Module six.moves | zip_longest | builtin-class itertools.zip_longest |
| Module six.moves.__init__ | BaseHTTPServer | Module http.server |
| Module six.moves.__init__ | CGIHTTPServer | Module http.server |
| Module six.moves.__init__ | PY2 | bool False |
| Module six.moves.__init__ | PY3 | bool True |
| Module six.moves.__init__ | SimpleHTTPServer | Module http.server |
| Module six.moves.__init__ | StringIO | builtin-class _io.StringIO |
| Module six.moves.__init__ | __name__ | str u'six.moves' |
| Module six.moves.__init__ | _thread | Module _thread |
| Module six.moves.__init__ | builtins | Module builtins |
| Module six.moves.__init__ | cPickle | Module pickle |
| Module six.moves.__init__ | cStringIO | builtin-class _io.StringIO |
| Module six.moves.__init__ | configparser | Module configparser |
| Module six.moves.__init__ | copyreg | Module copyreg |
| Module six.moves.__init__ | dbm_gnu | Module dbm.gnu |
| Module six.moves.__init__ | email_mime_base | Module email.mime.base |
| Module six.moves.__init__ | email_mime_multipart | Module email.mime.multipart |
| Module six.moves.__init__ | email_mime_text | Module email.mime.text |
| Module six.moves.__init__ | filter | builtin-class filter |
| Module six.moves.__init__ | filterfalse | builtin-class itertools.filterfalse |
| Module six.moves.__init__ | html_entities | Module html.entities |
| Module six.moves.__init__ | html_parser | Module html.parser |
| Module six.moves.__init__ | http_client | Module http.client |
| Module six.moves.__init__ | http_cookiejar | Module http.cookiejar |
| Module six.moves.__init__ | http_cookies | Module http.cookies |
| Module six.moves.__init__ | input | Builtin-function input |
| Module six.moves.__init__ | map | builtin-class map |
| Module six.moves.__init__ | queue | Module queue |
| Module six.moves.__init__ | range | builtin-class range |
| Module six.moves.__init__ | reload_module | Function reload |
| Module six.moves.__init__ | reprlib | Module reprlib |
| Module six.moves.__init__ | socketserver | Module socketserver |
| Module six.moves.__init__ | tkinter | Module tkinter |
| Module six.moves.__init__ | tkinter_colorchooser | Module tkinter.colorchooser |
| Module six.moves.__init__ | tkinter_commondialog | Module tkinter.commondialog |
| Module six.moves.__init__ | tkinter_constants | Module tkinter.constants |
| Module six.moves.__init__ | tkinter_dialog | Module tkinter.dialog |
| Module six.moves.__init__ | tkinter_dnd | Module tkinter.dnd |
| Module six.moves.__init__ | tkinter_filedialog | Module tkinter.filedialog |
| Module six.moves.__init__ | tkinter_font | Module tkinter.font |
| Module six.moves.__init__ | tkinter_messagebox | Module tkinter.messagebox |
| Module six.moves.__init__ | tkinter_scrolledtext | Module tkinter.scrolledtext |
| Module six.moves.__init__ | tkinter_simpledialog | Module tkinter.simpledialog |
| Module six.moves.__init__ | tkinter_tix | Module tkinter.tix |
| Module six.moves.__init__ | tkinter_tkfiledialog | Module tkinter.filedialog |
| Module six.moves.__init__ | tkinter_tksimpledialog | Module tkinter.simpledialog |
| Module six.moves.__init__ | tkinter_ttk | Module tkinter.ttk |
| Module six.moves.__init__ | urllib | Module six.moves.urllib |
| Module six.moves.__init__ | urllib_error | Module six.moves.urllib_error |
| Module six.moves.__init__ | urllib_parse | Module six.moves.urllib_parse |
| Module six.moves.__init__ | urllib_request | Module six.moves.urllib_request |
| Module six.moves.__init__ | urllib_response | Module six.moves.urllib_response |
| Module six.moves.__init__ | urllib_robotparser | Module six.moves.urllib_robotparser |
| Module six.moves.__init__ | xmlrpc_client | Module xmlrpc.client |
| Module six.moves.__init__ | xrange | builtin-class range |
| Module six.moves.__init__ | zip | builtin-class zip |
| Module six.moves.__init__ | zip_longest | builtin-class itertools.zip_longest |
| Module six.moves.urllib | __name__ | str u'six.moves.urllib' |
| Module six.moves.urllib | error | Module six.moves.urllib_error |
| Module six.moves.urllib | parse | Module six.moves.urllib_parse |
| Module six.moves.urllib | request | Module six.moves.urllib_request |
| Module six.moves.urllib | response | Module six.moves.urllib_response |
| Module six.moves.urllib | robotparser | Module six.moves.urllib_robotparser |
| Module six.moves.urllib.__init__ | __name__ | str u'six.moves.urllib' |
| Module six.moves.urllib.__init__ | error | Module six.moves.urllib_error |
| Module six.moves.urllib.__init__ | parse | Module six.moves.urllib_parse |
| Module six.moves.urllib.__init__ | request | Module six.moves.urllib_request |
| Module six.moves.urllib.__init__ | response | Module six.moves.urllib_response |
| Module six.moves.urllib.__init__ | robotparser | Module six.moves.urllib_robotparser |
| Module six.moves.urllib_error | PY2 | bool False |
| Module six.moves.urllib_error | PY3 | bool True |
| Module six.moves.urllib_error | __name__ | str u'six.moves.urllib_error' |
| Module six.moves.urllib_parse | PY2 | bool False |
| Module six.moves.urllib_parse | PY3 | bool True |
| Module six.moves.urllib_parse | __name__ | str u'six.moves.urllib_parse' |
| Module six.moves.urllib_request | PY2 | bool False |
| Module six.moves.urllib_request | PY3 | bool True |
| Module six.moves.urllib_request | __name__ | str u'six.moves.urllib_request' |
| Module six.moves.urllib_response | PY2 | bool False |
| Module six.moves.urllib_response | PY3 | bool True |
| Module six.moves.urllib_response | __name__ | str u'six.moves.urllib_response' |
| Module six.moves.urllib_robotparser | PY2 | bool False |
| Module six.moves.urllib_robotparser | PY3 | bool True |
| Module six.moves.urllib_robotparser | RobotFileParser | class RobotFileParser |
| Module six.moves.urllib_robotparser | __name__ | str u'six.moves.urllib_robotparser' |

View File

@@ -0,0 +1,5 @@
import six
#Check that some expected attributes are visible
six.moves
six.moves.range

View File

@@ -0,0 +1,11 @@
import python
predicate six(ModuleObject m) {
m.getName() = "six"
or
six(m.getPackage())
}
from ModuleObject mod, string name, Object obj
where mod.attributeRefersTo(name, obj, _) and six(mod)
select mod.toString(), name, obj.toString()

View File

@@ -0,0 +1,6 @@
class MyList(list):
pass
class MyDict(dict):
pass

View File

@@ -0,0 +1,67 @@
from mutual_inheritance import C, H, N, T
#Good newstyle (in Python2) classes
class W(object):
pass
class X(W):
pass
class Y(X):
pass
class Z(Y, X):
pass
#Good oldstyle (in Python2) classes
class O1:
pass
class O2(O1):
pass
class O3(O1):
pass
class O4(O2, O3):
pass
#Bad classes -- Illegal and designed to break MRO computation
class A(A):
pass
#Two way cycle
class B(C):
pass
class D(object, object, object, object, object, object, object, object):
pass
class E(D, D, D, D, D, D, D, D, D, D, D):
pass
#Two way cycle with object
class G(H, object):
pass
class J(J, object):
pass # Not a cycle as J is undefined when used as a base.
#Three way cycle
class M(N):
pass
class L(M):
pass
#Three way cycle with object
class S(T, object):
pass
class R(S, object):
pass

View File

@@ -0,0 +1,23 @@
| class MyDict | builtin-class dict | builtin-class object |
| class MyDict | class MyDict | builtin-class dict |
| class MyList | builtin-class list | builtin-class object |
| class MyList | class MyList | builtin-class list |
| class O1 | class O1 | builtin-class object |
| class O2 | class O1 | builtin-class object |
| class O2 | class O2 | class O1 |
| class O3 | class O1 | builtin-class object |
| class O3 | class O3 | class O1 |
| class O4 | class O1 | builtin-class object |
| class O4 | class O2 | class O3 |
| class O4 | class O3 | class O1 |
| class O4 | class O4 | class O2 |
| class W | class W | builtin-class object |
| class X | class W | builtin-class object |
| class X | class X | class W |
| class Y | class W | builtin-class object |
| class Y | class X | class W |
| class Y | class Y | class X |
| class Z | class W | builtin-class object |
| class Z | class X | class W |
| class Z | class Y | class X |
| class Z | class Z | class Y |

View File

@@ -0,0 +1,7 @@
import python
from ClassObject cls, ClassObject sup
where not cls.isC()
select cls.toString(), sup.toString(), cls.nextInMro(sup).toString()

Some files were not shown because too many files have changed in this diff Show More