1# ----------------- 2# First a few name resolution things 3# ----------------- 4 5x = 3 6if NOT_DEFINED: 7 x = '' 8#? 6 int() 9elif x: 10 pass 11else: 12 #? int() 13 x 14 15x = 1 16try: 17 x = '' 18#? 8 int() str() 19except x: 20 #? 5 int() str() 21 x 22 x = 1.0 23else: 24 #? 5 int() str() 25 x 26 x = list 27finally: 28 #? 5 int() str() float() list 29 x 30 x = tuple 31 32if False: 33 with open("") as defined_in_false: 34 #? ['flush'] 35 defined_in_false.flu 36 37# ----------------- 38# Return checks 39# ----------------- 40 41def foo(x): 42 if 1.0: 43 return 1 44 else: 45 return '' 46 47#? int() 48foo(1) 49 50 51# Exceptions are not analyzed. So check both if branches 52def try_except(x): 53 try: 54 if 0: 55 return 1 56 else: 57 return '' 58 except AttributeError: 59 return 1.0 60 61#? float() str() 62try_except(1) 63 64 65# Exceptions are not analyzed. So check both if branches 66def try_except(x): 67 try: 68 if 0: 69 return 1 70 else: 71 return '' 72 except AttributeError: 73 return 1.0 74 75#? float() str() 76try_except(1) 77 78def test_function(): 79 a = int(input()) 80 if a % 2 == 0: 81 return True 82 return "False" 83 84#? bool() str() 85test_function() 86 87# ----------------- 88# elif 89# ----------------- 90 91def elif_flows1(x): 92 if False: 93 return 1 94 elif True: 95 return 1.0 96 else: 97 return '' 98 99#? float() 100elif_flows1(1) 101 102 103def elif_flows2(x): 104 try: 105 if False: 106 return 1 107 elif 0: 108 return 1.0 109 else: 110 return '' 111 except ValueError: 112 return set 113 114#? str() set 115elif_flows2(1) 116 117 118def elif_flows3(x): 119 try: 120 if True: 121 return 1 122 elif 0: 123 return 1.0 124 else: 125 return '' 126 except ValueError: 127 return set 128 129#? int() set 130elif_flows3(1) 131 132# ----------------- 133# mid-difficulty if statements 134# ----------------- 135def check(a): 136 if a is None: 137 return 1 138 return '' 139 return set 140 141#? int() 142check(None) 143#? str() 144check('asb') 145 146a = list 147if 2 == True: 148 a = set 149elif 1 == True: 150 a = 0 151 152#? int() 153a 154if check != 1: 155 a = '' 156#? int() str() 157a 158if check == check: 159 a = list 160#? list 161a 162if check != check: 163 a = set 164else: 165 a = dict 166#? dict 167a 168if not (check is not check): 169 a = 1 170#? int() 171a 172 173 174# ----------------- 175# name resolution 176# ----------------- 177 178a = list 179def elif_name(x): 180 try: 181 if True: 182 a = 1 183 elif 0: 184 a = 1.0 185 else: 186 return '' 187 except ValueError: 188 a = x 189 return a 190 191#? int() set 192elif_name(set) 193 194if 0: 195 a = '' 196else: 197 a = int 198 199#? int 200a 201 202# ----------------- 203# isinstance 204# ----------------- 205 206class A(): pass 207 208def isinst(x): 209 if isinstance(x, A): 210 return dict 211 elif isinstance(x, int) and x == 1 or x is True: 212 return set 213 elif isinstance(x, (float, reversed)): 214 return list 215 elif not isinstance(x, str): 216 return tuple 217 return 1 218 219#? dict 220isinst(A()) 221#? set 222isinst(True) 223#? set 224isinst(1) 225#? tuple 226isinst(2) 227#? list 228isinst(1.0) 229#? tuple 230isinst(False) 231#? int() 232isinst('') 233 234# ----------------- 235# flows that are not reachable should be able to access parent scopes. 236# ----------------- 237 238foobar = '' 239 240if 0: 241 within_flow = 1.0 242 #? float() 243 within_flow 244 #? str() 245 foobar 246 if 0: 247 nested = 1 248 #? int() 249 nested 250 #? float() 251 within_flow 252 #? str() 253 foobar 254 #? 255 nested 256 257if False: 258 in_false = 1 259 #? ['in_false'] 260 in_false 261 262# ----------------- 263# True objects like modules 264# ----------------- 265 266class X(): 267 pass 268if X: 269 a = 1 270else: 271 a = '' 272#? int() 273a 274 275 276# ----------------- 277# Recursion issues 278# ----------------- 279 280def possible_recursion_error(filename): 281 if filename == 'a': 282 return filename 283 # It seems like without the brackets there wouldn't be a RecursionError. 284 elif type(filename) == str: 285 return filename 286 287 288if NOT_DEFINED: 289 s = str() 290else: 291 s = str() 292#? str() 293possible_recursion_error(s) 294 295 296# ----------------- 297# In combination with imports 298# ----------------- 299 300from import_tree import flow_import 301 302if 1 == flow_import.env: 303 a = 1 304elif 2 == flow_import.env: 305 a = '' 306elif 3 == flow_import.env: 307 a = 1.0 308 309#? int() str() 310a 311