You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow Fraction constructor to accept float and decimal instances directly. #52541
Activity
mdickinson commentedon Apr 2, 2010
Here's a patch that allows direct construction of a Fraction instance from a float or Decimal instance, performing an exact conversion in either case.
mdickinson commentedon Apr 2, 2010
(The patch is against trunk, btw.)
rhettinger commentedon Apr 2, 2010
The patch looks like what I expected.
In the docstring, it would be nice if we kept the line with the spec for decimal strings: [-+]?[0-9]+((/|.)[0-9]+)?
mdickinson commentedon Apr 2, 2010
Unfortunately, that line is wrong (or at least incomplete), since decimals in exponential form are also accepted:
>>> Fraction('2.3e4') Fraction(23000, 1)I could try to reinstate a fixed version.
Attaching a second version of the patch: same as the first, except for some doc tweaks. (Rewording, markup fixes.)
rhettinger commentedon Apr 2, 2010
Being wrong is a good reason to eliminate that line from the docstring :-) So, I'm happy with the patch as-is.
mdickinson commentedon Apr 2, 2010
Thanks, Raymond. Committed to trunk in r79629. Will forward port to py3k.
mdickinson commentedon Apr 3, 2010
Merged to py3k in r79670.