Merge pull request #1636 from markshannon/python-api-odds-and-ends

Python: Assorted improvements to API.
This commit is contained in:
Rebecca Valentine
2019-08-07 09:50:44 -07:00
committed by GitHub
13 changed files with 414 additions and 15 deletions

View File

@@ -0,0 +1,5 @@
| file://:0:0:0:0 | builtin-class bool | bool |
| file://:0:0:0:0 | builtin-class classmethod | classmethod |
| file://:0:0:0:0 | builtin-class float | float |
| file://:0:0:0:0 | builtin-class int | int |
| file://:0:0:0:0 | builtin-class object | object |

View File

@@ -0,0 +1,15 @@
import python
from ClassValue cls, string description
where
cls = ClassValue::bool() and description = "bool"
or
cls = ClassValue::int_() and description = "int"
or
cls = ClassValue::float_() and description = "float"
or
cls = ClassValue::classmethod() and description = "classmethod"
or
cls = ClassValue::bool().getMro().getItem(2) and description = "object"
select cls, description

View File

@@ -0,0 +1,16 @@
| 1 | file://:0:0:0:0 | int 1 |
| 2 | file://:0:0:0:0 | int 2 |
| 3 | file://:0:0:0:0 | int 3 |
| 4 | file://:0:0:0:0 | int 4 |
| 5 | file://:0:0:0:0 | int 5 |
| 6 | file://:0:0:0:0 | int 6 |
| 7 | file://:0:0:0:0 | int 7 |
| 8 | file://:0:0:0:0 | int 8 |
| 9 | file://:0:0:0:0 | int 9 |
| 10 | file://:0:0:0:0 | int 10 |
| 1000 | file://:0:0:0:0 | int 1000 |
| 1004 | file://:0:0:0:0 | int 1004 |
| b'b' | file://:0:0:0:0 | 'b' |
| b'd' | file://:0:0:0:0 | 'd' |
| u'a' | file://:0:0:0:0 | 'a' |
| u'c' | file://:0:0:0:0 | 'c' |

View File

@@ -0,0 +1,20 @@
import python
from string txt, Value val
where
exists(string s |
txt = "u'" + s + "'" and val = Value::forUnicode(s)
or
txt = "b'" + s + "'" and val = Value::forBytes(s)
|
s = "a" or s = "b" or s = "c" or s = "d"
)
or
exists(int i |
txt = i.toString() and val = Value::forInt(i)
|
i in [1..10] or i in [1000..1010]
)
select txt, val

View File

@@ -0,0 +1,5 @@
| file://:0:0:0:0 | Builtin-function exit | exit |
| file://:0:0:0:0 | Builtin-function len | len |
| file://:0:0:0:0 | builtin method append | list.append |
| test.py:8:1:8:10 | Function foo | foo |
| test.py:13:5:13:19 | Function C.meth | C.meth |

View File

@@ -0,0 +1,16 @@
import python
from FunctionValue v, string name
where name = v.getQualifiedName() and
(
v = Value::named("len")
or
v instanceof PythonFunctionValue
or
v = Value::named("sys.exit")
or
v = Value::named("list").(ClassValue).lookup("append")
)
select v, name

View File

@@ -0,0 +1,4 @@
| file://:0:0:0:0 | builtin-class ValueError | ValueError |
| file://:0:0:0:0 | builtin-class bool | bool |
| file://:0:0:0:0 | builtin-class slice | slice |
| file://:0:0:0:0 | list object | sys.argv |

View File

@@ -0,0 +1,12 @@
import python
from Value val, string name
where
val = Value::named(name)
and
(
name = "bool" or name = "sys" or name = "sys.argv" or
name = "ValueError" or name = "slice"
)
select val, name

View File

@@ -0,0 +1,14 @@
u"a"
b"b"
u"c"
b"d"
1000
1004
def foo():
pass
class C(object):
def meth(self):
pass