diff options
author | Georg Brandl <georg@python.org> | 2009-01-03 22:03:11 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2009-01-03 22:03:11 (GMT) |
commit | fe427895b58769840f1f61a82ea0cdfe55150347 (patch) | |
tree | ba6fc9493239a122199292caada1e9345d26e8f6 /Lib | |
parent | c63785db867804de8b676ddddcc90c3fcbf2c111 (diff) | |
download | cpython-fe427895b58769840f1f61a82ea0cdfe55150347.zip cpython-fe427895b58769840f1f61a82ea0cdfe55150347.tar.gz cpython-fe427895b58769840f1f61a82ea0cdfe55150347.tar.bz2 |
Manually merge r68095,68186,68187,68188,68190 from 2.6 branch.
Diffstat (limited to 'Lib')
-rwxr-xr-x | Lib/fractions.py | 2 | ||||
-rw-r--r-- | Lib/heapq.py | 8 | ||||
-rw-r--r-- | Lib/test/test_fractions.py | 2 |
3 files changed, 11 insertions, 1 deletions
diff --git a/Lib/fractions.py b/Lib/fractions.py index 4adb184..446ad8e 100755 --- a/Lib/fractions.py +++ b/Lib/fractions.py @@ -111,7 +111,7 @@ class Fraction(Rational): """ if isinstance(f, numbers.Integral): - f = float(f) + return cls(f) elif not isinstance(f, float): raise TypeError("%s.from_float() only takes floats, not %r (%s)" % (cls.__name__, f, type(f).__name__)) diff --git a/Lib/heapq.py b/Lib/heapq.py index 0a83b76..c13d650 100644 --- a/Lib/heapq.py +++ b/Lib/heapq.py @@ -354,6 +354,10 @@ def nsmallest(n, iterable, key=None): Equivalent to: sorted(iterable, key=key)[:n] """ + if key is None: + it = izip(iterable, count()) # decorate + result = _nsmallest(n, it) + return map(itemgetter(0), result) # undecorate in1, in2 = tee(iterable) it = izip(imap(key, in1), count(), in2) # decorate result = _nsmallest(n, it) @@ -365,6 +369,10 @@ def nlargest(n, iterable, key=None): Equivalent to: sorted(iterable, key=key, reverse=True)[:n] """ + if key is None: + it = izip(iterable, imap(neg, count())) # decorate + result = _nlargest(n, it) + return map(itemgetter(0), result) # undecorate in1, in2 = tee(iterable) it = izip(imap(key, in1), imap(neg, count()), in2) # decorate result = _nlargest(n, it) diff --git a/Lib/test/test_fractions.py b/Lib/test/test_fractions.py index 979fef7..a6c3c32 100644 --- a/Lib/test/test_fractions.py +++ b/Lib/test/test_fractions.py @@ -139,6 +139,8 @@ class FractionTest(unittest.TestCase): def testFromFloat(self): self.assertRaises(TypeError, F.from_float, 3+4j) self.assertEquals((10, 1), _components(F.from_float(10))) + bigint = 1234567890123456789 + self.assertEquals((bigint, 1), _components(F.from_float(bigint))) self.assertEquals((0, 1), _components(F.from_float(-0.0))) self.assertEquals((10, 1), _components(F.from_float(10.0))) self.assertEquals((-5, 2), _components(F.from_float(-2.5))) |