File tree Expand file tree Collapse file tree 1 file changed +36
-1
lines changed Expand file tree Collapse file tree 1 file changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -137,4 +137,39 @@ def __len__(self):
137
137
138
138
139
139
with assertRaises (TypeError ):
140
- bool (TestLenThrowError ())
140
+ bool (TestLenThrowError ())
141
+
142
+ # Verify that TypeError occurs when bad things are returned
143
+ # from __bool__(). This isn't really a bool test, but
144
+ # it's related.
145
+ def check (o ):
146
+ with assertRaises (TypeError ):
147
+ bool (o )
148
+
149
+ class Foo (object ):
150
+ def __bool__ (self ):
151
+ return self
152
+ check (Foo ())
153
+
154
+ class Bar (object ):
155
+ def __bool__ (self ):
156
+ return "Yes"
157
+ check (Bar ())
158
+
159
+ class Baz (int ):
160
+ def __bool__ (self ):
161
+ return self
162
+ check (Baz ())
163
+
164
+ # __bool__() must return a bool not an int
165
+ class Spam (int ):
166
+ def __bool__ (self ):
167
+ return 1
168
+ check (Spam ())
169
+
170
+ class Eggs :
171
+ def __len__ (self ):
172
+ return - 1
173
+
174
+ with assertRaises (ValueError ):
175
+ bool (Eggs ())
You can’t perform that action at this time.
0 commit comments