[Python-checkins] r79456 - in python/branches/py3k: Lib/fractions.py Lib/test/test_fractions.py

mark.dickinson python-checkins at python.org
Sat Mar 27 12:11:13 CET 2010


Author: mark.dickinson
Date: Sat Mar 27 12:11:13 2010
New Revision: 79456
Log:
Merged revisions 79455 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk
........
 r79455 | mark.dickinson | 2010年03月27日 11:09:29 +0000 (2010年3月27日) | 2 lines
 
 Make Fraction to complex comparisons with <=, <, >= or > raise TypeError.
........
Modified:
 python/branches/py3k/ (props changed)
 python/branches/py3k/Lib/fractions.py
 python/branches/py3k/Lib/test/test_fractions.py
Modified: python/branches/py3k/Lib/fractions.py
==============================================================================
--- python/branches/py3k/Lib/fractions.py	(original)
+++ python/branches/py3k/Lib/fractions.py	Sat Mar 27 12:11:13 2010
@@ -526,8 +526,6 @@
 if isinstance(other, numbers.Rational):
 return op(self._numerator * other.denominator,
 self._denominator * other.numerator)
- if isinstance(other, numbers.Complex) and other.imag == 0:
- other = other.real
 if isinstance(other, float):
 if math.isnan(other) or math.isinf(other):
 return op(0.0, other)
Modified: python/branches/py3k/Lib/test/test_fractions.py
==============================================================================
--- python/branches/py3k/Lib/test/test_fractions.py	(original)
+++ python/branches/py3k/Lib/test/test_fractions.py	Sat Mar 27 12:11:13 2010
@@ -479,8 +479,21 @@
 
 def testBigComplexComparisons(self):
 self.assertFalse(F(10**23) == complex(10**23))
- self.assertTrue(F(10**23) > complex(10**23))
- self.assertFalse(F(10**23) <= complex(10**23))
+ self.assertRaises(TypeError, operator.gt, F(10**23), complex(10**23))
+ self.assertRaises(TypeError, operator.le, F(10**23), complex(10**23))
+
+ x = F(3, 8)
+ z = complex(0.375, 0.0)
+ w = complex(0.375, 0.2)
+ self.assertTrue(x == z)
+ self.assertFalse(x != z)
+ self.assertFalse(x == w)
+ self.assertTrue(x != w)
+ for op in operator.lt, operator.le, operator.gt, operator.ge:
+ self.assertRaises(TypeError, op, x, z)
+ self.assertRaises(TypeError, op, z, x)
+ self.assertRaises(TypeError, op, x, w)
+ self.assertRaises(TypeError, op, w, x)
 
 def testMixedEqual(self):
 self.assertTrue(0.5 == F(1, 2))


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /