[Python-checkins] r64835 - in python/trunk/Lib: fractions.py test/test_fractions.py

Nick Coghlan ncoghlan at gmail.com
Thu Jul 10 12:14:17 CEST 2008


raymond.hettinger wrote:
> Author: raymond.hettinger
> Date: Thu Jul 10 11:31:08 2008
> New Revision: 64835
> 
> Log:
> Issue 3287: Raise correct exception for float inputs.
> 
> Modified:
>    python/trunk/Lib/fractions.py
>    python/trunk/Lib/test/test_fractions.py
> 
> Modified: python/trunk/Lib/fractions.py
> ==============================================================================
> --- python/trunk/Lib/fractions.py	(original)
> +++ python/trunk/Lib/fractions.py	Thu Jul 10 11:31:08 2008
> @@ -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__.')

Any particular reason this code is calling __index__ directly instead of 
using operator.index() which will give the TypeError automatically?

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-checkins mailing list