Debian Codegraph @

Lib/test/_crossinterp_definitions.py

raw
1 # This may be loaded as a module, in the current __main__ module,
2 # or in another __main__ module.
3
4
5 #######################################
6 # functions and generators
7
8 from test._code_definitions import *
9
10
11 #######################################
12 # classes
13
14 class Spam:
15 # minimal
16 pass
17
18
19 class SpamOkay:
20 def okay(self):
21 return True
22
23
24 class SpamFull:
25
26 a: object
27 b: object
28 c: object
29
30 @staticmethod
31 def staticmeth(cls):
32 return True
33
34 @classmethod
35 def classmeth(cls):
36 return True
37
38 def __new__(cls, *args, **kwargs):
39 return super().__new__(cls)
40
41 def __init__(self, a, b, c):
42 self.a = a
43 self.b = b
44 self.c = c
45
46 # __repr__
47 # __str__
48 # ...
49
50 def __eq__(self, other):
51 if not isinstance(other, SpamFull):
52 return NotImplemented
53 return (self.a == other.a and
54 self.b == other.b and
55 self.c == other.c)
56
57 @property
58 def prop(self):
59 return True
60
61
62 class SubSpamFull(SpamFull):
63 ...
64
65
66 class SubTuple(tuple):
67 ...
68
69
70 def class_eggs_inner():
71 class EggsNested:
72 ...
73 return EggsNested
74 EggsNested = class_eggs_inner()
75
76
77 TOP_CLASSES = {
78 Spam: (),
79 SpamOkay: (),
80 SpamFull: (1, 2, 3),
81 SubSpamFull: (1, 2, 3),
82 SubTuple: ([1, 2, 3],),
83 }
84 CLASSES_WITHOUT_EQUALITY = [
85 Spam,
86 SpamOkay,
87 ]
88 BUILTIN_SUBCLASSES = [
89 SubTuple,
90 ]
91 NESTED_CLASSES = {
92 EggsNested: (),
93 }
94 CLASSES = {
95 **TOP_CLASSES,
96 **NESTED_CLASSES,
97 }
98
99
100 #######################################
101 # exceptions
102
103 class MimimalError(Exception):
104 pass
105
106
107 class RichError(Exception):
108 def __init__(self, msg, value=None):
109 super().__init__(msg, value)
110 self.msg = msg
111 self.value = value
112
113 def __eq__(self, other):
114 if not isinstance(other, RichError):
115 return NotImplemented
116 if self.msg != other.msg:
117 return False
118 if self.value != other.value:
119 return False
120 return True