| 1 |
[case testIsinstanceInt] |
| 2 |
def is_int(value: object) -> bool: |
| 3 |
return isinstance(value, int) |
| 4 |
|
| 5 |
[out] |
| 6 |
def is_int(value): |
| 7 |
value :: object |
| 8 |
r0 :: bit |
| 9 |
L0: |
| 10 |
r0 = PyLong_Check(value) |
| 11 |
return r0 |
| 12 |
|
| 13 |
[case testIsinstanceNotBool1] |
| 14 |
def is_not_bool(value: object) -> bool: |
| 15 |
return not isinstance(value, bool) |
| 16 |
|
| 17 |
[out] |
| 18 |
def is_not_bool(value): |
| 19 |
value :: object |
| 20 |
r0, r1 :: bit |
| 21 |
L0: |
| 22 |
r0 = PyBool_Check(value) |
| 23 |
r1 = r0 ^ 1 |
| 24 |
return r1 |
| 25 |
|
| 26 |
[case testIsinstanceIntAndNotBool] |
| 27 |
# This test is to ensure that 'value' doesn't get coerced to int when we are |
| 28 |
# checking if it's a bool, since an int can never be an instance of a bool |
| 29 |
def is_not_bool_and_is_int(value: object) -> bool: |
| 30 |
return isinstance(value, int) and not isinstance(value, bool) |
| 31 |
|
| 32 |
[out] |
| 33 |
def is_not_bool_and_is_int(value): |
| 34 |
value :: object |
| 35 |
r0 :: bit |
| 36 |
r1 :: bool |
| 37 |
r2, r3 :: bit |
| 38 |
L0: |
| 39 |
r0 = PyLong_Check(value) |
| 40 |
if r0 goto L2 else goto L1 :: bool |
| 41 |
L1: |
| 42 |
r1 = r0 |
| 43 |
goto L3 |
| 44 |
L2: |
| 45 |
r2 = PyBool_Check(value) |
| 46 |
r3 = r2 ^ 1 |
| 47 |
r1 = r3 |
| 48 |
L3: |
| 49 |
return r1 |
| 50 |
|
| 51 |
[case testBorrowSpecialCaseWithIsinstance] |
| 52 |
class C: |
| 53 |
s: str |
| 54 |
|
| 55 |
def g() -> object: |
| 56 |
pass |
| 57 |
|
| 58 |
def f() -> None: |
| 59 |
x = g() |
| 60 |
if isinstance(x, C): |
| 61 |
x.s |
| 62 |
[out] |
| 63 |
def g(): |
| 64 |
r0 :: object |
| 65 |
L0: |
| 66 |
r0 = box(None, 1) |
| 67 |
return r0 |
| 68 |
def f(): |
| 69 |
r0, x, r1 :: object |
| 70 |
r2 :: ptr |
| 71 |
r3 :: object |
| 72 |
r4 :: bit |
| 73 |
r5 :: __main__.C |
| 74 |
r6 :: str |
| 75 |
L0: |
| 76 |
r0 = g() |
| 77 |
x = r0 |
| 78 |
r1 = __main__.C :: type |
| 79 |
r2 = get_element_ptr x ob_type :: PyObject |
| 80 |
r3 = borrow load_mem r2 :: builtins.object* |
| 81 |
keep_alive x |
| 82 |
r4 = r3 == r1 |
| 83 |
if r4 goto L1 else goto L2 :: bool |
| 84 |
L1: |
| 85 |
r5 = borrow cast(__main__.C, x) |
| 86 |
r6 = r5.s |
| 87 |
keep_alive x |
| 88 |
L2: |
| 89 |
return 1 |
| 90 |
|
| 91 |
[case testBytes] |
| 92 |
from typing import Any |
| 93 |
|
| 94 |
def is_bytes(x: Any) -> bool: |
| 95 |
return isinstance(x, bytes) |
| 96 |
|
| 97 |
def is_bytearray(x: Any) -> bool: |
| 98 |
return isinstance(x, bytearray) |
| 99 |
|
| 100 |
[out] |
| 101 |
def is_bytes(x): |
| 102 |
x :: object |
| 103 |
r0 :: bit |
| 104 |
L0: |
| 105 |
r0 = PyBytes_Check(x) |
| 106 |
return r0 |
| 107 |
def is_bytearray(x): |
| 108 |
x :: object |
| 109 |
r0 :: bit |
| 110 |
L0: |
| 111 |
r0 = PyByteArray_Check(x) |
| 112 |
return r0 |
| 113 |
|
| 114 |
[case testDict] |
| 115 |
from typing import Any |
| 116 |
|
| 117 |
def is_dict(x: Any) -> bool: |
| 118 |
return isinstance(x, dict) |
| 119 |
|
| 120 |
[out] |
| 121 |
def is_dict(x): |
| 122 |
x :: object |
| 123 |
r0 :: bit |
| 124 |
L0: |
| 125 |
r0 = PyDict_Check(x) |
| 126 |
return r0 |
| 127 |
|
| 128 |
[case testFloat] |
| 129 |
from typing import Any |
| 130 |
|
| 131 |
def is_float(x: Any) -> bool: |
| 132 |
return isinstance(x, float) |
| 133 |
|
| 134 |
[out] |
| 135 |
def is_float(x): |
| 136 |
x :: object |
| 137 |
r0 :: bit |
| 138 |
L0: |
| 139 |
r0 = PyFloat_Check(x) |
| 140 |
return r0 |
| 141 |
|
| 142 |
[case testSet] |
| 143 |
from typing import Any |
| 144 |
|
| 145 |
def is_set(x: Any) -> bool: |
| 146 |
return isinstance(x, set) |
| 147 |
|
| 148 |
def is_frozenset(x: Any) -> bool: |
| 149 |
return isinstance(x, frozenset) |
| 150 |
|
| 151 |
[out] |
| 152 |
def is_set(x): |
| 153 |
x :: object |
| 154 |
r0 :: bit |
| 155 |
L0: |
| 156 |
r0 = PySet_Check(x) |
| 157 |
return r0 |
| 158 |
def is_frozenset(x): |
| 159 |
x :: object |
| 160 |
r0 :: bit |
| 161 |
L0: |
| 162 |
r0 = PyFrozenSet_Check(x) |
| 163 |
return r0 |
| 164 |
|
| 165 |
[case testStr] |
| 166 |
from typing import Any |
| 167 |
|
| 168 |
def is_str(x: Any) -> bool: |
| 169 |
return isinstance(x, str) |
| 170 |
|
| 171 |
[out] |
| 172 |
def is_str(x): |
| 173 |
x :: object |
| 174 |
r0 :: bit |
| 175 |
L0: |
| 176 |
r0 = PyUnicode_Check(x) |
| 177 |
return r0 |
| 178 |
|
| 179 |
[case testTuple] |
| 180 |
from typing import Any |
| 181 |
|
| 182 |
def is_tuple(x: Any) -> bool: |
| 183 |
return isinstance(x, tuple) |
| 184 |
|
| 185 |
[out] |
| 186 |
def is_tuple(x): |
| 187 |
x :: object |
| 188 |
r0 :: bit |
| 189 |
L0: |
| 190 |
r0 = PyTuple_Check(x) |
| 191 |
return r0 |
| 192 |
|
| 193 |
[case testTupleOfPrimitives] |
| 194 |
from typing import Any |
| 195 |
|
| 196 |
def is_instance(x: Any) -> bool: |
| 197 |
return isinstance(x, (str, int, bytes)) |
| 198 |
|
| 199 |
[out] |
| 200 |
def is_instance(x): |
| 201 |
x :: object |
| 202 |
r0, r1, r2 :: bit |
| 203 |
r3 :: bool |
| 204 |
L0: |
| 205 |
r0 = PyUnicode_Check(x) |
| 206 |
if r0 goto L3 else goto L1 :: bool |
| 207 |
L1: |
| 208 |
r1 = PyLong_Check(x) |
| 209 |
if r1 goto L3 else goto L2 :: bool |
| 210 |
L2: |
| 211 |
r2 = PyBytes_Check(x) |
| 212 |
if r2 goto L3 else goto L4 :: bool |
| 213 |
L3: |
| 214 |
r3 = 1 |
| 215 |
goto L5 |
| 216 |
L4: |
| 217 |
r3 = 0 |
| 218 |
L5: |
| 219 |
return r3 |