@@ -192,14 +192,7 @@ def test_user_object(self):
192
192
# end up being passed to the cmath functions
193
193
194
194
# usual case: new-style class implementing __complex__
195
- class MyComplex (object ):
196
- def __init__ (self , value ):
197
- self .value = value
198
- def __complex__ (self ):
199
- return self .value
200
-
201
- # old-style class implementing __complex__
202
- class MyComplexOS :
195
+ class MyComplex :
203
196
def __init__ (self , value ):
204
197
self .value = value
205
198
def __complex__ (self ):
@@ -208,18 +201,13 @@ def __complex__(self):
208
201
# classes for which __complex__ raises an exception
209
202
class SomeException (Exception ):
210
203
pass
211
- class MyComplexException (object ):
212
- def __complex__ (self ):
213
- raise SomeException
214
- class MyComplexExceptionOS :
204
+ class MyComplexException :
215
205
def __complex__ (self ):
216
206
raise SomeException
217
207
218
208
# some classes not providing __float__ or __complex__
219
209
class NeitherComplexNorFloat (object ):
220
210
pass
221
- class NeitherComplexNorFloatOS :
222
- pass
223
211
class Index :
224
212
def __int__ (self ): return 2
225
213
def __index__ (self ): return 2
@@ -228,48 +216,32 @@ def __int__(self): return 2
228
216
229
217
# other possible combinations of __float__ and __complex__
230
218
# that should work
231
- class FloatAndComplex ( object ) :
219
+ class FloatAndComplex :
232
220
def __float__ (self ):
233
221
return flt_arg
234
222
def __complex__ (self ):
235
223
return cx_arg
236
- class FloatAndComplexOS :
237
- def __float__ (self ):
238
- return flt_arg
239
- def __complex__ (self ):
240
- return cx_arg
241
- class JustFloat (object ):
242
- def __float__ (self ):
243
- return flt_arg
244
- class JustFloatOS :
224
+ class JustFloat :
245
225
def __float__ (self ):
246
226
return flt_arg
247
227
248
228
for f in self .test_functions :
249
229
# usual usage
250
230
self .assertEqual (f (MyComplex (cx_arg )), f (cx_arg ))
251
- self .assertEqual (f (MyComplexOS (cx_arg )), f (cx_arg ))
252
231
# other combinations of __float__ and __complex__
253
232
self .assertEqual (f (FloatAndComplex ()), f (cx_arg ))
254
- self .assertEqual (f (FloatAndComplexOS ()), f (cx_arg ))
255
233
self .assertEqual (f (JustFloat ()), f (flt_arg ))
256
- self .assertEqual (f (JustFloatOS ()), f (flt_arg ))
257
234
self .assertEqual (f (Index ()), f (int (Index ())))
258
235
# TypeError should be raised for classes not providing
259
236
# either __complex__ or __float__, even if they provide
260
- # __int__ or __index__. An old-style class
261
- # currently raises AttributeError instead of a TypeError;
262
- # this could be considered a bug.
237
+ # __int__ or __index__:
263
238
self .assertRaises (TypeError , f , NeitherComplexNorFloat ())
264
239
self .assertRaises (TypeError , f , MyInt ())
265
- self .assertRaises (Exception , f , NeitherComplexNorFloatOS ())
266
240
# non-complex return value from __complex__ -> TypeError
267
241
for bad_complex in non_complexes :
268
242
self .assertRaises (TypeError , f , MyComplex (bad_complex ))
269
- self .assertRaises (TypeError , f , MyComplexOS (bad_complex ))
270
243
# exceptions in __complex__ should be propagated correctly
271
244
self .assertRaises (SomeException , f , MyComplexException ())
272
- self .assertRaises (SomeException , f , MyComplexExceptionOS ())
273
245
274
246
def test_input_type (self ):
275
247
# ints should be acceptable inputs to all cmath
0 commit comments