Debian Codegraph @

src/test/python/fixtures/special_methods.py

raw symbols SCIP
1 class Simple:
2 def __init__(self, x):
3 self.x = x
4
5 def __hash__(self):
6 return hash(self.x)
7
8 def __str__(self):
9 return str(self.x)
10
11 def __eq__(self, other):
12 return self.x == other
13
14 class ThrowsException:
15 def __hash__(self):
16 raise Exception('this __hash__ always raises Exception')
17
18 def __str__(self):
19 raise Exception('this __str__ always raises Exception')
20
21 def __eq__(self, other):
22 raise Exception('this __eq__ always raises Exception')
23
24 # __eq__ *can* return non boolean values
25 class NonBooleanEq:
26 def __eq__(self, other):
27 if self is other:
28 return 1
29 return 0
30
31 # __str__ should *not* return non string values
32 class NonStringStr:
33 def __str__(self):
34 return 1
35
36 class NoMethodsDefined:
37 def __init__(self):
38 pass
39
40 class EqAlwaysFalse:
41 def __eq__(self, other):
42 return False
43
44 class EqAlwaysTrue:
45 def __eq__(self, other):
46 return True
47
48 class HashNegativeOne:
49 def __hash__(self):
50 return -1