1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
|
"""
Checking for ``list.append`` and all the other possible array modifications.
"""
# -----------------
# list.append
# -----------------
arr = []
for a in [1,2]:
arr.append(a);
arr.append # should not cause an exception
arr.append() # should not cause an exception
#? int()
arr[10]
arr = [tuple()]
for a in [1,2]:
arr.append(a);
#? int() tuple()
arr[10]
#? int()
arr[10].index()
arr = list([])
arr.append(1)
#? int()
arr[0]
# -----------------
# list.insert
# -----------------
arr = [""]
arr.insert(0, 1.0)
# on exception due to this, please!
arr.insert(0)
arr.insert()
#? float() str()
arr[10]
for a in arr:
#? float() str()
a
#? float() str()
list(arr)[10]
# -----------------
# list.extend / set.update
# -----------------
arr = [1.0]
arr.extend([1,2,3])
arr.extend([])
arr.extend("")
arr.extend(list) # should ignore
#? float() int() str()
arr[100]
a = set(arr)
a.update(list(["", 1]))
#? float() int() str()
list(a)[0]
# -----------------
# set/list initialized as functions
# -----------------
st = set()
st.add(1)
#? int()
for s in st: s
lst = list()
lst.append(1)
#? int()
for i in lst: i
# -----------------
# renames / type changes
# -----------------
arr = []
arr2 = arr
arr2.append('')
#? str()
arr2[0]
lst = [1]
lst.append(1.0)
s = set(lst)
s.add("ahh")
lst = list(s)
lst.append({})
#? dict() int() float() str()
lst[0]
# should work with tuple conversion, too.
#? dict() int() float() str()
tuple(lst)[0]
# but not with an iterator
#?
iter(lst)[0]
# -----------------
# complex including +=
# -----------------
class C(): pass
class D(): pass
class E(): pass
lst = [1]
lst.append(1.0)
lst += [C()]
s = set(lst)
s.add("")
s += [D()]
lst = list(s)
lst.append({})
lst += [E()]
#? dict() int() float() str() C() D() E()
lst[0]
# -----------------
# functions
# -----------------
def arr_append(arr4, a):
arr4.append(a)
def add_to_arr(arr2, a):
arr2.append(a)
return arr2
def app(a):
arr3.append(a)
arr3 = [1.0]
res = add_to_arr(arr3, 1)
arr_append(arr3, 'str')
app(set())
#? float() str() int() set()
arr3[10]
#? float() str() int() set()
res[10]
# -----------------
# returns, special because the module dicts are not correct here.
# -----------------
def blub():
a = []
a.append(1.0)
#? float()
a[0]
return a
#? float()
blub()[0]
# list with default
def blub():
a = list([1])
a.append(1.0)
return a
#? int() float()
blub()[0]
# empty list
def blub():
a = list()
a.append(1.0)
return a
#? float()
blub()[0]
# with if
def blub():
if 1:
a = []
a.append(1.0)
return a
#? float()
blub()[0]
# with else clause
def blub():
if random.choice([0, 1]):
1
else:
a = []
a.append(1)
return a
#? int()
blub()[0]
# -----------------
# returns, the same for classes
# -----------------
class C():
def blub(self, b):
if 1:
a = []
a.append(b)
return a
def blub2(self):
""" mapper function """
a = self.blub(1.0)
#? float()
a[0]
return a
def literal_arr(self, el):
self.a = []
self.a.append(el)
#? int()
self.a[0]
return self.a
def list_arr(self, el):
self.b = list([])
self.b.append(el)
#? float()
self.b[0]
return self.b
#? int()
C().blub(1)[0]
#? float()
C().blub2(1)[0]
#? int()
C().a[0]
#? int()
C().literal_arr(1)[0]
#? float()
C().b[0]
#? float()
C().list_arr(1.0)[0]
# -----------------
# array recursions
# -----------------
a = set([1.0])
a.update(a)
a.update([1])
#? float() int()
list(a)[0]
def first(a):
b = []
b.append(a)
b.extend(second(a))
return list(b)
def second(a):
b = []
b.extend(first(a))
return list(b)
#? float()
first(1.0)[0]
def third():
b = []
b.extend
extend()
b.extend(first())
return list(b)
#?
third()[0]
# -----------------
# set.add
# -----------------
st = {1.0}
for a in [1,2]:
st.add(a)
st.append('') # lists should not have an influence
st.add # should not cause an exception
st.add()
st = {1.0}
st.add(1)
lst = list(st)
lst.append('')
#? float() int() str()
lst[0]
# -----------------
# list setitem
# -----------------
some_lst = [int]
some_lst[3] = str
#? int
some_lst[0]
#? str
some_lst[3]
#? int str
some_lst[2]
some_lst[0] = tuple
#? tuple
some_lst[0]
#? int str tuple
some_lst[1]
some_lst2 = list([1])
some_lst2[3] = ''
#? int() str()
some_lst2[0]
#? str()
some_lst2[3]
#? int() str()
some_lst2[2]
some_lst3 = []
some_lst3[0] = 3
some_lst3[:] = '' # Is ignored for now.
#? int()
some_lst3[0]
# -----------------
# set setitem/other modifications (should not work)
# -----------------
some_set = {int}
some_set[3] = str
#? int
some_set[0]
#? int
some_set[3]
something = object()
something[3] = str
#?
something[0]
#?
something[3]
# -----------------
# dict setitem
# -----------------
some_dct = {'a': float, 1: int}
some_dct['x'] = list
some_dct['y'] = tuple
#? list
some_dct['x']
#? int float list tuple
some_dct['unknown']
#? float
some_dct['a']
some_dct = dict({'a': 1, 1: ''})
#? int() str()
some_dct['la']
#? int()
some_dct['a']
some_dct['x'] = list
some_dct['y'] = tuple
#? list
some_dct['x']
#? int() str() list tuple
some_dct['unknown']
k = 'a'
#? int()
some_dct[k]
some_other_dct = dict(some_dct, c=set)
#? int()
some_other_dct['a']
#? list
some_other_dct['x']
#? set
some_other_dct['c']
|