diff options
author | Guido van Rossum <guido@python.org> | 2008-01-15 21:44:53 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2008-01-15 21:44:53 (GMT) |
commit | 7736b5becd273cb271c55fcce9155677a381c4f6 (patch) | |
tree | 2c18c15c4ee0475ab6b1394a2e5cb18358ddbbbc /Lib/numbers.py | |
parent | ae138cbfbbfb376917fd29abb6724d56ba5fc081 (diff) | |
download | cpython-7736b5becd273cb271c55fcce9155677a381c4f6.zip cpython-7736b5becd273cb271c55fcce9155677a381c4f6.tar.gz cpython-7736b5becd273cb271c55fcce9155677a381c4f6.tar.bz2 |
Merged revisions 59952-59984 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59952 | thomas.heller | 2008-01-14 02:35:28 -0800 (Mon, 14 Jan 2008) | 1 line
Issue 1821: configure libffi for amd64 on FreeeBSD.
........
r59953 | andrew.kuchling | 2008-01-14 06:48:43 -0800 (Mon, 14 Jan 2008) | 1 line
Update description of float_info
........
r59959 | raymond.hettinger | 2008-01-14 14:58:05 -0800 (Mon, 14 Jan 2008) | 1 line
Fix 1698398: Zipfile.printdir() crashed because the format string expected a tuple object of length six instead of a time.struct_time object.
........
r59961 | andrew.kuchling | 2008-01-14 17:29:16 -0800 (Mon, 14 Jan 2008) | 1 line
Typo fixes
........
r59962 | andrew.kuchling | 2008-01-14 17:29:44 -0800 (Mon, 14 Jan 2008) | 1 line
Markup fix
........
r59963 | andrew.kuchling | 2008-01-14 17:47:32 -0800 (Mon, 14 Jan 2008) | 1 line
Add many items
........
r59964 | andrew.kuchling | 2008-01-14 17:55:32 -0800 (Mon, 14 Jan 2008) | 1 line
Repair unfinished sentence
........
r59967 | raymond.hettinger | 2008-01-14 19:02:37 -0800 (Mon, 14 Jan 2008) | 5 lines
Issue 1820: structseq objects did not work with the % formatting operator or isinstance(t, tuple).
Orignal patch (without tests) by Leif Walsh.
........
r59968 | raymond.hettinger | 2008-01-14 19:07:42 -0800 (Mon, 14 Jan 2008) | 1 line
Tighten the definition of a named tuple.
........
r59969 | skip.montanaro | 2008-01-14 19:40:20 -0800 (Mon, 14 Jan 2008) | 3 lines
Better (?) text describing the lack of guarantees provided by qsize(),
empty() and full().
........
r59970 | raymond.hettinger | 2008-01-14 21:39:59 -0800 (Mon, 14 Jan 2008) | 1 line
Temporarily revert 59967 until GC can be added.
........
r59971 | raymond.hettinger | 2008-01-14 21:46:43 -0800 (Mon, 14 Jan 2008) | 1 line
Small grammar nit
........
r59972 | georg.brandl | 2008-01-14 22:55:56 -0800 (Mon, 14 Jan 2008) | 2 lines
Typo.
........
r59973 | georg.brandl | 2008-01-14 22:58:15 -0800 (Mon, 14 Jan 2008) | 2 lines
Remove duplicate entry.
........
r59974 | jeffrey.yasskin | 2008-01-14 23:46:24 -0800 (Mon, 14 Jan 2008) | 12 lines
Add rational.Rational as an implementation of numbers.Rational with infinite
precision. This has been discussed at http://bugs.python.org/issue1682. It's
useful primarily for teaching, but it also demonstrates how to implement a
member of the numeric tower, including fallbacks for mixed-mode arithmetic.
I expect to write a couple more patches in this area:
* Rational.from_decimal()
* Rational.trim/approximate() (maybe with different names)
* Maybe remove the parentheses from Rational.__str__()
* Maybe rename one of the Rational classes
* Maybe make Rational('3/2') work.
........
r59978 | andrew.kuchling | 2008-01-15 06:38:05 -0800 (Tue, 15 Jan 2008) | 8 lines
Restore description of sys.dont_write_bytecode.
The duplication is intentional -- this paragraph is in a section
describing additions to the sys module, and there's a later section
that mentions the switch. I think most people scan the what's-new and
don't read it in detail, so a bit of duplication is OK.
........
r59984 | guido.van.rossum | 2008-01-15 09:59:29 -0800 (Tue, 15 Jan 2008) | 3 lines
Issue #1786 (by myself): pdb should use its own stdin/stdout around an
exec call and when creating a recursive instance.
........
Diffstat (limited to 'Lib/numbers.py')
-rw-r--r-- | Lib/numbers.py | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/Lib/numbers.py b/Lib/numbers.py index b1c0697..7c73fa7 100644 --- a/Lib/numbers.py +++ b/Lib/numbers.py @@ -5,6 +5,7 @@ TODO: Fill out more detailed documentation on the operators.""" +from __future__ import division from abc import ABCMeta, abstractmethod, abstractproperty __all__ = ["Number", "Exact", "Inexact", @@ -61,7 +62,8 @@ class Complex(Number): def __complex__(self): """Return a builtin complex instance. Called for complex(self).""" - def __bool__(self): + # Will be __bool__ in 3.0. + def __nonzero__(self): """True if self != 0. Called for bool(self).""" return self != 0 @@ -96,6 +98,7 @@ class Complex(Number): """-self""" raise NotImplementedError + @abstractmethod def __pos__(self): """+self""" raise NotImplementedError @@ -120,12 +123,28 @@ class Complex(Number): @abstractmethod def __div__(self, other): - """self / other; should promote to float or complex when necessary.""" + """self / other without __future__ division + + May promote to float. + """ raise NotImplementedError @abstractmethod def __rdiv__(self, other): - """other / self""" + """other / self without __future__ division""" + raise NotImplementedError + + @abstractmethod + def __truediv__(self, other): + """self / other with __future__ division. + + Should promote to float when necessary. + """ + raise NotImplementedError + + @abstractmethod + def __rtruediv__(self, other): + """other / self with __future__ division""" raise NotImplementedError @abstractmethod |