Debian Codegraph @

test/static_analysis/branches.py

raw symbols SCIP
1 # -----------------
2 # Simple tests
3 # -----------------
4
5 import random
6
7 if random.choice([0, 1]):
8 x = ''
9 else:
10 x = 1
11 if random.choice([0, 1]):
12 y = ''
13 else:
14 y = 1
15
16 # A simple test
17 if x != 1:
18 x.upper()
19 else:
20 #! 2 attribute-error
21 x.upper()
22 pass
23
24 # This operation is wrong, because the types could be different.
25 #! 6 type-error-operation
26 z = x + y
27 # However, here we have correct types.
28 if x == y:
29 z = x + y
30 else:
31 #! 6 type-error-operation
32 z = x + y
33
34
35 # TODO enable this one.
36 #x = 3
37 #if x != 1:
38 # x.upper()
39
40 # -----------------
41 # With a function
42 # -----------------
43
44 def addition(a, b):
45 if type(a) == type(b):
46 # Might still be a type error, we might want to change this in the
47 # future.
48 #! 9 type-error-operation
49 return a + b
50 else:
51 #! 9 type-error-operation
52 return a + b
53
54 addition(1, 1)
55 addition(1.0, '')