[Python-checkins] gh-98727: Remove old style classes from `test_cmath` (GH-98728)
mdickinson
webhook-mailer at python.org
Wed Oct 26 14:09:08 EDT 2022
https://github.com/python/cpython/commit/6777e09166fc384ea0a4b50202c7b0bd7a23330c
commit: 6777e09166fc384ea0a4b50202c7b0bd7a23330c
branch: main
author: Nikita Sobolev <mail at sobolevn.me>
committer: mdickinson <dickinsm at gmail.com>
date: 2022-10-26T19:08:34+01:00
summary:
gh-98727: Remove old style classes from `test_cmath` (GH-98728)
files:
M Lib/test/test_cmath.py
diff --git a/Lib/test/test_cmath.py b/Lib/test/test_cmath.py
index 4bdec6d2d838..9fa08dc4ff3f 100644
--- a/Lib/test/test_cmath.py
+++ b/Lib/test/test_cmath.py
@@ -192,14 +192,7 @@ def test_user_object(self):
# end up being passed to the cmath functions
# usual case: new-style class implementing __complex__
- class MyComplex(object):
- def __init__(self, value):
- self.value = value
- def __complex__(self):
- return self.value
-
- # old-style class implementing __complex__
- class MyComplexOS:
+ class MyComplex:
def __init__(self, value):
self.value = value
def __complex__(self):
@@ -208,18 +201,13 @@ def __complex__(self):
# classes for which __complex__ raises an exception
class SomeException(Exception):
pass
- class MyComplexException(object):
- def __complex__(self):
- raise SomeException
- class MyComplexExceptionOS:
+ class MyComplexException:
def __complex__(self):
raise SomeException
# some classes not providing __float__ or __complex__
class NeitherComplexNorFloat(object):
pass
- class NeitherComplexNorFloatOS:
- pass
class Index:
def __int__(self): return 2
def __index__(self): return 2
@@ -228,48 +216,32 @@ def __int__(self): return 2
# other possible combinations of __float__ and __complex__
# that should work
- class FloatAndComplex(object):
+ class FloatAndComplex:
def __float__(self):
return flt_arg
def __complex__(self):
return cx_arg
- class FloatAndComplexOS:
- def __float__(self):
- return flt_arg
- def __complex__(self):
- return cx_arg
- class JustFloat(object):
- def __float__(self):
- return flt_arg
- class JustFloatOS:
+ class JustFloat:
def __float__(self):
return flt_arg
for f in self.test_functions:
# usual usage
self.assertEqual(f(MyComplex(cx_arg)), f(cx_arg))
- self.assertEqual(f(MyComplexOS(cx_arg)), f(cx_arg))
# other combinations of __float__ and __complex__
self.assertEqual(f(FloatAndComplex()), f(cx_arg))
- self.assertEqual(f(FloatAndComplexOS()), f(cx_arg))
self.assertEqual(f(JustFloat()), f(flt_arg))
- self.assertEqual(f(JustFloatOS()), f(flt_arg))
self.assertEqual(f(Index()), f(int(Index())))
# TypeError should be raised for classes not providing
# either __complex__ or __float__, even if they provide
- # __int__ or __index__. An old-style class
- # currently raises AttributeError instead of a TypeError;
- # this could be considered a bug.
+ # __int__ or __index__:
self.assertRaises(TypeError, f, NeitherComplexNorFloat())
self.assertRaises(TypeError, f, MyInt())
- self.assertRaises(Exception, f, NeitherComplexNorFloatOS())
# non-complex return value from __complex__ -> TypeError
for bad_complex in non_complexes:
self.assertRaises(TypeError, f, MyComplex(bad_complex))
- self.assertRaises(TypeError, f, MyComplexOS(bad_complex))
# exceptions in __complex__ should be propagated correctly
self.assertRaises(SomeException, f, MyComplexException())
- self.assertRaises(SomeException, f, MyComplexExceptionOS())
def test_input_type(self):
# ints should be acceptable inputs to all cmath
More information about the Python-checkins
mailing list