Skip to content

Commit 6777e09

Browse files
authored
gh-98727: Remove old style classes from test_cmath (GH-98728)
1 parent f323694 commit 6777e09

File tree

1 file changed

+5
-33
lines changed

1 file changed

+5
-33
lines changed

Lib/test/test_cmath.py

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,7 @@ def test_user_object(self):
192192
# end up being passed to the cmath functions
193193

194194
# 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:
203196
def __init__(self, value):
204197
self.value = value
205198
def __complex__(self):
@@ -208,18 +201,13 @@ def __complex__(self):
208201
# classes for which __complex__ raises an exception
209202
class SomeException(Exception):
210203
pass
211-
class MyComplexException(object):
212-
def __complex__(self):
213-
raise SomeException
214-
class MyComplexExceptionOS:
204+
class MyComplexException:
215205
def __complex__(self):
216206
raise SomeException
217207

218208
# some classes not providing __float__ or __complex__
219209
class NeitherComplexNorFloat(object):
220210
pass
221-
class NeitherComplexNorFloatOS:
222-
pass
223211
class Index:
224212
def __int__(self): return 2
225213
def __index__(self): return 2
@@ -228,48 +216,32 @@ def __int__(self): return 2
228216

229217
# other possible combinations of __float__ and __complex__
230218
# that should work
231-
class FloatAndComplex(object):
219+
class FloatAndComplex:
232220
def __float__(self):
233221
return flt_arg
234222
def __complex__(self):
235223
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:
245225
def __float__(self):
246226
return flt_arg
247227

248228
for f in self.test_functions:
249229
# usual usage
250230
self.assertEqual(f(MyComplex(cx_arg)), f(cx_arg))
251-
self.assertEqual(f(MyComplexOS(cx_arg)), f(cx_arg))
252231
# other combinations of __float__ and __complex__
253232
self.assertEqual(f(FloatAndComplex()), f(cx_arg))
254-
self.assertEqual(f(FloatAndComplexOS()), f(cx_arg))
255233
self.assertEqual(f(JustFloat()), f(flt_arg))
256-
self.assertEqual(f(JustFloatOS()), f(flt_arg))
257234
self.assertEqual(f(Index()), f(int(Index())))
258235
# TypeError should be raised for classes not providing
259236
# 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__:
263238
self.assertRaises(TypeError, f, NeitherComplexNorFloat())
264239
self.assertRaises(TypeError, f, MyInt())
265-
self.assertRaises(Exception, f, NeitherComplexNorFloatOS())
266240
# non-complex return value from __complex__ -> TypeError
267241
for bad_complex in non_complexes:
268242
self.assertRaises(TypeError, f, MyComplex(bad_complex))
269-
self.assertRaises(TypeError, f, MyComplexOS(bad_complex))
270243
# exceptions in __complex__ should be propagated correctly
271244
self.assertRaises(SomeException, f, MyComplexException())
272-
self.assertRaises(SomeException, f, MyComplexExceptionOS())
273245

274246
def test_input_type(self):
275247
# ints should be acceptable inputs to all cmath

0 commit comments

Comments
 (0)