Mercurial > cpython-lru_cache-weakref
changeset 47916:bed3dfd99281 legacy-trunk
Issue 3287: Raise correct exception for float inputs.
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Thu, 10 Jul 2008 09:31:08 +0000 |
| parents | 36188544c561 |
| children | c32e91650c14 |
| files | Lib/fractions.py Lib/test/test_fractions.py |
| diffstat | 2 files changed, 9 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/Lib/fractions.py Tue Jul 08 14:21:42 2008 +0000 +++ b/Lib/fractions.py Thu Jul 10 09:31:08 2008 +0000 @@ -96,9 +96,11 @@ if denominator == 0: raise ZeroDivisionError('Fraction(%s, 0)' % numerator) - - numerator = numerator.__index__() - denominator = denominator.__index__() + try: + numerator = numerator.__index__() + denominator = denominator.__index__() + except AttributeError: + raise TypeError('Numerator and denominator must support __index__.') g = gcd(numerator, denominator) self._numerator = numerator // g self._denominator = denominator // g
--- a/Lib/test/test_fractions.py Tue Jul 08 14:21:42 2008 +0000 +++ b/Lib/test/test_fractions.py Thu Jul 10 09:31:08 2008 +0000 @@ -62,11 +62,11 @@ self.assertRaisesMessage(ZeroDivisionError, "Fraction(12, 0)", F, 12, 0) - self.assertRaises(AttributeError, F, 1.5) - self.assertRaises(AttributeError, F, 1.5 + 3j) + self.assertRaises(TypeError, F, 1.5) + self.assertRaises(TypeError, F, 1.5 + 3j) - self.assertRaises(AttributeError, F, F(1, 2), 3) - self.assertRaises(AttributeError, F, "3/2", 3) + self.assertRaises(TypeError, F, F(1, 2), 3) + self.assertRaises(TypeError, F, "3/2", 3) def testFromString(self): self.assertEquals((5, 1), _components(F("5")))
