Best Python code snippet using playwright-python
test_builtins.py
Source:test_builtins.py
...43 StypyTypeError.reset_error_msgs()44 TypeWarning.reset_warning_msgs()45 def test_bytearray(self):46 obj = get_builtin_python_type(self.loc, "bytearray")47 compare_types(obj, bytearray)48 obj_instance = invoke(self.loc, obj)49 compare_types(type(obj_instance), bytearray)50 obj_instance = invoke(self.loc, obj, self.int_obj)51 compare_types(type(obj_instance), bytearray)52 obj_instance = invoke(self.loc, obj, self.str_obj)53 compare_types(type(obj_instance), bytearray)54 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")55 obj_instance = invoke(self.loc, obj, list_)56 assert_if_not_error(obj_instance)57 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)58 assert_if_not_error(obj_instance)59 list_ = self.type_store.get_type_of(Localization(__file__), "int_list")60 obj_instance = invoke(self.loc, obj, list_)61 compare_types(type(obj_instance), bytearray)62 compare_types(type(get_elements_type(obj_instance)), int)63 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list")64 obj_instance = invoke(self.loc, obj, list_)65 compare_types(type(obj_instance), bytearray)66 compare_types(type(get_elements_type(obj_instance)), int)67 self.assertTrue(len(TypeWarning.get_warning_msgs()) == 1)68 def test_all(self):69 obj = get_builtin_python_type_instance(self.loc, "all")70 compare_types(type(obj), types.BuiltinFunctionType)71 obj_instance = invoke(self.loc, obj)72 assert_if_not_error(obj_instance)73 obj_instance = invoke(self.loc, obj, self.int_obj)74 assert_if_not_error(obj_instance)75 obj_instance = invoke(self.loc, obj, self.str_obj)76 compare_types(type(obj_instance), bool)77 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")78 obj_instance = invoke(self.loc, obj, list_)79 compare_types(type(obj_instance), bool)80 list_ = self.type_store.get_type_of(Localization(__file__), "int_list")81 obj_instance = invoke(self.loc, obj, list_)82 compare_types(type(obj_instance), bool)83 def test_set(self):84 obj = get_builtin_python_type(self.loc, "set")85 compare_types(obj, set)86 obj_instance = invoke(self.loc, obj)87 compare_types(obj_instance, set)88 obj_instance = invoke(self.loc, obj, self.int_obj)89 assert_if_not_error(obj_instance)90 obj_instance = invoke(self.loc, obj, self.str_obj)91 compare_types(obj_instance, set)92 compare_types(get_elements_type(obj_instance), str())93 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")94 obj_instance = invoke(self.loc, obj, list_)95 compare_types(get_elements_type(obj_instance), [complex(), str()])96 obj_instance = invoke(self.loc, obj, self.str_obj, self.int_obj)97 assert_if_not_error(obj_instance)98 list_ = self.type_store.get_type_of(Localization(__file__), "int_list")99 obj_instance = invoke(self.loc, obj, list_)100 compare_types(obj_instance, set)101 compare_types(get_elements_type(obj_instance), int())102 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list")103 obj_instance = invoke(self.loc, obj, list_)104 compare_types(obj_instance, set)105 compare_types(get_elements_type(obj_instance), [int(), str()])106 def test_help(self):107 obj = get_builtin_python_type_instance(self.loc, "help")108 assert_equal_type_name(type(obj), "_Helper")109 obj_instance = invoke(self.loc, obj)110 compare_types(type(obj_instance), str)111 obj_instance = invoke(self.loc, obj, self.int_obj)112 compare_types(type(obj_instance), str)113 def test_vars(self):114 t = self.type_store.open_function_context("test_func")115 t.set_type_of(self.loc, "local_1", get_builtin_python_type_instance(self.loc, "int"))116 t.set_type_of(self.loc, "local_2", get_builtin_python_type_instance(self.loc, "str"))117 obj = get_builtin_python_type_instance(self.loc, "vars")118 compare_types(type(obj), types.BuiltinFunctionType)119 obj_instance = invoke(self.loc, obj)120 compare_types(obj_instance, dict)121 compare_types(type(get_values_from_key(obj_instance, "local_1")), int)122 compare_types(type(get_values_from_key(obj_instance, "local_2")), str)123 obj_instance = invoke(self.loc, obj, self.int_obj)124 assert_if_not_error(obj_instance)125 obj_instance = invoke(self.loc, obj, type(self.int_obj))126 compare_types(obj_instance, dict)127 self.assertTrue(len(obj_instance) == 56)128 t.close_function_context()129 def test_bool(self):130 obj = get_builtin_python_type_instance(self.loc, "bool")131 compare_types(type(obj), bool)132 obj = bool133 obj_instance = invoke(self.loc, obj)134 compare_types(type(obj_instance), bool)135 obj_instance = invoke(self.loc, obj, self.int_obj)136 compare_types(type(obj_instance), bool)137 obj_instance = invoke(self.loc, obj, self.str_obj)138 compare_types(type(obj_instance), bool)139 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")140 obj_instance = invoke(self.loc, obj, list_)141 compare_types(type(obj_instance), bool)142 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)143 assert_if_not_error(obj_instance)144 list_ = self.type_store.get_type_of(Localization(__file__), "int_list")145 obj_instance = invoke(self.loc, obj, list_)146 compare_types(type(obj_instance), bool)147 def test_float(self):148 class Foo:149 def __float__(self, localization):150 return get_builtin_python_type_instance(localization, 'float')151 obj = get_builtin_python_type(self.loc, "float")152 compare_types(obj, float)153 obj_instance = invoke(self.loc, obj)154 compare_types(type(obj_instance), float)155 obj_instance = invoke(self.loc, obj, self.int_obj)156 compare_types(type(obj_instance), float)157 obj_instance = invoke(self.loc, obj, self.str_obj)158 assert_if_not_error(obj_instance)159 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")160 obj_instance = invoke(self.loc, obj, list_)161 assert_if_not_error(obj_instance)162 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)163 assert_if_not_error(obj_instance)164 param = Foo()165 obj_instance = invoke(self.loc, obj, param)166 compare_types(type(obj_instance), float)167 def test_import(self):168 obj = get_builtin_python_type_instance(self.loc, "__import__")169 compare_types(type(obj), types.BuiltinFunctionType)170 obj_instance = invoke(self.loc, obj, "math")171 compare_types((obj_instance), types.ModuleType)172 obj_instance = invoke(self.loc, obj, self.int_obj)173 assert_if_not_error(obj_instance)174 obj_instance = invoke(self.loc, obj, "math", self.int_obj)175 compare_types((obj_instance), types.ModuleType)176 obj_instance = invoke(self.loc, obj, "math", self.int_obj, self.int_obj)177 compare_types((obj_instance), types.ModuleType)178 obj_instance = invoke(self.loc, obj, "math", self.int_obj, self.int_obj, self.int_obj)179 compare_types((obj_instance), types.ModuleType)180 obj_instance = invoke(self.loc, obj, "math", self.int_obj, self.int_obj, self.int_obj, self.str_obj)181 assert_if_not_error(obj_instance)182 def test_unicode(self):183 class WrongFoo:184 def __str__(self, localization):185 return get_builtin_python_type_instance(localization, 'float')186 class Foo:187 def __str__(self, localization):188 return get_builtin_python_type_instance(localization, 'str')189 obj = get_builtin_python_type(self.loc, "unicode")190 compare_types(obj, unicode)191 obj_instance = invoke(self.loc, obj)192 compare_types(type(obj_instance), unicode)193 obj_instance = invoke(self.loc, obj, self.int_obj)194 compare_types(type(obj_instance), unicode)195 obj_instance = invoke(self.loc, obj, self.str_obj)196 compare_types(type(obj_instance), unicode)197 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")198 obj_instance = invoke(self.loc, obj, list_)199 compare_types(type(obj_instance), unicode)200 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)201 assert_if_not_error(obj_instance)202 param = Foo()203 obj_instance = invoke(self.loc, obj, param)204 compare_types(type(obj_instance), unicode)205 param = WrongFoo()206 obj_instance = invoke(self.loc, obj, param)207 assert_if_not_error(obj_instance)208 def test_enumerate(self):209 class Foo:210 def __iter__(self, localization):211 t = get_builtin_python_type_instance(localization, "listiterator")212 set_contained_elements_type(localization, t,213 get_builtin_python_type_instance(localization, 'float', 3))214 return t215 obj = get_builtin_python_type(self.loc, "enumerate")216 compare_types(obj, enumerate)217 obj_instance = invoke(self.loc, obj)218 assert_if_not_error(obj_instance)219 obj_instance = invoke(self.loc, obj, self.int_obj)220 assert_if_not_error(obj_instance)221 obj_instance = invoke(self.loc, obj, self.str_obj)222 compare_types(obj_instance, enumerate)223 compare_types(get_elements_type(obj_instance), tuple)224 compare_types(get_elements_type(get_elements_type(obj_instance)), [int(), str()])225 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")226 obj_instance = invoke(self.loc, obj, list_)227 compare_types(obj_instance, enumerate)228 compare_types(get_elements_type(obj_instance), tuple)229 compare_types(get_elements_type(get_elements_type(obj_instance)), [int(), complex(), str()])230 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list")231 obj_instance = invoke(self.loc, obj, list_)232 compare_types(obj_instance, enumerate)233 compare_types(get_elements_type(obj_instance), tuple)234 compare_types(get_elements_type(get_elements_type(obj_instance)), [int(), str()])235 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)236 assert_if_not_error(obj_instance)237 param = Foo()238 obj_instance = invoke(self.loc, obj, param)239 compare_types(obj_instance, enumerate)240 compare_types(get_elements_type(obj_instance), tuple)241 compare_types(get_elements_type(get_elements_type(obj_instance)), [int(), float(3)])242 def test_reduce(self):243 obj = get_builtin_python_type_instance(self.loc, "reduce")244 compare_types(type(obj), types.BuiltinFunctionType)245 obj_instance = invoke(self.loc, obj)246 assert_if_not_error(obj_instance)247 obj_instance = invoke(self.loc, obj, self.int_obj)248 assert_if_not_error(obj_instance)249 def my_func1(localization, *args, **kwargs):250 result = python_operator(localization, '+', args[0], args[1])251 return result252 func = my_func1253 list_ = self.type_store.get_type_of(Localization(__file__), "int_list")254 obj_instance = invoke(self.loc, obj, func, list_)255 compare_types(type(obj_instance), int)256 def my_func2(localization, *args, **kwargs):257 param1 = get_builtin_python_type(localization, "str")258 arg1 = invoke(localization, param1, args[0])259 param1 = get_builtin_python_type(localization, "str")260 arg2 = invoke(localization, param1, args[1])261 result = python_operator(localization, '+', arg1, arg2)262 return result263 func2 = my_func2264 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")265 obj_instance = invoke(self.loc, obj, func2, list_)266 compare_types(type(obj_instance), str)267 def invalid_func(localization, *args, **kwargs):268 raise Exception("This always fails")269 func3 = invalid_func270 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")271 obj_instance = invoke(self.loc, obj, func3, list_)272 assert_if_not_error(obj_instance)273 initial = get_builtin_python_type_instance(self.loc, "int")274 list_ = self.type_store.get_type_of(Localization(__file__), "int_list")275 obj_instance = invoke(self.loc, obj, func, list_, initial)276 compare_types(type(obj_instance), int)277 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")278 obj_instance = invoke(self.loc, obj, func2, list_, initial)279 compare_types(type(obj_instance), str)280 initial2 = get_builtin_python_type_instance(self.loc, "str")281 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")282 obj_instance = invoke(self.loc, obj, func2, list_, initial2)283 compare_types(type(obj_instance), str)284 def test_list(self):285 obj = get_builtin_python_type(self.loc, "list")286 compare_types(obj, list)287 obj_instance = invoke(self.loc, obj)288 compare_types(obj_instance, list)289 obj_instance = invoke(self.loc, obj, self.int_obj)290 assert_if_not_error(obj_instance)291 obj_instance = invoke(self.loc, obj, self.str_obj)292 compare_types(obj_instance, list)293 compare_types(type(get_elements_type(obj_instance)), str)294 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")295 obj_instance = invoke(self.loc, obj, list_)296 compare_types((get_elements_type(obj_instance)), [complex(), str()])297 obj_instance = invoke(self.loc, obj, self.str_obj, self.int_obj)298 assert_if_not_error(obj_instance)299 list_ = self.type_store.get_type_of(Localization(__file__), "int_list")300 obj_instance = invoke(self.loc, obj, list_)301 compare_types((obj_instance), list)302 compare_types(type(get_elements_type(obj_instance)), int)303 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list")304 obj_instance = invoke(self.loc, obj, list_)305 compare_types((obj_instance), list)306 compare_types((get_elements_type(obj_instance)), [int(), str()])307 def test_coerce(self):308 obj = get_builtin_python_type_instance(self.loc, "coerce")309 compare_types(type(obj), types.BuiltinFunctionType)310 obj_instance = invoke(self.loc, obj)311 assert_if_not_error(obj_instance)312 obj_instance = invoke(self.loc, obj, self.int_obj)313 assert_if_not_error(obj_instance)314 obj_instance = invoke(self.loc, obj, self.str_obj)315 assert_if_not_error(obj_instance)316 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")317 obj_instance = invoke(self.loc, obj, list_)318 assert_if_not_error(obj_instance)319 list_ = self.type_store.get_type_of(Localization(__file__), "int_list")320 obj_instance = invoke(self.loc, obj, list_)321 assert_if_not_error(obj_instance)322 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)323 compare_types(obj_instance, tuple)324 compare_types(type(get_elements_type(obj_instance)), int)325 obj_instance = invoke(self.loc, obj, self.int_obj, self.float_obj)326 compare_types(obj_instance, tuple)327 compare_types(get_elements_type(obj_instance), [self.int_obj, self.float_obj])328 obj_instance = invoke(self.loc, obj, self.int_obj, self.str_obj)329 assert_if_not_error(obj_instance)330 def test_intern(self):331 obj = get_builtin_python_type_instance(self.loc, "intern")332 compare_types(type(obj), types.BuiltinFunctionType)333 obj_instance = invoke(self.loc, obj)334 assert_if_not_error(obj_instance)335 obj_instance = invoke(self.loc, obj, self.int_obj)336 assert_if_not_error(obj_instance)337 obj_instance = invoke(self.loc, obj, self.str_obj)338 compare_types(type(obj_instance), str)339 def test_globals(self):340 t = Context(None, __file__)341 t.set_type_of(self.loc, "global_1", get_builtin_python_type_instance(self.loc, "int"))342 t.set_type_of(self.loc, "global_2", get_builtin_python_type_instance(self.loc, "str"))343 obj = get_builtin_python_type_instance(self.loc, "globals")344 compare_types(type(obj), types.BuiltinFunctionType)345 obj_instance = invoke(self.loc, obj)346 compare_types(obj_instance, dict)347 #compare_types(obj_instance.wrapped_type['__builtins__'], dict)348 compare_types(obj_instance.wrapped_type['__doc__'], None)349 compare_types(obj_instance.wrapped_type['__name__'], str())350 compare_types(obj_instance.wrapped_type['__package__'], None)351 compare_types(obj_instance.wrapped_type['global_1'], int())352 compare_types(obj_instance.wrapped_type['global_2'], str())353 def test_issubclass(self):354 obj = get_builtin_python_type_instance(self.loc, "issubclass")355 compare_types(type(obj), types.BuiltinFunctionType)356 obj_instance = invoke(self.loc, obj)357 assert_if_not_error(obj_instance)358 type1 = int359 type2 = complex360 obj_instance = invoke(self.loc, obj, type1, type2)361 compare_types(type(obj_instance), bool)362 instance1 = get_builtin_python_type_instance(self.loc, "int")363 instance2 = get_builtin_python_type_instance(self.loc, "complex")364 obj_instance = invoke(self.loc, obj, instance1, instance2)365 assert_if_not_error(obj_instance)366 def test_divmod(self):367 obj = get_builtin_python_type_instance(self.loc, "divmod")368 compare_types(type(obj), types.BuiltinFunctionType)369 obj_instance = invoke(self.loc, obj)370 assert_if_not_error(obj_instance)371 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)372 compare_types(obj_instance, tuple)373 compare_types(type(get_elements_type(obj_instance)), int)374 obj_instance = invoke(self.loc, obj, self.int_obj, self.float_obj)375 compare_types(obj_instance, tuple)376 compare_types(type(get_elements_type(obj_instance)), float)377 def test_file(self):378 obj = file #get_builtin_python_type_instance(self.loc, "file")379 obj_instance = invoke(self.loc, obj)380 assert_if_not_error(obj_instance)381 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)382 assert_if_not_error(obj_instance)383 obj_instance = invoke(self.loc, obj, self.str_obj)384 compare_types(type(obj_instance), file)385 obj_instance = invoke(self.loc, obj, self.str_obj, self.str_obj)386 compare_types(type(obj_instance), file)387 obj_instance = invoke(self.loc, obj, self.str_obj, self.str_obj, self.int_obj)388 compare_types(type(obj_instance), file)389 class Foo:390 def __trunc__(self, localization):391 return get_builtin_python_type_instance(localization, "int")392 trunc_instance = Foo()393 obj_instance = invoke(self.loc, obj, self.str_obj, self.str_obj, trunc_instance)394 compare_types(type(obj_instance), file)395 def test_unichr(self):396 obj = get_builtin_python_type_instance(self.loc, "unichr")397 compare_types(type(obj), types.BuiltinFunctionType)398 obj_instance = invoke(self.loc, obj)399 assert_if_not_error(obj_instance)400 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)401 assert_if_not_error(obj_instance)402 obj_instance = invoke(self.loc, obj, self.int_obj)403 compare_types(type(obj_instance), unicode)404 class Foo:405 def __trunc__(self, localization):406 return get_builtin_python_type_instance(localization, "int")407 trunc_instance = Foo()408 obj_instance = invoke(self.loc, obj, trunc_instance)409 compare_types(type(obj_instance), unicode)410 def test_apply(self):411 class Foo1:412 def __call__(self, localization):413 return get_builtin_python_type_instance(None, "int")414 instance1 = Foo1()415 class Foo2:416 def __call__(self, localization, param):417 return get_builtin_python_type_instance(None, type(param).__name__)418 class Foo2b:419 def __call__(self, localization, param, param2):420 return get_builtin_python_type_instance(None, type(param2).__name__)421 instance2 = Foo2()422 instance2b = Foo2b()423 class Foo3:424 def __call__(self, localization, *param):425 return param[-1]426 instance3 = Foo3()427 apply_func = get_builtin_python_type_instance(self.loc, "apply")428 compare_types(type(apply_func), types.BuiltinFunctionType)429 obj_instance = invoke(self.loc, apply_func)430 assert_if_not_error(obj_instance)431 obj_instance = invoke(self.loc, apply_func, instance1)432 compare_types(type(obj_instance), int)433 tuple_ = get_builtin_python_type(self.loc, "tuple")434 types_ = get_builtin_python_type_instance(self.loc, "list")435 set_contained_elements_type(self.loc, types_, self.float_obj)436 tuple_ = invoke(self.loc, tuple_, types_)437 obj_instance = invoke(self.loc, apply_func, instance2, tuple_)438 compare_types(type(obj_instance), float)439 obj_instance = invoke(self.loc, apply_func, instance2b, tuple_)440 compare_types(type(obj_instance), float)441 dict_ = get_builtin_python_type_instance(self.loc, "dict")442 add_key_and_value_type(dict_, self.str_obj, self.int_obj)443 obj_instance = invoke(self.loc, apply_func, instance3, tuple_, dict_)444 compare_types(obj_instance, dict)445 builtins = load_builtin_operators_module()446 add = self.type_store.get_type_of_member(self.loc, builtins, "add")447 obj_instance = invoke(self.loc, apply_func, add, tuple_)448 compare_types(type(obj_instance), float)449 def test_isinstance(self):450 obj = get_builtin_python_type_instance(self.loc, "isinstance")451 compare_types(type(obj), types.BuiltinFunctionType)452 obj_instance = invoke(self.loc, obj)453 assert_if_not_error(obj_instance)454 obj_instance = invoke(self.loc, obj, self.int_obj, int)455 compare_types(type(obj_instance), bool)456 obj_instance = invoke(self.loc, obj, self.str_obj, str)457 compare_types(type(obj_instance), bool)458 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")459 obj_instance = invoke(self.loc, obj, list_, list)460 compare_types(type(obj_instance), bool)461 list_ = self.type_store.get_type_of(Localization(__file__), "int_list")462 obj_instance = invoke(self.loc, obj, list_, tuple)463 compare_types(type(obj_instance), bool)464 def test_next(self):465 obj = get_builtin_python_type_instance(self.loc, "next")466 compare_types(type(obj), types.BuiltinFunctionType)467 obj_instance = invoke(self.loc, obj)468 assert_if_not_error(obj_instance)469 obj_instance = invoke(self.loc, obj, self.int_obj)470 assert_if_not_error(obj_instance)471 obj_instance = invoke(self.loc, obj, self.str_obj)472 assert_if_not_error(obj_instance)473 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")474 iter_list_call = self.type_store.get_type_of_member(self.loc, list_, "__iter__")475 iter_list = invoke(self.loc, iter_list_call)476 compare_types(iter_list, ExtraTypeDefinitions.listiterator)477 obj_instance = invoke(self.loc, obj, list_)478 assert_if_not_error(obj_instance)479 obj_instance = invoke(self.loc, obj, iter_list)480 compare_types(obj_instance, [complex(), str()])481 obj_instance = invoke(self.loc, obj, iter_list, self.float_obj)482 compare_types(obj_instance, [complex(), str(), float(3.14)])483 list_ = self.type_store.get_type_of(Localization(__file__), "int_list")484 iter_list_call = self.type_store.get_type_of_member(self.loc, list_, "__iter__")485 iter_list = invoke(self.loc, iter_list_call)486 compare_types(iter_list, ExtraTypeDefinitions.listiterator)487 obj_instance = invoke(self.loc, obj, list_)488 assert_if_not_error(obj_instance)489 obj_instance = invoke(self.loc, obj, iter_list)490 compare_types(type(obj_instance), int)491 obj_instance = invoke(self.loc, obj, iter_list, self.float_obj)492 compare_types(obj_instance, [int(), float(3.14)])493 def test_any(self):494 obj = get_builtin_python_type_instance(self.loc, "any")495 compare_types(type(obj), types.BuiltinFunctionType)496 obj_instance = invoke(self.loc, obj)497 assert_if_not_error(obj_instance)498 obj_instance = invoke(self.loc, obj, self.int_obj)499 assert_if_not_error(obj_instance)500 obj_instance = invoke(self.loc, obj, self.str_obj)501 assert_if_not_error(obj_instance)502 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")503 obj_instance = invoke(self.loc, obj, list_)504 compare_types(type(obj_instance), bool)505 def test_locals(self):506 context = self.type_store.open_function_context("test_func2")507 context.set_type_of(self.loc, "local_1", get_builtin_python_type_instance(self.loc, "int"))508 context.set_type_of(self.loc, "local_2", get_builtin_python_type_instance(self.loc, "str"))509 obj = get_builtin_python_type_instance(self.loc, "locals")510 compare_types(type(obj), types.BuiltinFunctionType)511 obj_instance = invoke(self.loc, obj)512 compare_types(obj_instance, dict)513 compare_types(type(obj_instance.wrapped_type['local_1']), int)514 compare_types(type(obj_instance.wrapped_type['local_2']), str)515 self.type_store.close_function_context()516 def test_filter(self):517 obj = get_builtin_python_type_instance(self.loc, "filter")518 compare_types(type(obj), types.BuiltinFunctionType)519 obj_instance = invoke(self.loc, obj)520 assert_if_not_error(obj_instance)521 obj_instance = invoke(self.loc, obj, self.int_obj)522 assert_if_not_error(obj_instance)523 obj_instance = invoke(self.loc, obj, self.str_obj)524 assert_if_not_error(obj_instance)525 def my_func1(localization, *args, **kwargs):526 return False527 func1 = my_func1528 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")529 obj_instance = invoke(self.loc, obj, func1, list_)530 compare_types(obj_instance, list)531 compare_types(get_elements_type(obj_instance), [complex(), str()])532 obj_instance = invoke(self.loc, obj, func1, self.str_obj)533 compare_types(obj_instance, list)534 compare_types(get_elements_type(obj_instance), str())535 def test_slice(self):536 obj = get_builtin_python_type(self.loc, "slice")537 compare_types(obj, slice)538 obj_instance = invoke(self.loc, obj)539 assert_if_not_error(obj_instance)540 obj_instance = invoke(self.loc, obj, self.int_obj)541 compare_types(get_elements_type(obj_instance), [int(), types.NoneType])542 obj_instance = invoke(self.loc, obj, self.str_obj)543 compare_types(get_elements_type(obj_instance), [str(), types.NoneType])544 def my_func1(localization, *args, **kwargs):545 return False546 func1 = my_func1547 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")548 obj_instance = invoke(self.loc, obj, func1, list_)549 compare_types(obj_instance, slice)550 compare_types(get_elements_type(obj_instance), [list_, False])551 obj_instance = invoke(self.loc, obj, func1, self.str_obj)552 compare_types(obj_instance, slice)553 compare_types(get_elements_type(obj_instance), [str(), False])554 def test_copyright(self):555 obj = get_builtin_python_type(self.loc, "copyright")556 assert_equal_type_name(type(obj), "_Printer")557 obj_instance = invoke(self.loc, obj)558 compare_types(type(obj_instance), types.NoneType)559 obj_instance = invoke(self.loc, obj, self.int_obj)560 assert_if_not_error(obj_instance)561 def test_min(self):562 obj = get_builtin_python_type_instance(self.loc, "min")563 compare_types(type(obj), types.BuiltinFunctionType)564 obj_instance = invoke(self.loc, obj)565 assert_if_not_error(obj_instance)566 obj_instance = invoke(self.loc, obj, self.int_obj)567 assert_if_not_error(obj_instance)568 obj_instance = invoke(self.loc, obj, self.str_obj)569 compare_types(type(obj_instance), str)570 obj_instance = invoke(self.loc, obj, self.int_obj, self.float_obj)571 compare_types(obj_instance, [self.int_obj, self.float_obj])572 obj_instance = invoke(self.loc, obj, self.int_obj, self.float_obj, self.int_obj, self.float_obj, self.int_obj,573 self.float_obj, self.int_obj, self.float_obj)574 compare_types(obj_instance, [int(), float()])575 tuple_ = get_builtin_python_type_instance(self.loc, "tuple")576 set_contained_elements_type(self.loc, tuple_, self.float_obj)577 obj_instance = invoke(self.loc, obj, tuple_)578 compare_types(type(obj_instance), float)579 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")580 obj_instance = invoke(self.loc, obj, list_)581 compare_types(obj_instance, [complex(), str()])582 list_ = self.type_store.get_type_of(Localization(__file__), "int_list")583 obj_instance = invoke(self.loc, obj, list_)584 compare_types(type(obj_instance), int)585 def func(localization, *args, **kwargs):586 return get_builtin_python_type_instance(localization, "int")587 dict = {'key': func}588 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")589 obj_instance = invoke(self.loc, obj, list_, **dict)590 compare_types(obj_instance, [complex(), str()])591 def test_open(self):592 obj = get_builtin_python_type_instance(self.loc, "open")593 compare_types(type(obj), types.BuiltinFunctionType)594 obj_instance = invoke(self.loc, obj)595 assert_if_not_error(obj_instance)596 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)597 assert_if_not_error(obj_instance)598 obj_instance = invoke(self.loc, obj, self.str_obj)599 compare_types(type(obj_instance), file)600 obj_instance = invoke(self.loc, obj, self.str_obj, self.str_obj)601 compare_types(type(obj_instance), file)602 obj_instance = invoke(self.loc, obj, self.str_obj, self.str_obj, self.int_obj)603 compare_types(type(obj_instance), file)604 class Foo:605 def __trunc__(self, localization):606 return get_builtin_python_type_instance(localization, "int")607 trunc_instance = Foo()608 obj_instance = invoke(self.loc, obj, self.str_obj, self.str_obj, trunc_instance)609 compare_types(type(obj_instance), file)610 def test_sum(self):611 obj = get_builtin_python_type_instance(self.loc, "sum")612 compare_types(type(obj), types.BuiltinFunctionType)613 obj_instance = invoke(self.loc, obj)614 assert_if_not_error(obj_instance)615 obj_instance = invoke(self.loc, obj, self.int_obj)616 assert_if_not_error(obj_instance)617 class Foo:618 def __add__(self, localization, other):619 return get_builtin_python_type_instance(localization, "int")620 list_ = self.type_store.get_type_of(Localization(__file__), "int_list")621 obj_instance = invoke(self.loc, obj, list_)622 compare_types(type(obj_instance), int)623 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")624 obj_instance = invoke(self.loc, obj, list_)625 assert_if_not_error(obj_instance)626 instance = Foo()627 list_ = get_builtin_python_type_instance(self.loc, "list")628 set_contained_elements_type(self.loc, list_, instance)629 obj_instance = invoke(self.loc, obj, list_)630 assert_if_not_error(obj_instance)631 obj_instance = invoke(self.loc, obj, list_, self.int_obj)632 assert_if_not_error(obj_instance)633 def test_chr(self):634 obj = get_builtin_python_type_instance(self.loc, "chr")635 compare_types(type(obj), types.BuiltinFunctionType)636 obj_instance = invoke(self.loc, obj)637 assert_if_not_error(obj_instance)638 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)639 assert_if_not_error(obj_instance)640 obj_instance = invoke(self.loc, obj, self.int_obj)641 compare_types(type(obj_instance), str)642 obj_instance = invoke(self.loc, obj, self.int_obj, self.str_obj)643 assert_if_not_error(obj_instance)644 class Foo:645 def __trunc__(self, localization):646 return get_builtin_python_type_instance(localization, "int")647 trunc_instance = Foo()648 obj_instance = invoke(self.loc, obj, trunc_instance)649 compare_types(type(obj_instance), str)650 def test_hex(self):651 obj = get_builtin_python_type_instance(self.loc, "hex")652 compare_types(type(obj), types.BuiltinFunctionType)653 obj_instance = invoke(self.loc, obj)654 assert_if_not_error(obj_instance)655 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)656 assert_if_not_error(obj_instance)657 obj_instance = invoke(self.loc, obj, self.int_obj)658 compare_types(type(obj_instance), str)659 obj_instance = invoke(self.loc, obj, self.int_obj, self.str_obj)660 assert_if_not_error(obj_instance)661 class Foo:662 def __hex__(self, localization):663 return get_builtin_python_type_instance(localization, "int")664 class Foo2:665 def __hex__(self, localization):666 return get_builtin_python_type_instance(localization, "str")667 hex_instance = Foo()668 obj_instance = invoke(self.loc, obj, hex_instance)669 assert_if_not_error(obj_instance)670 hex_instance = Foo2()671 obj_instance = invoke(self.loc, obj, hex_instance)672 compare_types(type(obj_instance), str)673 def test_execfile(self):674 obj = get_builtin_python_type_instance(self.loc, "execfile")675 compare_types(type(obj), types.BuiltinFunctionType)676 obj_instance = invoke(self.loc, obj)677 assert_if_not_error(obj_instance)678 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)679 assert_if_not_error(obj_instance)680 obj_instance = invoke(self.loc, obj, self.str_obj)681 compare_types(type(obj_instance), DynamicType)682 dict_ = get_builtin_python_type_instance(self.loc, "dict")683 obj_instance = invoke(self.loc, obj, self.str_obj, dict_)684 compare_types(type(obj_instance), DynamicType)685 obj_instance = invoke(self.loc, obj, self.str_obj, dict_, dict_)686 compare_types(type(obj_instance), DynamicType)687 def test_long(self):688 obj = get_builtin_python_type(self.loc, "long")689 compare_types(obj, types.LongType)690 obj_instance = invoke(self.loc, obj)691 compare_types(type(obj_instance), long)692 obj_instance = invoke(self.loc, obj, self.float_obj)693 compare_types(type(obj_instance), long)694 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)695 compare_types(type(obj_instance), long)696 obj_instance = invoke(self.loc, obj, self.float_obj, self.int_obj)697 compare_types(type(obj_instance), long)698 obj_instance = invoke(self.loc, obj, self.float_obj, self.float_obj)699 assert_if_not_error(obj_instance)700 obj_instance = invoke(self.loc, obj, self.str_obj)701 assert_if_not_error(obj_instance)702 obj_instance = invoke(self.loc, obj, self.int_obj, self.str_obj)703 assert_if_not_error(obj_instance)704 class Foo:705 def __trunc__(self, localization):706 return get_builtin_python_type_instance(localization, "int")707 trunc_instance = Foo()708 obj_instance = invoke(self.loc, obj, trunc_instance)709 compare_types(type(obj_instance), long)710 obj_instance = invoke(self.loc, obj, self.int_obj, trunc_instance)711 compare_types(type(obj_instance), long)712 obj_instance = invoke(self.loc, obj, trunc_instance, trunc_instance)713 compare_types(type(obj_instance), long)714 def test_id(self):715 obj = get_builtin_python_type_instance(self.loc, "id")716 compare_types(type(obj), types.BuiltinFunctionType)717 obj_instance = invoke(self.loc, obj)718 assert_if_not_error(obj_instance)719 type1 = int720 type2 = complex721 obj_instance = invoke(self.loc, obj, type1)722 compare_types(type(obj_instance), long)723 obj_instance = invoke(self.loc, obj, type2)724 compare_types(type(obj_instance), long)725 instance1 = get_builtin_python_type_instance(self.loc, "int")726 instance2 = get_builtin_python_type_instance(self.loc, "complex")727 obj_instance = invoke(self.loc, obj, instance1)728 compare_types(type(obj_instance), long)729 obj_instance = invoke(self.loc, obj, instance2)730 compare_types(type(obj_instance), long)731 def test_xrange(self):732 obj = get_builtin_python_type_instance(self.loc, "xrange")733 compare_types(obj, types.XRangeType)734 obj_instance = invoke(self.loc, obj)735 assert_if_not_error(obj_instance)736 obj_instance = invoke(self.loc, obj, self.float_obj)737 assert_if_not_error(obj_instance)738 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)739 compare_types(obj_instance, xrange)740 compare_types(type(get_elements_type(obj_instance)), int)741 obj_instance = invoke(self.loc, obj, self.float_obj, self.int_obj)742 assert_if_not_error(obj_instance)743 obj_instance = invoke(self.loc, obj, self.float_obj, self.float_obj)744 assert_if_not_error(obj_instance)745 obj_instance = invoke(self.loc, obj, self.str_obj)746 assert_if_not_error(obj_instance)747 obj_instance = invoke(self.loc, obj, self.int_obj, self.str_obj)748 assert_if_not_error(obj_instance)749 class Foo:750 def __trunc__(self, localization):751 return get_builtin_python_type_instance(localization, "int")752 trunc_instance = Foo()753 obj_instance = invoke(self.loc, obj, trunc_instance)754 compare_types(obj_instance, xrange)755 compare_types(type(get_elements_type(obj_instance)), int)756 obj_instance = invoke(self.loc, obj, self.int_obj, trunc_instance)757 compare_types(obj_instance, xrange)758 compare_types(type(get_elements_type(obj_instance)), int)759 obj_instance = invoke(self.loc, obj, trunc_instance, trunc_instance)760 compare_types(obj_instance, xrange)761 compare_types(type(get_elements_type(obj_instance)), int)762 def test_int(self):763 obj = get_builtin_python_type(self.loc, "int")764 compare_types((obj), types.IntType)765 obj_instance = invoke(self.loc, obj)766 compare_types(type(obj_instance), int)767 obj_instance = invoke(self.loc, obj, self.float_obj)768 compare_types(type(obj_instance), int)769 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)770 compare_types(type(obj_instance), int)771 obj_instance = invoke(self.loc, obj, self.float_obj, self.int_obj)772 compare_types(type(obj_instance), int)773 obj_instance = invoke(self.loc, obj, self.float_obj, self.float_obj)774 assert_if_not_error(obj_instance)775 obj_instance = invoke(self.loc, obj, self.str_obj)776 assert_if_not_error(obj_instance)777 obj_instance = invoke(self.loc, obj, self.int_obj, self.str_obj)778 assert_if_not_error(obj_instance)779 class Foo:780 def __trunc__(self, localization):781 return get_builtin_python_type_instance(localization, "int")782 trunc_instance = Foo()783 obj_instance = invoke(self.loc, obj, trunc_instance)784 compare_types(type(obj_instance), int)785 obj_instance = invoke(self.loc, obj, self.int_obj, trunc_instance)786 compare_types(type(obj_instance), int)787 obj_instance = invoke(self.loc, obj, trunc_instance, trunc_instance)788 compare_types(type(obj_instance), int)789 def test_getattr(self):790 obj = get_builtin_python_type_instance(self.loc, "getattr")791 compare_types(type(obj), types.BuiltinFunctionType)792 obj_instance = invoke(self.loc, obj)793 assert_if_not_error(obj_instance)794 obj_instance = invoke(self.loc, obj, self.int_obj)795 assert_if_not_error(obj_instance)796 class Foo:797 def __add__(self, localization, other):798 return get_builtin_python_type_instance(localization, "int")799 Foo.attclass = int800 foo_inst = Foo()801 foo_inst.attinst = str802 class_ = Foo803 instance = foo_inst804 val1 = get_builtin_python_type_instance(self.loc, "str", "attclass")805 val2 = get_builtin_python_type_instance(self.loc, "str", "attinst")806 val3 = get_builtin_python_type_instance(self.loc, "str", "not_exist")807 val4 = get_builtin_python_type_instance(self.loc, "str")808 obj_instance = invoke(self.loc, obj, class_, val1)809 compare_types(obj_instance, int)810 obj_instance = invoke(self.loc, obj, class_, val2)811 assert_if_not_error(obj_instance)812 obj_instance = invoke(self.loc, obj, class_, val3)813 assert_if_not_error(obj_instance)814 obj_instance = invoke(self.loc, obj, class_, val4)815 compare_types(obj_instance, [Foo.__add__, str(), int])816 obj_instance = invoke(self.loc, obj, instance, val1)817 compare_types(obj_instance, int)818 obj_instance = invoke(self.loc, obj, instance, val2)819 compare_types(obj_instance, str)820 obj_instance = invoke(self.loc, obj, instance, val3)821 assert_if_not_error(obj_instance)822 obj_instance = invoke(self.loc, obj, instance, val4)823 compare_types(obj_instance, [foo_inst.__add__, str, str(), int])824 def test_abs(self):825 class Foo:826 def __abs__(self, localization):827 return get_builtin_python_type_instance(localization, 'int')828 obj = get_builtin_python_type_instance(self.loc, "abs")829 compare_types(type(obj), types.BuiltinFunctionType)830 obj_instance = invoke(self.loc, obj)831 assert_if_not_error(obj_instance)832 obj_instance = invoke(self.loc, obj, self.int_obj)833 compare_types(type(obj_instance), int)834 complex_inst = get_builtin_python_type_instance(self.loc, "complex")835 obj_instance = invoke(self.loc, obj, complex_inst)836 compare_types(type(obj_instance), float)837 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")838 obj_instance = invoke(self.loc, obj, list_)839 assert_if_not_error(obj_instance)840 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)841 assert_if_not_error(obj_instance)842 param = Foo()843 obj_instance = invoke(self.loc, obj, param)844 compare_types(type(obj_instance), int)845 def test_exit(self):846 obj = get_builtin_python_type(self.loc, "exit")847 assert_equal_type_name(type(obj), "Quitter")848 obj_instance = invoke(self.loc, obj)849 compare_types(obj_instance, undefined_type.UndefinedType)850 obj_instance = invoke(self.loc, obj, self.int_obj)851 compare_types(obj_instance, undefined_type.UndefinedType)852 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")853 obj_instance = invoke(self.loc, obj, list_)854 compare_types(obj_instance, undefined_type.UndefinedType)855 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)856 assert_if_not_error(obj_instance)857 def test_pow(self):858 obj = get_builtin_python_type_instance(self.loc, "pow")859 compare_types(type(obj), types.BuiltinFunctionType)860 obj_instance = invoke(self.loc, obj)861 assert_if_not_error(obj_instance)862 obj_instance = invoke(self.loc, obj, self.int_obj)863 assert_if_not_error(obj_instance)864 class Foo:865 def __pow__(self, localization, other, another):866 return get_builtin_python_type_instance(localization, "int")867 complex_inst = get_builtin_python_type_instance(self.loc, "complex")868 obj_instance = invoke(self.loc, obj, complex_inst, self.int_obj)869 compare_types(type(obj_instance), types.ComplexType)870 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)871 compare_types(type(obj_instance), int)872 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")873 obj_instance = invoke(self.loc, obj, list_, list_)874 assert_if_not_error(obj_instance)875 instance = instance = Foo()876 obj_instance = invoke(self.loc, obj, instance, self.int_obj, self.int_obj)877 compare_types(type(obj_instance), int)878 bool_inst = get_builtin_python_type_instance(self.loc, "bool")879 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj, bool_inst)880 compare_types(type(obj_instance), int)881 long_inst = get_builtin_python_type_instance(self.loc, "long")882 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj, long_inst)883 compare_types(type(obj_instance), long)884 def test_input(self):885 obj = get_builtin_python_type_instance(self.loc, "input")886 assert_equal_type_name(obj, "input")887 obj_instance = invoke(self.loc, obj)888 compare_types((obj_instance), DynamicType)889 obj_instance = invoke(self.loc, obj, self.int_obj)890 compare_types((obj_instance), DynamicType)891 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")892 obj_instance = invoke(self.loc, obj, list_)893 compare_types((obj_instance), DynamicType)894 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)895 assert_if_not_error(obj_instance)896 def test_type(self):897 obj = get_builtin_python_type_instance(self.loc, "type")898 assert_equal_type_name(obj, "type")899 obj_instance = invoke(self.loc, obj)900 assert_if_not_error(obj_instance)901 obj_instance = invoke(self.loc, obj, self.int_obj)902 compare_types(obj_instance, int)903 obj_instance = invoke(self.loc, obj, self.str_obj)904 compare_types(obj_instance, str)905 class Foo:906 def __pow__(self, localization, other, another):907 return get_builtin_python_type_instance(localization, "int")908 complex_inst = get_builtin_python_type_instance(self.loc, "complex")909 obj_instance = invoke(self.loc, obj, complex_inst)910 compare_types(obj_instance, types.ComplexType)911 obj_instance = invoke(self.loc, obj, self.int_obj)912 compare_types(obj_instance, int)913 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")914 obj_instance = invoke(self.loc, obj, list_, list_)915 assert_if_not_error(obj_instance)916 obj_instance = invoke(self.loc, obj, list_)917 compare_types(obj_instance, list)918 instance = Foo()919 obj_instance = invoke(self.loc, obj, instance)920 compare_types(obj_instance, type(Foo()))921 bool_inst = get_builtin_python_type_instance(self.loc, "bool")922 obj_instance = invoke(self.loc, obj, bool_inst)923 compare_types(obj_instance, bool)924 long_inst = get_builtin_python_type_instance(self.loc, "long")925 obj_instance = invoke(self.loc, obj, long_inst)926 compare_types(obj_instance, long)927 type_inst = get_builtin_python_type_instance(self.loc, "type")928 obj_instance = invoke(self.loc, obj, type_inst)929 compare_types(obj_instance, types.TypeType)930 def test_oct(self):931 obj = get_builtin_python_type_instance(self.loc, "oct")932 compare_types(type(obj), types.BuiltinFunctionType)933 obj_instance = invoke(self.loc, obj)934 assert_if_not_error(obj_instance)935 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)936 assert_if_not_error(obj_instance)937 obj_instance = invoke(self.loc, obj, self.int_obj)938 compare_types(type(obj_instance), str)939 obj_instance = invoke(self.loc, obj, self.int_obj, self.str_obj)940 assert_if_not_error(obj_instance)941 class Foo:942 def __oct__(self, localization):943 return get_builtin_python_type_instance(localization, "int")944 class Foo2:945 def __oct__(self, localization):946 return get_builtin_python_type_instance(localization, "str")947 hex_instance = Foo()948 obj_instance = invoke(self.loc, obj, hex_instance)949 assert_if_not_error(obj_instance)950 hex_instance = Foo2()951 obj_instance = invoke(self.loc, obj, hex_instance)952 compare_types(type(obj_instance), str)953 def test_bin(self):954 obj = get_builtin_python_type_instance(self.loc, "bin")955 compare_types(type(obj), types.BuiltinFunctionType)956 obj_instance = invoke(self.loc, obj)957 assert_if_not_error(obj_instance)958 bool_inst = get_builtin_python_type_instance(self.loc, "bool")959 obj_instance = invoke(self.loc, obj, bool_inst)960 compare_types(type(obj_instance), str)961 long_inst = get_builtin_python_type_instance(self.loc, "long")962 obj_instance = invoke(self.loc, obj, long_inst)963 compare_types(type(obj_instance), str)964 def test_map(self):965 obj = get_builtin_python_type(self.loc, "map")966 compare_types(type(obj), types.BuiltinFunctionType)967 obj_instance = invoke(self.loc, obj)968 assert_if_not_error(obj_instance)969 obj_instance = invoke(self.loc, obj, self.int_obj)970 assert_if_not_error(obj_instance)971 list_ = self.type_store.get_type_of(Localization(__file__), "int_list")972 obj_instance = invoke(self.loc, obj, self.int_obj, list_)973 assert_if_not_error(obj_instance)974 func = get_builtin_python_type(self.loc, 'str')975 list_ = self.type_store.get_type_of(Localization(__file__), "int_list")976 obj_instance = invoke(self.loc, obj, func, list_)977 compare_types(obj_instance, list)978 compare_types(type(get_elements_type(obj_instance)), str)979 def my_func1(localization, *args, **kwargs):980 param1 = get_builtin_python_type(localization, "str")981 result = invoke(localization, param1, args[0])982 return result983 func = my_func1984 list_ = self.type_store.get_type_of(Localization(__file__), "int_list")985 obj_instance = invoke(self.loc, obj, func, list_)986 compare_types(obj_instance, list)987 compare_types(type(get_elements_type(obj_instance)), str)988 def my_func2(localization, *args, **kwargs):989 param2 = get_builtin_python_type_instance(localization, "int")990 result = python_operator(localization, '/', args[0], param2)991 return result992 func2 = my_func2993 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")994 obj_instance = invoke(self.loc, obj, func2, list_)995 compare_types(obj_instance, list)996 compare_types(type(get_elements_type(obj_instance)), complex)997 def invalid_func(localization, *args, **kwargs):998 return StypyTypeError(localization, "This always fails")999 func3 = invalid_func1000 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")1001 obj_instance = invoke(self.loc, obj, func3, list_)1002 assert_if_not_error(obj_instance)1003 def my_func3(localization, *args, **kwargs):1004 if len(args) > 2:1005 return StypyTypeError(localization, "Too many arguments")1006 result = python_operator(localization, '+', args[0], args[1])1007 return result1008 func4 = my_func31009 list_ = self.type_store.get_type_of(Localization(__file__), "int_list")1010 obj_instance = invoke(self.loc, obj, func4, list_, list_)1011 compare_types(obj_instance, list)1012 compare_types(type(get_elements_type(obj_instance)), int)1013 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")1014 obj_instance = invoke(self.loc, obj, func4, list_, list_, list_)1015 assert_if_not_error(obj_instance)1016 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")1017 obj_instance = invoke(self.loc, obj, func2, list_, list_)1018 compare_types(obj_instance, list)1019 compare_types(type(get_elements_type(obj_instance)), complex)1020 def my_func4(localization, *args, **kwargs):1021 str_var = get_builtin_python_type_instance(localization, "str")1022 result = python_operator(localization, '+', args[0], str_var)1023 return result1024 func5 = my_func41025 str_var = get_builtin_python_type_instance(self.loc, "str")1026 obj_instance = invoke(self.loc, obj, func5, str_var)1027 compare_types(obj_instance, list)1028 compare_types(type(get_elements_type(obj_instance)), str)1029 obj_instance = invoke(self.loc, obj, func2, str_var)1030 assert_if_not_error(obj_instance)1031 def test_zip(self):1032 obj = get_builtin_python_type_instance(self.loc, "zip")1033 compare_types(type(obj), types.BuiltinFunctionType)1034 obj_instance = invoke(self.loc, obj)1035 assert_if_not_error(obj_instance)1036 obj_instance = invoke(self.loc, obj, self.int_obj)1037 assert_if_not_error(obj_instance)1038 list_ = self.type_store.get_type_of(Localization(__file__), "int_list")1039 obj_instance = invoke(self.loc, obj, list_)1040 compare_types(obj_instance, list)1041 compare_types(get_elements_type(obj_instance), tuple)1042 compare_types(type(get_elements_type(get_elements_type(obj_instance))), int)1043 list_ = self.type_store.get_type_of(Localization(__file__), "int_list")1044 obj_instance = invoke(self.loc, obj, list_, list_)1045 compare_types(obj_instance, list)1046 compare_types(get_elements_type(obj_instance), tuple)1047 compare_types(type(get_elements_type(get_elements_type(obj_instance))), int)1048 list_2 = self.type_store.get_type_of(Localization(__file__), "mixed_type_list")1049 obj_instance = invoke(self.loc, obj, list_, list_2)1050 compare_types(obj_instance, list)1051 compare_types(get_elements_type(obj_instance), tuple)1052 compare_types(get_elements_type(get_elements_type(obj_instance)), [int(), str()])1053 list_3 = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")1054 obj_instance = invoke(self.loc, obj, list_, list_3)1055 compare_types(obj_instance, list)1056 compare_types(get_elements_type(obj_instance), tuple)1057 compare_types(get_elements_type(get_elements_type(obj_instance)), [int(), str(), complex()])1058 str_instance = get_builtin_python_type_instance(self.loc, "str")1059 obj_instance = invoke(self.loc, obj, list_, str_instance)1060 compare_types(obj_instance, list)1061 compare_types(get_elements_type(obj_instance), tuple)1062 compare_types(get_elements_type(get_elements_type(obj_instance)), [int(), str()])1063 str_instance = get_builtin_python_type_instance(self.loc, "str")1064 obj_instance = invoke(self.loc, obj, str_instance, str_instance)1065 compare_types(obj_instance, list)1066 compare_types(get_elements_type(obj_instance), tuple)1067 compare_types(type(get_elements_type(get_elements_type(obj_instance))), str)1068 def test_hash(self):1069 obj = get_builtin_python_type_instance(self.loc, "hash")1070 compare_types(type(obj), types.BuiltinFunctionType)1071 obj_instance = invoke(self.loc, obj)1072 assert_if_not_error(obj_instance)1073 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)1074 assert_if_not_error(obj_instance)1075 obj_instance = invoke(self.loc, obj, self.int_obj)1076 compare_types(type(obj_instance), int)1077 obj_instance = invoke(self.loc, obj, self.str_obj)1078 compare_types(type(obj_instance), int)1079 class Foo:1080 def __trunc__(self, localization):1081 return get_builtin_python_type_instance(localization, "int")1082 trunc_instance = Foo()1083 obj_instance = invoke(self.loc, obj, trunc_instance)1084 compare_types(type(obj_instance), int)1085 def test_format(self):1086 obj = get_builtin_python_type_instance(self.loc, "format")1087 compare_types(type(obj), types.BuiltinFunctionType)1088 obj_instance = invoke(self.loc, obj)1089 assert_if_not_error(obj_instance)1090 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)1091 assert_if_not_error(obj_instance)1092 obj_instance = invoke(self.loc, obj, self.int_obj)1093 compare_types(type(obj_instance), str)1094 obj_instance = invoke(self.loc, obj, self.str_obj)1095 compare_types(type(obj_instance), str)1096 obj_instance = invoke(self.loc, obj, self.str_obj, self.str_obj)1097 compare_types(type(obj_instance), str)1098 class Foo:1099 def __trunc__(self, localization):1100 return get_builtin_python_type_instance(localization, "int")1101 trunc_instance = Foo()1102 obj_instance = invoke(self.loc, obj, trunc_instance)1103 compare_types(type(obj_instance), str)1104 def test_max(self):1105 obj = get_builtin_python_type_instance(self.loc, "max")1106 compare_types(type(obj), types.BuiltinFunctionType)1107 obj_instance = invoke(self.loc, obj)1108 assert_if_not_error(obj_instance)1109 obj_instance = invoke(self.loc, obj, self.int_obj)1110 assert_if_not_error(obj_instance)1111 obj_instance = invoke(self.loc, obj, self.str_obj)1112 compare_types(type(obj_instance), str)1113 obj_instance = invoke(self.loc, obj, self.int_obj, self.float_obj)1114 compare_types(obj_instance, [self.int_obj, self.float_obj])1115 obj_instance = invoke(self.loc, obj, self.int_obj, self.float_obj, self.int_obj, self.float_obj, self.int_obj,1116 self.float_obj, self.int_obj, self.float_obj)1117 compare_types(obj_instance, [self.int_obj, self.float_obj])1118 tuple_ = get_builtin_python_type_instance(self.loc, "tuple")1119 set_contained_elements_type(self.loc, tuple_, self.float_obj)1120 obj_instance = invoke(self.loc, obj, tuple_)1121 compare_types(type(obj_instance), float)1122 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")1123 obj_instance = invoke(self.loc, obj, list_)1124 compare_types(obj_instance, [complex(), str()])1125 list_ = self.type_store.get_type_of(Localization(__file__), "int_list")1126 obj_instance = invoke(self.loc, obj, list_)1127 compare_types(type(obj_instance), int)1128 def func(localization, *args, **kwargs):1129 return get_builtin_python_type_instance(localization, "int")1130 dict = {'key': func}1131 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")1132 obj_instance = invoke(self.loc, obj, list_, **dict)1133 compare_types(obj_instance, [complex(), str()])1134 def test_reversed(self):1135 obj = get_builtin_python_type_instance(self.loc, "reversed")1136 assert_equal_type_name(obj, "reversed")1137 obj_instance = invoke(self.loc, obj)1138 assert_if_not_error(obj_instance)1139 obj_instance = invoke(self.loc, obj, self.int_obj)1140 assert_if_not_error(obj_instance)1141 list_ = self.type_store.get_type_of(Localization(__file__), "int_list")1142 obj_instance = invoke(self.loc, obj, list_)1143 compare_types(obj_instance, reversed)1144 compare_types(type(get_elements_type(obj_instance)), int)1145 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")1146 obj_instance = invoke(self.loc, obj, list_)1147 compare_types(obj_instance, reversed)1148 compare_types(get_elements_type(obj_instance), [complex(), str()])1149 str_ = get_builtin_python_type_instance(self.loc, "str")1150 obj_instance = invoke(self.loc, obj, str_)1151 compare_types(obj_instance, reversed)1152 compare_types(get_elements_type(obj_instance), str())1153 def test_object(self):1154 obj = get_builtin_python_type_instance(self.loc, "object")1155 assert_equal_type_name(type(obj), "object")1156 obj = object1157 obj_instance = invoke(self.loc, obj)1158 compare_types(type(obj_instance), object)1159 obj_instance = invoke(self.loc, obj, self.int_obj)1160 assert_if_not_error(obj_instance)1161 def test_quit(self):1162 obj = get_builtin_python_type_instance(self.loc, "quit")1163 assert_equal_type_name(type(obj), "Quitter")1164 obj_instance = invoke(self.loc, obj)1165 compare_types(obj_instance, undefined_type.UndefinedType)1166 obj_instance = invoke(self.loc, obj, self.int_obj)1167 compare_types(obj_instance, undefined_type.UndefinedType)1168 def test_len(self):1169 obj = get_builtin_python_type_instance(self.loc, "len")1170 compare_types(type(obj), types.BuiltinFunctionType)1171 obj_instance = invoke(self.loc, obj)1172 assert_if_not_error(obj_instance)1173 obj_instance = invoke(self.loc, obj, self.int_obj)1174 assert_if_not_error(obj_instance)1175 class Foo:1176 def __len__(self, localization):1177 return get_builtin_python_type_instance(localization, "int")1178 class Foo2:1179 def __len__(self, localization):1180 return get_builtin_python_type_instance(localization, "str")1181 list_ = self.type_store.get_type_of(Localization(__file__), "int_list")1182 obj_instance = invoke(self.loc, obj, list_)1183 compare_types(type(obj_instance), int)1184 instance = Foo()1185 obj_instance = invoke(self.loc, obj, instance)1186 compare_types(type(obj_instance), int)1187 obj_instance = invoke(self.loc, obj, self.str_obj)1188 compare_types(type(obj_instance), int)1189 instance = Foo2()1190 obj_instance = invoke(self.loc, obj, instance)1191 assert_if_not_error(obj_instance)1192 def test_repr(self):1193 obj = get_builtin_python_type_instance(self.loc, "repr")1194 compare_types(type(obj), types.BuiltinFunctionType)1195 obj_instance = invoke(self.loc, obj)1196 assert_if_not_error(obj_instance)1197 obj_instance = invoke(self.loc, obj, self.int_obj)1198 compare_types(type(obj_instance), str)1199 class Foo:1200 def __repr__(self, localization):1201 return get_builtin_python_type_instance(localization, "str")1202 class Foo2:1203 def __repr__(self, localization):1204 return get_builtin_python_type_instance(localization, "int")1205 list_ = self.type_store.get_type_of(Localization(__file__), "int_list")1206 obj_instance = invoke(self.loc, obj, list_)1207 compare_types(type(obj_instance), str)1208 instance = Foo()1209 obj_instance = invoke(self.loc, obj, instance)1210 compare_types(type(obj_instance), str)1211 obj_instance = invoke(self.loc, obj, self.str_obj)1212 compare_types(type(obj_instance), str)1213 instance = Foo2()1214 obj_instance = invoke(self.loc, obj, instance)1215 assert_if_not_error(obj_instance)1216 def test_callable(self):1217 obj = get_builtin_python_type_instance(self.loc, "callable")1218 # self.assert_equal_type_name(obj, "__builtin__.quit")1219 compare_types(type(obj), types.BuiltinFunctionType)1220 obj_instance = invoke(self.loc, obj)1221 assert_if_not_error(obj_instance)1222 obj_instance = invoke(self.loc, obj, self.int_obj)1223 compare_types(type(obj_instance), bool)1224 def test_credits(self):1225 obj = get_builtin_python_type(self.loc, "credits")1226 assert_equal_type_name(type(obj), "_Printer")1227 obj_instance = invoke(self.loc, obj)1228 compare_types(type(obj_instance), types.NoneType)1229 obj_instance = invoke(self.loc, obj, self.int_obj)1230 assert_if_not_error(obj_instance)1231 def test_tuple(self):1232 obj = get_builtin_python_type(self.loc, "tuple")1233 compare_types(obj, tuple)1234 obj_instance = invoke(self.loc, obj)1235 compare_types(obj_instance, tuple)1236 obj_instance = invoke(self.loc, obj, self.int_obj)1237 assert_if_not_error(obj_instance)1238 obj_instance = invoke(self.loc, obj, self.str_obj)1239 compare_types(obj_instance, tuple)1240 compare_types(type(get_elements_type(obj_instance)), str)1241 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")1242 obj_instance = invoke(self.loc, obj, list_)1243 compare_types(get_elements_type(obj_instance), [complex(), str()])1244 obj_instance = invoke(self.loc, obj, self.str_obj, self.int_obj)1245 assert_if_not_error(obj_instance)1246 list_ = self.type_store.get_type_of(Localization(__file__), "int_list")1247 obj_instance = invoke(self.loc, obj, list_)1248 compare_types(obj_instance, tuple)1249 compare_types(type(get_elements_type(obj_instance)), int)1250 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list")1251 obj_instance = invoke(self.loc, obj, list_)1252 compare_types(obj_instance, tuple)1253 compare_types(get_elements_type(obj_instance), [int(), str()])1254 def test_eval(self):1255 obj = get_builtin_python_type_instance(self.loc, "eval")1256 compare_types(type(obj), types.BuiltinFunctionType)1257 obj_instance = invoke(self.loc, obj)1258 assert_if_not_error(obj_instance)1259 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)1260 assert_if_not_error(obj_instance)1261 code = get_builtin_python_type_instance(self.loc, "CodeType")1262 obj_instance = invoke(self.loc, obj, code)1263 compare_types(type(obj_instance), DynamicType)1264 dict_ = get_builtin_python_type_instance(self.loc, "dict")1265 obj_instance = invoke(self.loc, obj, code, dict_)1266 compare_types(type(obj_instance), DynamicType)1267 obj_instance = invoke(self.loc, obj, code, dict_, dict_)1268 assert_if_not_error(obj_instance)1269 obj_instance = invoke(self.loc, obj, code, dict_, dict_, dict_)1270 assert_if_not_error(obj_instance)1271 str_ = get_builtin_python_type_instance(self.loc, "str")1272 obj_instance = invoke(self.loc, obj, str_, dict_, dict_)1273 compare_types(type(obj_instance), DynamicType)1274 def test_frozenset(self):1275 obj = get_builtin_python_type(self.loc, "frozenset")1276 compare_types(obj, frozenset)1277 obj_instance = invoke(self.loc, obj)1278 compare_types(obj_instance, frozenset)1279 obj_instance = invoke(self.loc, obj, self.int_obj)1280 assert_if_not_error(obj_instance)1281 obj_instance = invoke(self.loc, obj, self.str_obj)1282 compare_types(obj_instance, frozenset)1283 compare_types(get_elements_type(obj_instance), str())1284 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")1285 obj_instance = invoke(self.loc, obj, list_)1286 compare_types(get_elements_type(obj_instance), [complex(), str()])1287 obj_instance = invoke(self.loc, obj, self.str_obj, self.int_obj)1288 assert_if_not_error(obj_instance)1289 list_ = self.type_store.get_type_of(Localization(__file__), "int_list")1290 obj_instance = invoke(self.loc, obj, list_)1291 compare_types(obj_instance, frozenset)1292 compare_types(get_elements_type(obj_instance), int())1293 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list")1294 obj_instance = invoke(self.loc, obj, list_)1295 compare_types(obj_instance, frozenset)1296 compare_types(get_elements_type(obj_instance), [int(), str()])1297 def test_sorted(self):1298 obj = get_builtin_python_type_instance(self.loc, "sorted")1299 compare_types(type(obj), types.BuiltinFunctionType)1300 obj_instance = invoke(self.loc, obj)1301 assert_if_not_error(obj_instance)1302 obj_instance = invoke(self.loc, obj, self.int_obj)1303 assert_if_not_error(obj_instance)1304 list_ = self.type_store.get_type_of(Localization(__file__), "int_list")1305 obj_instance = invoke(self.loc, obj, list_)1306 compare_types(obj_instance, list)1307 compare_types(type(get_elements_type(obj_instance)), int)1308 def my_func1(localization, *args, **kwargs):1309 param1 = get_builtin_python_type_instance(localization, "str", args[0])1310 return param11311 func = my_func11312 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list")1313 obj_instance = invoke(self.loc, obj, list_, func)1314 compare_types(obj_instance, list)1315 compare_types(get_elements_type(obj_instance), [int(), str()])1316 obj_instance = invoke(self.loc, obj, list_, func, func)1317 compare_types(obj_instance, list)1318 compare_types(get_elements_type(obj_instance), [int(), str()])1319 bool_obj = get_builtin_python_type_instance(self.loc, "bool")1320 obj_instance = invoke(self.loc, obj, list_, func, func, bool_obj)1321 compare_types(obj_instance, list)1322 compare_types(get_elements_type(obj_instance), [int(), str()])1323 # str1324 str_ = get_builtin_python_type_instance(self.loc, "str")1325 obj_instance = invoke(self.loc, obj, str_)1326 compare_types(obj_instance, list)1327 compare_types(type(get_elements_type(obj_instance)), str)1328 func = my_func11329 obj_instance = invoke(self.loc, obj, str_, func)1330 compare_types(obj_instance, list)1331 compare_types(type(get_elements_type(obj_instance)), str)1332 obj_instance = invoke(self.loc, obj, str_, func, func)1333 compare_types(obj_instance, list)1334 compare_types(type(get_elements_type(obj_instance)), str)1335 bool_obj = get_builtin_python_type_instance(self.loc, "bool")1336 obj_instance = invoke(self.loc, obj, str_, func, func, bool_obj)1337 compare_types(obj_instance, list)1338 compare_types(type(get_elements_type(obj_instance)), str)1339 def test_ord(self):1340 obj = get_builtin_python_type_instance(self.loc, "ord")1341 compare_types(type(obj), types.BuiltinFunctionType)1342 obj_instance = invoke(self.loc, obj)1343 assert_if_not_error(obj_instance)1344 obj_instance = invoke(self.loc, obj, self.int_obj)1345 assert_if_not_error(obj_instance)1346 list_ = self.type_store.get_type_of(Localization(__file__), "int_list")1347 obj_instance = invoke(self.loc, obj, list_)1348 assert_if_not_error(obj_instance)1349 str_ = get_builtin_python_type_instance(self.loc, "str")1350 obj_instance = invoke(self.loc, obj, str_)1351 compare_types(type(obj_instance), int)1352 def test_super(self):1353 obj = get_builtin_python_type(self.loc, "super")1354 compare_types(obj, super)1355 obj_instance = invoke(self.loc, obj)1356 assert_if_not_error(obj_instance)1357 int_class = get_builtin_python_type(self.loc, "int")1358 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)1359 assert_if_not_error(obj_instance)1360 obj_instance = invoke(self.loc, obj, int_class)1361 compare_types(type(obj_instance), super)1362 compare_types(get_member(self.loc, obj_instance, "__thisclass__"), int)1363 compare_types(get_member(self.loc, obj_instance, "__self_class__"), None)1364 str_class = get_builtin_python_type(self.loc, "str")1365 obj_instance = invoke(self.loc, obj, str_class)1366 compare_types(type(obj_instance), super)1367 compare_types(get_member(self.loc, obj_instance, "__thisclass__"), str)1368 compare_types(get_member(self.loc, obj_instance, "__self_class__"), None)1369 obj_instance = invoke(self.loc, obj, str_class, self.str_obj)1370 compare_types(type(obj_instance), super)1371 compare_types(get_member(self.loc, obj_instance, "__thisclass__"), str)1372 compare_types(get_member(self.loc, obj_instance, "__self_class__"), str)1373 obj_instance = invoke(self.loc, obj, self.str_obj, self.str_obj)1374 assert_if_not_error(obj_instance)1375 class Foo(object):1376 att = int1377 def func(self, localization):1378 return get_builtin_python_type_instance(localization, "int")1379 foo_class = Foo1380 foo_instance = Foo()1381 obj_instance = invoke(self.loc, obj, foo_class, foo_instance)1382 compare_types(type(obj_instance), super)1383 compare_types(get_member(self.loc, obj_instance, "__thisclass__"), foo_class)1384 compare_types(get_member(self.loc, obj_instance, "__self_class__"), foo_class)1385 def test_hasattr(self):1386 obj = get_builtin_python_type_instance(self.loc, "hasattr")1387 compare_types(type(obj), types.BuiltinFunctionType)1388 obj_instance = invoke(self.loc, obj)1389 assert_if_not_error(obj_instance)1390 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)1391 assert_if_not_error(obj_instance)1392 obj_instance = invoke(self.loc, obj, self.int_obj)1393 assert_if_not_error(obj_instance)1394 obj_instance = invoke(self.loc, obj, self.str_obj)1395 assert_if_not_error(obj_instance)1396 obj_instance = invoke(self.loc, obj, self.str_obj, self.str_obj)1397 compare_types(type(obj_instance), bool)1398 class Foo:1399 att = int1400 def func(self, localization):1401 return get_builtin_python_type_instance(localization, "int")1402 foo_class = Foo1403 foo_instance = Foo()1404 att_str = get_builtin_python_type_instance(self.loc, "str", value="att")1405 func_str = get_builtin_python_type_instance(self.loc, "str", value="func")1406 ne_str = get_builtin_python_type_instance(self.loc, "str", value="ne")1407 obj_instance = invoke(self.loc, obj, foo_class, att_str)1408 compare_types(type(obj_instance), bool)1409 compare_types(obj_instance, True)1410 obj_instance = invoke(self.loc, obj, foo_class, func_str)1411 compare_types(type(obj_instance), bool)1412 compare_types(obj_instance, True)1413 obj_instance = invoke(self.loc, obj, foo_class, ne_str)1414 compare_types(type(obj_instance), bool)1415 compare_types(obj_instance, False)1416 obj_instance = invoke(self.loc, obj, foo_instance, att_str)1417 compare_types(type(obj_instance), bool)1418 compare_types(obj_instance, True)1419 obj_instance = invoke(self.loc, obj, foo_instance, func_str)1420 compare_types(type(obj_instance), bool)1421 compare_types(obj_instance, True)1422 obj_instance = invoke(self.loc, obj, foo_instance, ne_str)1423 compare_types(type(obj_instance), bool)1424 compare_types(obj_instance, False)1425 def test_delattr(self):1426 obj = get_builtin_python_type_instance(self.loc, "delattr")1427 compare_types(type(obj), types.BuiltinFunctionType)1428 obj_instance = invoke(self.loc, obj)1429 assert_if_not_error(obj_instance)1430 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)1431 assert_if_not_error(obj_instance)1432 obj_instance = invoke(self.loc, obj, self.int_obj)1433 assert_if_not_error(obj_instance)1434 obj_instance = invoke(self.loc, obj, self.str_obj)1435 assert_if_not_error(obj_instance)1436 obj_instance = invoke(self.loc, obj, self.str_obj, self.str_obj)1437 assert_if_not_error(obj_instance)1438 class Foo:1439 att = int1440 def func(self, localization):1441 return get_builtin_python_type_instance(localization, "int")1442 foo_class = Foo1443 foo_instance = Foo()1444 att_str = get_builtin_python_type_instance(self.loc, "str", value="att")1445 func_str = get_builtin_python_type_instance(self.loc, "str", value="func")1446 ne_str = get_builtin_python_type_instance(self.loc, "str", value="ne")1447 obj_instance = invoke(self.loc, obj, foo_class, att_str)1448 compare_types(type(obj_instance), types.NoneType)1449 obj_instance = invoke(self.loc, obj, foo_class, func_str)1450 compare_types(type(obj_instance), types.NoneType)1451 obj_instance = invoke(self.loc, obj, foo_class, ne_str)1452 assert_if_not_error(obj_instance)1453 obj = get_builtin_python_type_instance(self.loc, "hasattr")1454 obj_instance = invoke(self.loc, obj, foo_class, att_str)1455 compare_types(type(obj_instance), bool)1456 compare_types(obj_instance, False)1457 obj_instance = invoke(self.loc, obj, foo_class, func_str)1458 compare_types(type(obj_instance), bool)1459 compare_types(obj_instance, False)1460 obj_instance = invoke(self.loc, obj, foo_class, ne_str)1461 compare_types(type(obj_instance), bool)1462 compare_types(obj_instance, False)1463 obj_instance = invoke(self.loc, obj, foo_instance, att_str)1464 compare_types(type(obj_instance), bool)1465 compare_types(obj_instance, False)1466 obj_instance = invoke(self.loc, obj, foo_instance, func_str)1467 compare_types(type(obj_instance), bool)1468 compare_types(obj_instance, False)1469 obj_instance = invoke(self.loc, obj, foo_instance, ne_str)1470 compare_types(type(obj_instance), bool)1471 compare_types(obj_instance, False)1472 def test_dict(self):1473 obj = get_builtin_python_type(self.loc, "dict")1474 compare_types(obj, dict)1475 obj_instance = invoke(self.loc, obj)1476 compare_types(obj_instance, dict)1477 obj_instance = invoke(self.loc, obj, self.int_obj)1478 assert_if_not_error(obj_instance)1479 obj_instance = invoke(self.loc, obj, self.str_obj)1480 assert_if_not_error(obj_instance)1481 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")1482 tuple_obj = get_builtin_python_type(self.loc, "tuple")1483 tuple1 = invoke(self.loc, tuple_obj, list_)1484 list_param1 = get_builtin_python_type_instance(self.loc, "list")1485 self.type_store.set_type_of(self.loc, "list_param1", list_param1)1486 append = self.type_store.get_type_of_member(self.loc, list_param1, "append")1487 invoke(self.loc, append, tuple1)1488 obj_instance = invoke(self.loc, obj, list_param1)1489 keys = obj_instance.keys()1490 values = obj_instance.values()1491 self.assertTrue(1492 get_builtin_python_type_instance(self.loc,1493 "complex") in keys and get_builtin_python_type_instance(1494 self.loc, "str") in keys)1495 list_ = self.type_store.get_type_of(Localization(__file__), "int_list")1496 tuple_obj = get_builtin_python_type(self.loc, "tuple")1497 tuple1 = invoke(self.loc, tuple_obj, list_)1498 list_param2 = get_builtin_python_type_instance(self.loc, "list")1499 self.type_store.set_type_of(self.loc, "list_param2", list_param2)1500 append = self.type_store.get_type_of_member(self.loc, list_param2, "append")1501 invoke(self.loc, append, tuple1)1502 obj_instance = invoke(self.loc, obj, list_param2)1503 keys = obj_instance.keys()1504 values = obj_instance.values()1505 self.assertTrue(isinstance(keys[0], int))1506 self.assertTrue(isinstance(values[0], int))1507 obj_instance2 = invoke(self.loc, obj, obj_instance)1508 compare_types(obj_instance2, dict)1509 keys = obj_instance2.keys()1510 values = obj_instance2.values()1511 self.assertTrue(isinstance(keys[0], int))1512 self.assertTrue(isinstance(values[0], int))1513 obj_instance = invoke(self.loc, obj, self.str_obj, self.int_obj)1514 assert_if_not_error(obj_instance)1515 def test_setattr(self):1516 obj = get_builtin_python_type_instance(self.loc, "setattr")1517 compare_types(type(obj), types.BuiltinFunctionType)1518 obj_instance = invoke(self.loc, obj)1519 assert_if_not_error(obj_instance)1520 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)1521 assert_if_not_error(obj_instance)1522 obj_instance = invoke(self.loc, obj, self.int_obj)1523 assert_if_not_error(obj_instance)1524 obj_instance = invoke(self.loc, obj, self.str_obj)1525 assert_if_not_error(obj_instance)1526 obj_instance = invoke(self.loc, obj, self.str_obj, self.str_obj)1527 assert_if_not_error(obj_instance)1528 class Foo:1529 pass1530 foo_class = Foo1531 foo_instance = Foo()1532 att_str = get_builtin_python_type_instance(self.loc, "str", value="att")1533 func_str = get_builtin_python_type_instance(self.loc, "str", value="func")1534 ne_str = get_builtin_python_type_instance(self.loc, "str", value="ne")1535 val = get_builtin_python_type_instance(self.loc, "int")1536 obj_instance = invoke(self.loc, obj, foo_class, att_str, val)1537 compare_types(type(obj_instance), types.NoneType)1538 obj_instance = invoke(self.loc, obj, foo_class, func_str, val)1539 compare_types(type(obj_instance), types.NoneType)1540 obj = get_builtin_python_type_instance(self.loc, "hasattr")1541 obj_instance = invoke(self.loc, obj, foo_class, att_str)1542 compare_types(type(obj_instance), bool)1543 compare_types(obj_instance, True)1544 obj_instance = invoke(self.loc, obj, foo_class, func_str)1545 compare_types(type(obj_instance), bool)1546 compare_types(obj_instance, True)1547 obj_instance = invoke(self.loc, obj, foo_class, ne_str)1548 compare_types(type(obj_instance), bool)1549 compare_types(obj_instance, False)1550 obj_instance = invoke(self.loc, obj, foo_instance, att_str)1551 compare_types(type(obj_instance), bool)1552 compare_types(obj_instance, True)1553 obj_instance = invoke(self.loc, obj, foo_instance, func_str)1554 compare_types(type(obj_instance), bool)1555 compare_types(obj_instance, True)1556 obj_instance = invoke(self.loc, obj, foo_instance, ne_str)1557 compare_types(type(obj_instance), bool)1558 compare_types(obj_instance, False)1559 def test_license(self):1560 obj = get_builtin_python_type_instance(self.loc, "license")1561 assert_equal_type_name(type(obj), "_Printer")1562 obj_instance = invoke(self.loc, obj)1563 compare_types(type(obj_instance), types.NoneType)1564 obj_instance = invoke(self.loc, obj, self.int_obj)1565 assert_if_not_error(obj_instance)1566 def test_classmethod(self):1567 obj = get_builtin_python_type(self.loc, "classmethod")1568 compare_types(obj, classmethod)1569 obj_instance = invoke(self.loc, obj)1570 assert_if_not_error(obj_instance)1571 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)1572 assert_if_not_error(obj_instance)1573 obj_instance = invoke(self.loc, obj, self.int_obj)1574 compare_types(type(obj_instance), classmethod)1575 class Foo:1576 def __oct__(self, localization):1577 return get_builtin_python_type_instance(localization, "int")1578 hex_instance = Foo()1579 obj_instance = invoke(self.loc, obj, hex_instance)1580 compare_types(type(obj_instance), classmethod)1581 def test_raw_input(self):1582 obj = get_builtin_python_type_instance(self.loc, "input")1583 assert_equal_type_name(obj, "input")1584 obj_instance = invoke(self.loc, obj)1585 compare_types(obj_instance, DynamicType)1586 obj_instance = invoke(self.loc, obj, self.int_obj)1587 compare_types(obj_instance, DynamicType)1588 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")1589 obj_instance = invoke(self.loc, obj, list_)1590 compare_types(obj_instance, DynamicType)1591 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)1592 assert_if_not_error(obj_instance)1593 def test_bytes(self):1594 obj = get_builtin_python_type(self.loc, "bytes")1595 compare_types(obj, bytes)1596 obj_instance = invoke(self.loc, obj)1597 compare_types(type(obj_instance), str)1598 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)1599 assert_if_not_error(obj_instance)1600 obj_instance = invoke(self.loc, obj, self.int_obj)1601 compare_types(type(obj_instance), str)1602 class Foo:1603 def __str__(self, localization):1604 return get_builtin_python_type_instance(localization, "int")1605 oct_instance = Foo()1606 obj_instance = invoke(self.loc, obj, oct_instance)1607 assert_if_not_error(obj_instance)1608 def test_iter(self):1609 obj = get_builtin_python_type_instance(self.loc, "iter")1610 compare_types(type(obj), types.BuiltinFunctionType)1611 obj_instance = invoke(self.loc, obj)1612 assert_if_not_error(obj_instance)1613 obj_instance = invoke(self.loc, obj, self.int_obj)1614 assert_if_not_error(obj_instance)1615 obj_instance = invoke(self.loc, obj, self.str_obj)1616 compare_types(obj_instance, ExtraTypeDefinitions.iterator)1617 compare_types(type(get_elements_type(obj_instance)), str)1618 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list2")1619 obj_instance = invoke(self.loc, obj, list_)1620 compare_types(obj_instance, ExtraTypeDefinitions.listiterator)1621 compare_types(get_elements_type(obj_instance), [complex(), str()])1622 obj_instance = invoke(self.loc, obj, self.str_obj, self.int_obj)1623 assert_if_not_error(obj_instance)1624 list_ = self.type_store.get_type_of(Localization(__file__), "int_list")1625 obj_instance = invoke(self.loc, obj, list_)1626 compare_types(obj_instance, ExtraTypeDefinitions.listiterator)1627 compare_types(type(get_elements_type(obj_instance)), int)1628 list_ = self.type_store.get_type_of(Localization(__file__), "mixed_type_list")1629 obj_instance = invoke(self.loc, obj, list_)1630 compare_types(obj_instance, ExtraTypeDefinitions.listiterator)1631 compare_types(get_elements_type(obj_instance), [int(), str()])1632 class Foo:1633 def __call__(self, localization, *args, **kwargs):1634 return float()1635 obj_instance = invoke(self.loc, obj, Foo(), int())1636 compare_types(obj_instance, ExtraTypeDefinitions.callable_iterator)1637 compare_types(type(get_elements_type(obj_instance)), float)1638 def test_compile(self):1639 obj = get_builtin_python_type_instance(self.loc, "compile")1640 compare_types(type(obj), types.BuiltinFunctionType)1641 obj_instance = invoke(self.loc, obj)1642 assert_if_not_error(obj_instance)1643 obj_instance = invoke(self.loc, obj, self.int_obj)1644 assert_if_not_error(obj_instance)1645 obj_instance = invoke(self.loc, obj, self.str_obj)1646 assert_if_not_error(obj_instance)1647 obj_instance = invoke(self.loc, obj, self.str_obj, self.str_obj, self.str_obj)1648 compare_types(type(obj_instance), DynamicType)1649 obj_instance = invoke(self.loc, obj, self.str_obj, self.str_obj, self.str_obj, self.int_obj, self.int_obj)1650 compare_types(type(obj_instance), DynamicType)1651 def test_reload(self):1652 obj = get_builtin_python_type_instance(self.loc, "reload")1653 compare_types(type(obj), types.BuiltinFunctionType)1654 obj_instance = invoke(self.loc, obj)1655 assert_if_not_error(obj_instance)1656 obj_instance = invoke(self.loc, obj, self.int_obj)1657 assert_if_not_error(obj_instance)1658 obj_instance = invoke(self.loc, obj, self.str_obj)1659 assert_if_not_error(obj_instance)1660 dest = Context(self.type_store, "func")1661 import_from_module(self.loc, "time", None, dest)1662 module_ = dest.get_type_of(self.loc, "time")1663 obj_instance = invoke(self.loc, obj, module_)1664 compare_types(obj_instance, module_)1665 dest.close_function_context()1666 def test_range(self):1667 obj = get_builtin_python_type_instance(self.loc, "range")1668 compare_types(type(obj), types.BuiltinFunctionType)1669 obj_instance = invoke(self.loc, obj)1670 assert_if_not_error(obj_instance)1671 obj_instance = invoke(self.loc, obj, self.float_obj)1672 assert_if_not_error(obj_instance)1673 obj_instance = invoke(self.loc, obj, self.int_obj)1674 compare_types(obj_instance, list)1675 compare_types(type(get_elements_type(obj_instance)), int)1676 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)1677 compare_types(obj_instance, list)1678 compare_types(type(get_elements_type(obj_instance)), int)1679 obj_instance = invoke(self.loc, obj, self.float_obj, self.int_obj)1680 assert_if_not_error(obj_instance)1681 obj_instance = invoke(self.loc, obj, self.str_obj)1682 assert_if_not_error(obj_instance)1683 obj_instance = invoke(self.loc, obj, self.int_obj, self.str_obj)1684 assert_if_not_error(obj_instance)1685 class Foo:1686 def __trunc__(self, localization):1687 return get_builtin_python_type_instance(localization, "int")1688 class Foo2:1689 def __trunc__(self, localization):1690 return get_builtin_python_type_instance(localization, "list")1691 trunc_instance = Foo()1692 wrong_instance = Foo2()1693 obj_instance = invoke(self.loc, obj, trunc_instance)1694 compare_types(obj_instance, list)1695 compare_types(type(get_elements_type(obj_instance)), int)1696 obj_instance = invoke(self.loc, obj, trunc_instance, self.int_obj)1697 compare_types(obj_instance, list)1698 compare_types(type(get_elements_type(obj_instance)), int)1699 obj_instance = invoke(self.loc, obj, trunc_instance, trunc_instance)1700 compare_types(obj_instance, list)1701 compare_types(type(get_elements_type(obj_instance)), int)1702 obj_instance = invoke(self.loc, obj, wrong_instance)1703 assert_if_not_error(obj_instance)1704 obj_instance = invoke(self.loc, obj, wrong_instance, self.int_obj)1705 assert_if_not_error(obj_instance)1706 obj_instance = invoke(self.loc, obj, wrong_instance, trunc_instance)1707 assert_if_not_error(obj_instance)1708 def test_staticmethod(self):1709 obj = get_builtin_python_type(self.loc, "staticmethod")1710 compare_types(obj, staticmethod)1711 obj_instance = invoke(self.loc, obj)1712 assert_if_not_error(obj_instance)1713 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)1714 assert_if_not_error(obj_instance)1715 obj_instance = invoke(self.loc, obj, self.int_obj)1716 compare_types(type(obj_instance), staticmethod)1717 class Foo:1718 def __oct__(self, localization):1719 return get_builtin_python_type_instance(localization, "int")1720 hex_instance = Foo()1721 obj_instance = invoke(self.loc, obj, hex_instance)1722 compare_types(type(obj_instance), staticmethod)1723 def test_str(self):1724 obj = get_builtin_python_type(self.loc, "str")1725 compare_types(obj, str)1726 obj_instance = invoke(self.loc, obj)1727 compare_types(type(obj_instance), str)1728 obj_instance = invoke(self.loc, obj, self.int_obj)1729 compare_types(type(obj_instance), str)1730 class Foo:1731 def __str__(self, localization):1732 return get_builtin_python_type_instance(localization, "str")1733 class Foo2:1734 def __str__(self, localization):1735 return get_builtin_python_type_instance(localization, "int")1736 list_ = self.type_store.get_type_of(Localization(__file__), "int_list")1737 obj_instance = invoke(self.loc, obj, list_)1738 compare_types(type(obj_instance), str)1739 instance = Foo()1740 obj_instance = invoke(self.loc, obj, instance)1741 compare_types(type(obj_instance), str)1742 obj_instance = invoke(self.loc, obj, self.str_obj)1743 compare_types(type(obj_instance), str)1744 instance = Foo2()1745 obj_instance = invoke(self.loc, obj, instance)1746 assert_if_not_error(obj_instance)1747 def test_complex(self):1748 obj = get_builtin_python_type(self.loc, "complex")1749 compare_types(obj, types.ComplexType)1750 obj_instance = invoke(self.loc, obj)1751 compare_types(type(obj_instance), complex)1752 obj_instance = invoke(self.loc, obj, self.float_obj)1753 compare_types(type(obj_instance), complex)1754 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)1755 compare_types(type(obj_instance), complex)1756 obj_instance = invoke(self.loc, obj, self.float_obj, self.int_obj)1757 compare_types(type(obj_instance), complex)1758 obj_instance = invoke(self.loc, obj, self.str_obj)1759 assert_if_not_error(obj_instance)1760 obj_instance = invoke(self.loc, obj, self.int_obj, self.str_obj)1761 assert_if_not_error(obj_instance)1762 class Foo:1763 def __float__(self, localization):1764 return get_builtin_python_type_instance(localization, "float")1765 class Foo2:1766 def __float__(self, localization):1767 return get_builtin_python_type_instance(localization, "list")1768 float_instance = Foo()1769 wrong_instance = Foo2()1770 obj_instance = invoke(self.loc, obj, float_instance)1771 compare_types(type(obj_instance), complex)1772 obj_instance = invoke(self.loc, obj, self.int_obj, float_instance)1773 compare_types(type(obj_instance), complex)1774 obj_instance = invoke(self.loc, obj, float_instance, float_instance)1775 compare_types(type(obj_instance), complex)1776 obj_instance = invoke(self.loc, obj, wrong_instance)1777 assert_if_not_error(obj_instance)1778 obj_instance = invoke(self.loc, obj, self.int_obj, wrong_instance)1779 assert_if_not_error(obj_instance)1780 obj_instance = invoke(self.loc, obj, wrong_instance, wrong_instance)1781 assert_if_not_error(obj_instance)1782 def test_property(self):1783 obj = get_builtin_python_type_instance(self.loc, "property")1784 compare_types(type(obj), property)1785 obj = property1786 obj_instance = invoke(self.loc, obj)1787 compare_types(type(obj_instance), property)1788 def get(self, localization):1789 return get_builtin_python_type_instance(localization, "int")1790 def set(self, localization, *args):1791 return get_builtin_python_type_instance(localization, "int")1792 def del_(self, localization):1793 return get_builtin_python_type_instance(localization, "int")1794 fget = get1795 fset = set1796 fdel = del_1797 fdoc = get_builtin_python_type_instance(self.loc, "str")1798 obj_instance = invoke(self.loc, obj, fget)1799 compare_types(type(obj_instance), property)1800 compare_types(type(get_member(self.loc, obj_instance, "fget")), types.FunctionType)1801 obj_instance = invoke(self.loc, obj, fget, fset)1802 compare_types(type(obj_instance), property)1803 compare_types(type(get_member(self.loc, obj_instance, "fget")), types.FunctionType)1804 compare_types(type(get_member(self.loc, obj_instance, "fset")), types.FunctionType)1805 obj_instance = invoke(self.loc, obj, fget, fset, fdel)1806 compare_types(type(obj_instance), property)1807 compare_types(type(get_member(self.loc, obj_instance, "fget")), types.FunctionType)1808 compare_types(type(get_member(self.loc, obj_instance, "fset")), types.FunctionType)1809 compare_types(type(get_member(self.loc, obj_instance, "fdel")), types.FunctionType)1810 obj_instance = invoke(self.loc, obj, fget, fset, fdel, fdoc)1811 compare_types(type(obj_instance), property)1812 compare_types(type(get_member(self.loc, obj_instance, "fget")), types.FunctionType)1813 compare_types(type(get_member(self.loc, obj_instance, "fset")), types.FunctionType)1814 compare_types(type(get_member(self.loc, obj_instance, "fdel")), types.FunctionType)1815 compare_types(type(get_member(self.loc, obj_instance, "__doc__")), str)1816 def test_round(self):1817 obj = get_builtin_python_type_instance(self.loc, "round")1818 compare_types(type(obj), types.BuiltinFunctionType)1819 obj_instance = invoke(self.loc, obj)1820 assert_if_not_error(obj_instance)1821 obj_instance = invoke(self.loc, obj, self.float_obj)1822 compare_types(type(obj_instance), float)1823 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)1824 compare_types(type(obj_instance), float)1825 obj_instance = invoke(self.loc, obj, self.float_obj, self.int_obj)1826 compare_types(type(obj_instance), float)1827 obj_instance = invoke(self.loc, obj, self.str_obj)1828 assert_if_not_error(obj_instance)1829 obj_instance = invoke(self.loc, obj, self.int_obj, self.str_obj)1830 assert_if_not_error(obj_instance)1831 class Foo:1832 def __float__(self, localization):1833 return get_builtin_python_type_instance(localization, "float")1834 class Foo2:1835 def __float__(self, localization):1836 return get_builtin_python_type_instance(localization, "list")1837 class Foo3:1838 def __index__(self, localization):1839 return get_builtin_python_type_instance(localization, "int")1840 float_instance = Foo()1841 wrong_instance = Foo2()1842 index_instance = Foo3()1843 obj_instance = invoke(self.loc, obj, float_instance)1844 compare_types(type(obj_instance), float)1845 obj_instance = invoke(self.loc, obj, float_instance, self.int_obj)1846 compare_types(type(obj_instance), float)1847 obj_instance = invoke(self.loc, obj, float_instance, index_instance)1848 compare_types(type(obj_instance), float)1849 obj_instance = invoke(self.loc, obj, wrong_instance)1850 assert_if_not_error(obj_instance)1851 obj_instance = invoke(self.loc, obj, wrong_instance, self.int_obj)1852 assert_if_not_error(obj_instance)1853 obj_instance = invoke(self.loc, obj, wrong_instance, self.int_obj, self.int_obj)1854 assert_if_not_error(obj_instance)1855 def test_dir(self):1856 obj = get_builtin_python_type_instance(self.loc, "dir")1857 compare_types(type(obj), types.BuiltinFunctionType)1858 obj_instance = invoke(self.loc, obj)1859 compare_types(obj_instance, list)1860 compare_types(type(get_elements_type(obj_instance)), str)1861 obj_instance = invoke(self.loc, obj, self.int_obj, self.int_obj)1862 assert_if_not_error(obj_instance)1863 obj_instance = invoke(self.loc, obj, self.int_obj)1864 compare_types(obj_instance, list)1865 compare_types(type(get_elements_type(obj_instance)), str)1866 class Foo:1867 def __oct__(self, localization):1868 return get_builtin_python_type_instance(localization, "int")1869 hex_instance = Foo()1870 obj_instance = invoke(self.loc, obj, hex_instance)1871 compare_types(obj_instance, list)1872 compare_types(type(get_elements_type(obj_instance)), str)1873 def test_cmp(self):1874 obj = get_builtin_python_type_instance(self.loc, "cmp")1875 compare_types(type(obj), types.BuiltinFunctionType)1876 obj_instance = invoke(self.loc, obj)1877 assert_if_not_error(obj_instance)1878 obj_instance = invoke(self.loc, obj, self.int_obj)1879 assert_if_not_error(obj_instance)1880 obj_instance = invoke(self.loc, obj, self.int_obj, self.str_obj)...
type_inferencer.py
Source:type_inferencer.py
...41 expr_infered = node.expr.inferenced_type42 self.visit(node.expr, scope)43 node_expr = self.update_type(node.expr.inferenced_type)44 node_expr = conforms(node_expr, node_type)45 node.inferenced_type = self.compare_types(type_infered, node_type)46 node.expr.inferenced_type = self.compare_types(expr_infered, node_expr)47 48 var = scope.find_variable(node.id)49 var.type = node.inferenced_type50 self.current_attrb = None51 @visitor.when(FuncDeclarationNode)52 def visit(self, node, scopex:Scope()):53 scope:Scope = scopex.next_child()54 self.current_method = self.current_type.get_method(node.id)55 for idx, typex in zip(self.current_method.param_names, self.current_method.param_types):56 var = scope.find_variable(idx)57 var.type = self.compare_types(var.type, typex)58 decl_inferred = node.inferenced_type59 expr_inferred = node.body.inferenced_type60 ret_type_decl = self.update_type(self.current_method.return_type)61 self.visit(node.body, scope)62 ret_type_expr = self.update_type(node.body.inferenced_type)63 conforms(ret_type_expr, ret_type_decl)64 print("Comapring inferenced type in FuncDecl")65 node.inferenced_type = self.compare_types(decl_inferred, ret_type_decl)66 print("Comapring Body inferenced type in FuncDecl")67 node.body.inferenced_type = self.compare_types(expr_inferred, ret_type_expr)68 if isinstance(self.current_method.return_type, AutoType):69 auto_return = self.current_method.return_type70 ret_type_decl = conforms(ret_type_decl, ret_type_expr)71 print("Comapring inferenced type in FuncDecl Once Agagin")72 node.inferenced_type = self.compare_types(decl_inferred, ret_type_decl)73 if is_subset(ret_type_decl, auto_return):74 self.current_method.return_type = ret_type_decl75 self.current_method = None76 @visitor.when(BlockNode)77 def visit(self, node, scope):78 for expr in node.body:79 self.visit(expr, scope)80 node.inferenced_type = node.body[-1].inferenced_type81 @visitor.when(IfDeclarationNode)82 def visit(self, node, scope):83 if_inferred = node.ifexpr.inferenced_type84 self.visit(node.ifexpr, scope)85 ifexpr_type = self.update_type(node.ifexpr.inferenced_type)86 bool_type = self.context.get_type("Bool")87 if isinstance(ifexpr_type, AutoType):88 ifexpr_type.set_upper_limmit([bool_type])89 node.ifexpr.inferenced_type = self.compare_types(if_inferred, ifexpr_type)90 self.visit(node.thenexpr, scope)91 then_type = self.update_type(node.thenexpr.inferenced_type)92 self.visit(node.elseexpr, scope)93 else_type = self.update_type(node.elseexpr.inferenced_type)94 node_inferred = node.inferenced_type95 joined = join(then_type, else_type)96 if not isinstance(joined, ErrorType):97 type_sets, heads = joined98 auto = AutoType("IF", heads, type_sets)99 else:100 auto = ErrorType()101 102 if is_subset(auto, node_inferred):103 node.inferenced_type = self.compare_types(node_inferred, auto)104 105 @visitor.when(CaseDeclarationNode)106 def visit(self, node, scope:Scope):107 self.visit(node.expr, scope)108 var_types = []109 for var in node.casevars:110 child = scope.next_child()111 self.visit(var, child)112 var_types.append(var.inferenced_type)113 node_inferred = node.inferenced_type114 auto = join_list(var_types)115 if is_subset(auto, node_inferred):116 node.inferenced_type = self.compare_types(node_inferred, auto)117 118 @visitor.when(WhileDeclarationNode)119 def visit(self, node, scope):120 while_inferred = node.whileexpr.inferenced_type121 body_inferred = node.bodyexpr.inferenced_type122 self.visit(node.whileexpr, scope)123 wh_expr = self.update_type(node.whileexpr.inferenced_type)124 if isinstance(wh_expr, AutoType):125 wh_expr.set_upper_limmit([self.context.get_type("Bool")])126 node.whileexpr.inferenced_type = self.compare_types(while_inferred, wh_expr)127 128 self.visit(node.bodyexpr, scope)129 body = self.update_type(node.bodyexpr.inferenced_type)130 node.bodyexpr.inferenced_type = self.compare_types(body_inferred, body)131 132 @visitor.when(LetDeclarationNode)133 def visit(self, node, scope):134 child = scope.next_child()135 for var in node.letvars:136 self.visit(var, child)137 node_inferred = node.inferenced_type138 self.visit(node.expr, child)139 node_type= self.update_type(node.expr.inferenced_type)140 node.inferenced_type = self.compare_types(node_inferred, node_type)141 142 @visitor.when(CaseVarNode)143 def visit(self, node, scope:Scope):144 node_infer = node.inferenced_type145 self.visit(node.expr, scope)146 expr_type = self.update_type(node.expr.inferenced_type)147 node.inferenced_type = self.compare_types(node_infer, expr_type)148 @visitor.when(VarDeclarationNode)149 def visit(self, node, scope:Scope):150 if node.define:151 node_type = scope.find_variable(node.id).type152 else:153 node_type = ErrorType()154 if node.expr:155 expr_inferr = node.expr.inferenced_type156 self.visit(node.expr, scope)157 expr_type = self.update_type(node.expr.inferenced_type)158 expr_type = conforms(expr_type, node_type)159 node.expr.inferenced_type = self.compare_types(expr_inferr, expr_type)160 161 node.inferenced_type = self.compare_types(node.inferenced_type, node_type)162 163 @visitor.when(AssignNode)164 def visit(self, node, scope:Scope):165 if not node.define:166 var = None167 var_type = ErrorType()168 else:169 var = scope.find_variable(node.id)170 var_type = var.type171 expr_inferred = node.expr.inferenced_type172 self.visit(node.expr, scope)173 node_expr = self.update_type(node.expr.inferenced_type)174 if node.define:175 node_expr = conforms(node_expr, var_type)176 node.expr.inferenced_type = self.compare_types(expr_inferred, node_expr)177 if isinstance(var_type, AutoType):178 var_type = conforms(var_type, node_expr)179 var.type = self.compare_types(var.type, var_type)180 node.inferenced_type = self.compare_types(node.inferenced_type, var_type)181 @visitor.when(CallNode)182 def visit(self, node, scope):183 if isinstance(node.inferenced_type, ErrorType):184 return185 if node.obj == None:186 obj_type = self.current_type187 elif isinstance(node.obj, tuple):188 self.visit(node.obj[0], scope)189 child_type = self.update_type(node.obj[0].inferenced_type)190 try:191 obj_type = self.context.get_type(node.obj[1], selftype=False, autotype=False)192 if isinstance(child_type, AutoType):193 child_type.set_upper_limmit([obj_type])194 except SemanticError:195 obj_type = ErrorType()196 else:197 self.visit(node.obj, scope)198 obj_type = self.update_type(node.obj.inferenced_type)199 200 method = None201 try:202 method = obj_type.get_method(node.id)203 except SemanticError:204 if isinstance(obj_type, AutoType):205 result = self.context.get_method_by_name(node.id, len(node.args))206 valid = []207 for meth, typex in result:208 if typex in obj_type.type_set:209 valid.append((meth, typex))210 if len(valid) > 1:211 error = f"Method \"{node.id}\" found in {len(valid)} unrelated types:\n"212 error += " -Found in: "213 error += ", ".join(typex.name for _, typex in valid)214 self.AddError(error)215 obj_type = ErrorType()216 elif len(valid) == 0:217 self.AddError(f"There is no method called {node.id} which takes {len(node.args)} paramters.")218 obj_type == ErrorType()219 else:220 method, types = valid[0]221 obj_type.set_upper_limmit([types])222 node.inferenced_obj_type = self.compare_types(node.inferenced_obj_type, obj_type)223 if method:224 type_set = set()225 heads = []226 ret_type = self.update_type(method.return_type)227 heads, type_set = smart_add(type_set, heads, ret_type)228 if len(node.args) == len(method.param_types):229 for i in range(len(node.args)):230 arg, param_type = node.args[i], method.param_types[i]231 arg_infer = arg.inferenced_type232 self.visit(arg, scope)233 arg_type = self.update_type(arg.inferenced_type)234 arg_type = conforms(arg_type, param_type)235 if isinstance(param_type, AutoType):236 param_type = conforms(param_type, arg_type)237 method.param_types[i] = self.compare_types(method.param_types[i], param_type)238 arg.inferenced_type = self.compare_types(arg_infer, arg_type)239 240 inferred = node.inferenced_type241 if isinstance(ret_type, AutoType) and is_subset(inferred, ret_type):242 method.return_type.set_upper_limmit(heads)243 node.inferenced_type = self.compare_types(inferred, method.return_type)244 elif is_subset(ret_type, inferred):245 node.inferenced_type = self.compare_types(inferred, ret_type)246 else:247 node.inferenced_type = ErrorType()248 @visitor.when(OperationNode)249 def visit(self, node, scope):250 left_infer = node.left.inferenced_type251 self.visit(node.left, scope)252 left_type = self.update_type(node.left.inferenced_type)253 254 right_infer = node.right.inferenced_type255 self.visit(node.right, scope)256 right_type = self.update_type(node.right.inferenced_type)257 258 int_type = self.context.get_type("Int")259 if isinstance(left_type, AutoType):260 left_type.set_upper_limmit([int_type])261 node.left.inferenced_type = self.compare_types(left_infer, left_type)262 263 if isinstance(right_type, AutoType):264 right_type.set_upper_limmit([int_type])265 node.right.inferenced_type = self.compare_types(right_infer, right_type)266 @visitor.when(ComparisonNode)267 def visit(self, node, scope):268 left_infer = node.left.inferenced_type269 self.visit(node.left, scope)270 left_type = self.update_type(node.left.inferenced_type)271 right_infer = node.right.inferenced_type272 self.visit(node.right, scope)273 right_type = self.update_type(node.right.inferenced_type)274 left_type = conforms(left_type, right_type)275 node.left.inferenced_type = self.compare_types(left_infer, left_type)276 right_type = conforms(right_type, left_type)277 node.right.inferenced_type = self.compare_types(right_infer, right_type)278 279 node.inferenced_type = self.context.get_type("Bool")# if len(right_type.type_set) > 0 and len(left_type.type_set) > 0 else ErrorType()280 281 @visitor.when(NotNode)282 def visit(self, node, scope):283 lex_infer = node.lex.inferenced_type284 self.visit(node.lex, scope)285 lex_type = self.update_type(node.lex.inferenced_type)286 bool_type = self.context.get_type("Bool")287 if isinstance(lex_type, AutoType):288 lex_type.set_upper_limmit([bool_type])289 node.lex.inferenced_type = self.compare_types(lex_infer, lex_type)290 node.inferenced_type = bool_type291 292 @visitor.when(HyphenNode)293 def visit(self, node, scope):294 lex_infer = node.lex.inferenced_type295 self.visit(node.lex, scope)296 lex_type = self.update_type(node.lex.inferenced_type)297 int_type = self.context.get_type("Int")298 if isinstance(lex_type, AutoType):299 lex_type.set_upper_limmit([int_type])300 node.lex.inferenced_type = self.compare_types(lex_infer, lex_type)301 node.inferenced_type = int_type302 303 @visitor.when(IsVoidDeclarationNode)304 def visit(self, node, scope):305 lex_infer = node.lex.inferenced_type306 self.visit(node.lex, scope)307 lex_type = self.update_type(node.lex.inferenced_type)308 node.lex.inferenced_type = self.compare_types(lex_infer, lex_type)309 310 @visitor.when(VariableNode)311 def visit(self, node, scope):312 313 if node.define:314 var = scope.find_variable(node.lex)315 var.type = self.update_type(var.type)316 var_type =var.type317 else:318 var_type = ErrorType()319 node.inferenced_type = self.compare_types(node.inferenced_type, var_type)320 @visitor.when(InstantiateNode)321 def visit(self, node, scope):322 pass323 324 @visitor.when(ConstantNumNode)325 def visit(self, node, scope):326 pass327 328 @visitor.when(ConstantStringNode)329 def visit(self, node, scope):330 pass331 332 @visitor.when(ConstantBoolNode)333 def visit(self, node, scope):334 pass335 def update_type(self, typex:Type):336 if isinstance(typex, SelfType):337 typex = self.current_type338 return typex339 def compare_types(self, old_type, new_type):340 if isinstance(old_type, ErrorType) or isinstance(new_type, ErrorType):341 return ErrorType()342 343 if isinstance(old_type, AutoType) and isinstance(new_type, AutoType):344 if len(old_type.type_set) == len(new_type.type_set) and len(old_type.type_set.intersection(new_type.type_set)) == len(new_type.type_set):345 return new_type346 print(f"Chaged ocurred while comparing {old_type.name} and {new_type.name}")347 print("old_type set:", ", ".join(typex.name for typex in old_type.type_set))348 print("new_type set:", ", ".join(typex.name for typex in new_type.type_set))349 print("old_type cond:", [[typex.name for typex in type_set] for type_set in old_type.conditions_list])350 print("new_type cond:", [[typex.name for typex in type_set] for type_set in new_type.conditions_list])351 self.types_updated = True352 if len(new_type.type_set) > 0:353 return new_type...
test_union_type.py
Source:test_union_type.py
...15 StypyTypeError.reset_error_msgs()16 TypeWarning.reset_warning_msgs()17 def test_create_union_type_with_vars(self):18 union = UnionType.add(int, str)19 compare_types(union, [int, str])20 union2 = UnionType(union, list)21 compare_types(union, [int, str])22 compare_types(union2, [int, str, list])23 self.assertFalse(union == union2)24 clone = UnionType.add(int, str)25 self.assertTrue(union == clone)26 def test_create_union_type_with_funcs(self):27 def foo():28 pass29 union = UnionType.add(foo, range)30 compare_types(union, [foo, range])31 union2 = UnionType(union, getattr)32 compare_types(union, [foo, range])33 compare_types(union2, [foo, range, getattr])34 self.assertFalse(union == union2)35 clone = UnionType.add(foo, range)36 self.assertTrue(union == clone)37 def test_create_union_type_with_classes(self):38 class Foo:39 pass40 union = UnionType.add(Foo, AssertionError)41 compare_types(union, [Foo, AssertionError])42 union2 = UnionType(union, object)43 compare_types(union2, [Foo, AssertionError, object])44 clone = UnionType.add(Foo, AssertionError)45 self.assertFalse(union == union2)46 self.assertTrue(union == clone)47 def test_create_union_type_with_instances(self):48 class Foo:49 pass50 foo_inst = Foo()51 assert_inst = AssertionError()52 object_inst = object()53 union = UnionType.add(foo_inst, assert_inst)54 compare_types(union, [foo_inst, assert_inst])55 union2 = UnionType(union, object_inst)56 compare_types(union2, [foo_inst, assert_inst, object_inst])57 clone = UnionType.add(foo_inst, assert_inst)58 self.assertFalse(union == union2)59 self.assertTrue(union == clone)60 clone2 = UnionType.add(foo_inst, AssertionError())61 self.assertFalse(union == clone2)62 def test_create_union_type_with_modules(self):63 import math64 import sys65 import types66 union = UnionType.add(math, sys)67 compare_types(union, [math, sys])68 clone = UnionType.add(math, sys)69 compare_types(union, clone.types)70 union2 = UnionType.add(clone, types)71 compare_types(union2, [math, sys, types])72 self.assertFalse(union == union2)73 def test_create_union_type_with_mixed_types(self):74 int_var = int75 def fun():76 pass77 class Foo:78 def method(self):79 pass80 def method_2(self):81 pass82 class_var = Foo83 method_var = Foo.method84 instance_var = Foo()85 import math86 module_var = math87 union = UnionType.create_from_type_list([int_var, fun, class_var, method_var, instance_var,88 module_var])89 compare_types(union, [int_var, fun, class_var, method_var, instance_var,90 module_var])91 clone = UnionType.create_from_type_list([int_var, fun, class_var, method_var, instance_var,92 module_var])93 compare_types(union, clone)94 method2_var = Foo.method_295 UnionType.add(clone, types)96 UnionType.add(clone, method2_var)97 compare_types(union, [int_var, fun, class_var, method_var, instance_var,98 module_var])99 compare_types(clone, [int_var, fun, class_var, method_var, instance_var,100 module_var, method2_var,101 types102 ])103 def test_merge_union_types(self):104 int_var = int105 def fun():106 pass107 class Foo:108 def method(self):109 pass110 def method_2(self):111 pass112 class_var = Foo113 method_var = Foo.method114 instance_var = Foo()115 import math116 module_var = math117 union1 = UnionType.create_from_type_list([int_var, fun, class_var])118 union2 = UnionType.create_from_type_list([method_var, instance_var,119 module_var])120 compare_types(union1, [int_var, fun, class_var])121 compare_types(union2, [method_var, instance_var, module_var])122 fused_union = UnionType.add(union1, union2)123 compare_types(fused_union, [int_var, fun, class_var, method_var, instance_var,124 module_var])125 clone = UnionType.create_from_type_list([int_var, fun, class_var, method_var, instance_var,126 module_var])127 compare_types(fused_union, clone)128 method2_var = Foo.method_2129 UnionType.add(clone, types)130 UnionType.add(clone, method2_var)131 compare_types(fused_union, [int_var, fun, class_var, method_var, instance_var,132 module_var])133 compare_types(clone, [int_var, fun, class_var, method_var, instance_var,134 module_var, method2_var,135 types])136 clone2 = UnionType.create_from_type_list([int_var, fun, class_var, method_var, instance_var,137 module_var, method2_var,138 types])139 self.assertFalse(fused_union == clone)140 compare_types(clone2, clone)141 # ############################## TYPE-BOUND TESTS ###############################142 def test_get_type_of_member(self):143 context = Context(None, __file__)144 # Access a member that none of the stored types has145 union1 = UnionType.add(int,146 str)147 ret = union1.foo148 assert_if_not_error(ret)149 class Foo:150 att1 = int151 def method(self):152 pass153 def method_2(self):154 pass155 class Foo2:156 att1 = float157 def method(self):158 pass159 def method_2(self):160 pass161 # Access a member that can be provided only by some of the types in the union162 union2 = UnionType.add(Foo, str)163 ret = union2.method164 self.assertTrue(len(TypeWarning.get_warning_msgs()) == 1)165 TypeWarning.reset_warning_msgs()166 compare_types(ret, Foo.method)167 instance1 = Foo()168 union3 = UnionType.add(instance1, str)169 instance2 = Foo2()170 union3 = UnionType.add(instance2, union3)171 ret = union3.method172 self.assertTrue(len(TypeWarning.get_warning_msgs()) == 1)173 compare_types(ret, [instance1.method,174 instance2.method,175 ])176 TypeWarning.reset_warning_msgs()177 # Access a member that can be provided by all the types in the union178 union4 = UnionType.add(Foo, Foo2)179 self.assertTrue(len(TypeWarning.get_warning_msgs()) == 0)180 ret = union4.method181 compare_types(ret, [Foo.method,182 Foo2.method])183 ret = union4.att1184 compare_types(ret, [int, float])185 # Access a member that can be provided by all the types in the union (using only Python types)186 union5 = UnionType.add(int, str)187 self.assertTrue(len(TypeWarning.get_warning_msgs()) == 0)188 context.set_type_of(self.loc, "union5", union5)189 # "__str__" is a special method so we have to use the context to access to it190 ret = context.get_type_of_member(self.loc, union5, "__str__")191 compare_types(ret, [int.__str__,192 str.__str__])193 def test_set_type_of_member(self):194 # Set a member on non-modifiable types195 union1 = UnionType.add(int, str)196 union1.foo = int197 self.assertTrue(len(StypyTypeError.get_error_msgs()) == 1)198 class Foo:199 def method(self):200 pass201 def method_2(self):202 pass203 class Foo2:204 def method(self):205 pass206 def method_2(self):207 pass208 # Set a member with some of the types of the union able to be modified209 union2 = UnionType.add(Foo, str)210 union2.member = str211 self.assertTrue(len(TypeWarning.get_warning_msgs()) == 1)212 # TypeWarning.print_warning_msgs()213 compare_types(union2.member, str)214 self.assertTrue(len(TypeWarning.get_warning_msgs()) == 2)215 TypeWarning.reset_warning_msgs()216 instance1 = Foo()217 union3 = UnionType.add(instance1, str)218 instance2 = Foo2()219 union3 = UnionType.add(instance2, union3)220 union3.member = str221 self.assertTrue(len(TypeWarning.get_warning_msgs()) == 1)222 compare_types(union3.member, str)223 TypeWarning.reset_warning_msgs()224 StypyTypeError.reset_error_msgs()225 # Set a member using all-modifiable types226 union4 = UnionType.add(Foo, Foo2)227 self.assertTrue(len(TypeWarning.get_warning_msgs()) == 0)228 union4.member = float229 self.assertTrue(len(StypyTypeError.get_error_msgs()) == 0)230 self.assertTrue(len(TypeWarning.get_warning_msgs()) == 0)231 ret = union4.member232 compare_types(ret, float)233 def obj_func(cls):234 pass235 union4.class_method = types.MethodType(obj_func, union4)236 ret = union4.class_method237 compare_types(ret, types.MethodType(obj_func, union4))238 # # ############################## DYNAMIC INHERITANCE ###############################239 def test_change_type(self):240 # Set a member on non-modifiable types241 union1 = UnionType.add(int, str)242 union1.__class__ = int243 self.assertTrue(len(StypyTypeError.get_error_msgs()) == 1)244 class Foo:245 def method(self):246 pass247 def method_2(self):248 pass249 class Foo2:250 def method(self):251 pass252 def method_2(self):253 pass254 # Set a member with some of the types of the union able to be modified255 union2 = UnionType.add(Foo(), str)256 union2.__class__ = Foo2257 self.assertTrue(len(TypeWarning.get_warning_msgs()) == 1)258 # TypeWarning.print_warning_msgs()259 union_types = map(lambda x: type(x), union2.get_types())260 compare_types(union_types, [type(Foo2()), types.TypeType])261 TypeWarning.reset_warning_msgs()262 instance1 = Foo()263 union3 = UnionType.add(instance1, str)264 instance2 = Foo2()265 union3 = UnionType.add(instance2, union3)266 union3.__class__ = Foo2267 self.assertTrue(len(TypeWarning.get_warning_msgs()) == 1)268 union_types = map(lambda x: type(x), union2.get_types())269 compare_types(union_types, [type(Foo2()), types.TypeType])270 TypeWarning.reset_warning_msgs()271 StypyTypeError.reset_error_msgs()272 # Set a member using all-modifiable types273 foo1 = Foo()274 foo2 = Foo()275 union4 = UnionType.add(foo1, foo2)276 self.assertTrue(len(TypeWarning.get_warning_msgs()) == 0)277 self.assertTrue(len(StypyTypeError.get_error_msgs()) == 0)278 self.assertTrue(len(TypeWarning.get_warning_msgs()) == 0)279 ret = union4280 compare_types(ret, foo1)281 def test_change_base_types(self):282 # Set a member on non-modifiable types283 union1 = UnionType.add(int, str)284 union1.__bases__ = (int,)285 self.assertTrue(len(StypyTypeError.get_error_msgs()) == 1)286 class Foo:287 def method(self):288 pass289 def method_2(self):290 pass291 class Foo2:292 def method(self):293 pass294 def method_2(self):295 pass296 # Set a member with some of the types of the union able to be modified297 union2 = UnionType.add(Foo(), str)298 union2.__bases__ = (Foo2,)299 self.assertTrue(len(TypeWarning.get_warning_msgs()) == 1)300 # TypeWarning.print_warning_msgs()301 compare_types(union2.__bases__.types[0].contained_types, Foo2)302 compare_types(union2.__bases__.types[1].contained_types, str.__bases__[0])303 TypeWarning.reset_warning_msgs()304 instance1 = Foo()305 union3 = UnionType.add(instance1, str)306 instance2 = Foo2()307 union3 = UnionType.add(instance2, union3)308 union3.__bases__ = (Foo2,)309 self.assertTrue(len(TypeWarning.get_warning_msgs()) == 1)310 compare_types(union3.__bases__.types[0].contained_types, Foo2)311 compare_types(union3.__bases__.types[1].contained_types, str.__bases__[0])312 #compare_types(union3.__bases__, [(Foo2,), str.__bases__])313 TypeWarning.reset_warning_msgs()314 StypyTypeError.reset_error_msgs()315 # Set a member using all-modifiable types316 union4 = UnionType.add(Foo(), Foo())317 self.assertTrue(len(TypeWarning.get_warning_msgs()) == 0)318 union4.__bases__ = (Foo2,)319 self.assertTrue(len(StypyTypeError.get_error_msgs()) == 0)320 self.assertTrue(len(TypeWarning.get_warning_msgs()) == 0)321 ret = union4.__bases__...
match.py
Source:match.py
...32 assert isinstance(t2, _linda_server.Value) and t2.isType(), str(t2)33 assert t1.isId(), str(t1)34 assert t2.isId(), str(t2)35 return t1.id == t2.id36def compare_types(t1, t2, checked=None):37 assert t1.isType()38 assert t2.isType()39 if checked is None:40 checked = {(t1, t2): []}41 elif (t1, t2) in checked:42 return lambda x: convertValue(checked(t1, t2), x)43 else:44 checked[(t1, t2)] = []45 code = checked[(t1, t2)]46 print t1, t2, t1.isFunctionType(), t2.isFunctionType()47 if t1.isNil() and t2.isNil():48 code.append(("SETTYPEID", t2.type_id))49 elif t1.isId() and t2.isId():50 if t1.id in builtin and t2.id in builtin:51 if t1.id == t2.id:52 code.append(("SETTYPEID", t2.type_id))53 return lambda x: convertValue(checked[(t1, t2)], x)54 else:55 return None56 else:57 print t1.id, t2.id58 if t1.id not in builtin:59 nt = lookupType(t1.id_type_id)60 func = compare_types(nt, t2, checked)61 if func:62 code.append(("EVAL", checked[(nt, t2)]))63 return lambda x: convertValue(checked[(t1, t2)], x)64 if t2.id not in builtin:65 nt = lookupType(t2.id_type_id)66 func = compare_types(t1, nt, checked)67 if func:68 code.append(("EVAL", checked[(t1, nt)]))69 return lambda x: convertValue(checked[(t1, t2)], x)70 if t1.id not in builtin and t2.id not in builtin:71 nt1 = lookupType(t1.id_type_id)72 nt2 = lookupType(t2.id_type_id)73 func = compare_types(nt1, nt2, checked)74 if func:75 code.append(("EVAL", checked[(nt1, nt2)]))76 return lambda x: convertValue(checked[(t1, t2)], x)77 else:78 return None79 elif t1.isProductType() and t2.isProductType():80 t1e = flattenProductType(t1)81 t2e = flattenProductType(t2)82 if len(t1e) != len(t2e):83 return None84 funcs = []85 for e1, e2 in zip(t1e, t2e):86 f = compare_types(e1, e2, checked)87 if f is None:88 return89 else:90 funcs.append(checked[(e1, e2)])91 code.append(("EXPLODE", t1))92 for i in range(len(funcs)):93 code.append(("EVAL", funcs[i]))94 code.append(("ROTATE", ))95 code.append(("CONSTRUCT", t2))96 code.append(("SETTYPEID", t2.type_id))97 return lambda x: convertValue(checked[(t1, t2)], x)98 elif t1.isSumType() and t2.isSumType():99 t1e = flattenSumType(t1)100 t2e = flattenSumType(t2)101 if len(t1e) != len(t2e):102 return None103 for perm in all_perms(range(len(t2))):104 funcs = []105 for i in range(len(perm)):106 f = compare_types(t1e[i][0], t2e[perm[i]][0], checked)107 if f is None:108 break109 else:110 funcs.append(checked[(t1e[i][0], t2e[perm[i]][0])])111 for pos in t2e[perm[i]][1][::-1]:112 funcs[-1].append(("CREATESUM", perm[i]))113 if len(funcs) == len(perm):114 code.append(("SUMCASE", funcs))115 code.append(("SETTYPEID", t2.type_id))116 return lambda x: convertValue(checked[(t1, t2)], x)117 elif t1.isPtrType() and t2.isPtrType():118 f = compare_types(t1.ptrtype, t2.ptrtype, checked)119 if f is None:120 return121 code.append(("PTRCONV", checked[(t1.ptrtype, t2.ptrtype)]))122 return lambda x: convertValue(checked[(t1, t2)], x)123 elif t1.isFunctionType() and t2.isFunctionType():124 print "got functions", t1, t2125 arg = compare_types(t1.arg, t2.arg, checked)126 if arg is None:127 return None128 result = compare_types(t2.result, t1.result, checked)129 if result is None:130 return None131 return lambda x: wrap_function(t2.arg, checked[(t1.arg, t2.arg)], t2.result, checked[(t2.result, t1.result)], x)132def flattenProductType(p, memo = None):133 if memo is None:134 memo = {}135 if p.type_id:136 memo[p.type_id] = True137 l = []138 for i in range(len(p)):139 e = p[i]140 if e.isProductType():141 l.extend(flattenProductType(e, memo))142 elif e.isId() and not e.id in builtin:...
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!