Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3feef61

Browse files
committed
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60706,60708-60712,60714-60724 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r60701 | georg.brandl | 2008-02-09 22:36:15 +0100 (Sat, 09 Feb 2008) | 2 lines Needs only 2.4 now. ........ r60702 | georg.brandl | 2008-02-09 22:38:54 +0100 (Sat, 09 Feb 2008) | 2 lines Docs are rst now. ........ r60703 | georg.brandl | 2008-02-09 23:00:00 +0100 (Sat, 09 Feb 2008) | 2 lines Fix link. ........ r60704 | georg.brandl | 2008-02-10 00:09:25 +0100 (Sun, 10 Feb 2008) | 2 lines Fix for newest doctools. ........ r60709 | raymond.hettinger | 2008-02-10 08:21:09 +0100 (Sun, 10 Feb 2008) | 1 line Clarify that decimal also supports fixed-point arithmetic. ........ r60710 | nick.coghlan | 2008-02-10 08:32:52 +0100 (Sun, 10 Feb 2008) | 1 line Add missing NEWS entry for r60695 ........ r60712 | mark.dickinson | 2008-02-10 15:58:38 +0100 (Sun, 10 Feb 2008) | 3 lines Turn classmethods into staticmethods, and avoid calling the constructor of subclasses of Rational. (See discussion in issue #1682.) ........ r60715 | mark.dickinson | 2008-02-10 16:19:58 +0100 (Sun, 10 Feb 2008) | 2 lines Typos in decimal comment and documentation ........ r60716 | skip.montanaro | 2008-02-10 16:31:54 +0100 (Sun, 10 Feb 2008) | 2 lines Get the saying right. ;-) ........ r60717 | skip.montanaro | 2008-02-10 16:32:16 +0100 (Sun, 10 Feb 2008) | 2 lines whoops - revert ........ r60718 | mark.dickinson | 2008-02-10 20:23:36 +0100 (Sun, 10 Feb 2008) | 2 lines Remove reference to Rational ........ r60719 | raymond.hettinger | 2008-02-10 21:35:16 +0100 (Sun, 10 Feb 2008) | 1 line Complete an open todo on pickletools -- add a pickle optimizer. ........ r60721 | mark.dickinson | 2008-02-10 22:29:51 +0100 (Sun, 10 Feb 2008) | 3 lines Rename rational.Rational to fractions.Fraction, to avoid name clash with numbers.Rational. See issue #1682 for related discussion. ........ r60722 | christian.heimes | 2008-02-11 03:26:22 +0100 (Mon, 11 Feb 2008) | 1 line The test requires the network resource ........ r60723 | mark.dickinson | 2008-02-11 04:11:55 +0100 (Mon, 11 Feb 2008) | 3 lines Put an extra space into the repr of a Fraction: Fraction(1, 2) instead of Fraction(1,2). ........
1 parent ba99c58 commit 3feef61

15 files changed

Lines changed: 190 additions & 146 deletions

File tree

Demo/classes/README

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ Complex.py Complex numbers
44
Dates.py Date manipulation package by Tim Peters
55
Dbm.py Wrapper around built-in dbm, supporting arbitrary values
66
Range.py Example of a generator: re-implement built-in range()
7-
Rat.py Rational numbers
87
Rev.py Yield the reverse of a sequence
98
Vec.py A simple vector class
109
bitvec.py A bit-vector class by Jan-Hein B\"uhrman

Doc/README.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ those familiar with the previous docs written in LaTeX.
1414
Building the docs
1515
=================
1616

17-
You need to install Python 2.5.1 or higher (but Python 3.0 is not supported yet);
17+
You need to install Python 2.4 or higher (but Python 3.0 is not supported yet);
1818
the toolset used to build the docs are written in Python. The toolset used
1919
to build the documentation is called *Sphinx*, it is not included in this
2020
tree, but maintained separately in the Python Subversion repository. Also
@@ -55,7 +55,7 @@ Available make targets are:
5555

5656
* "latex", which builds LaTeX source files that can be run with "pdflatex"
5757
to produce PDF documents.
58-
58+
5959
* "linkcheck", which checks all external references to see whether they are
6060
broken, redirected or malformed, and outputs this information to stdout
6161
as well as a plain-text (.txt) file.

Doc/conf.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@
3838
today_fmt = '%B %d, %Y'
3939

4040
# List of files that shouldn't be included in the build.
41-
unused_files = [
42-
'whatsnew/2.0.rst',
43-
'whatsnew/2.1.rst',
44-
'whatsnew/2.2.rst',
45-
'whatsnew/2.3.rst',
46-
'whatsnew/2.4.rst',
47-
'whatsnew/2.5.rst',
48-
'whatsnew/2.6.rst',
49-
'maclib/scrap.rst',
50-
'library/xmllib.rst',
51-
'library/xml.etree.rst',
41+
unused_docs = [
42+
'whatsnew/2.0',
43+
'whatsnew/2.1',
44+
'whatsnew/2.2',
45+
'whatsnew/2.3',
46+
'whatsnew/2.4',
47+
'whatsnew/2.5',
48+
'whatsnew/2.6',
49+
'maclib/scrap',
50+
'library/xmllib',
51+
'library/xml.etree',
5252
]
5353

5454
# Relative filename of the reference count data file.

Doc/extending/windows.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ and add the following to the module initialization function::
179179

180180
MyObject_Type.ob_type = &PyType_Type;
181181

182-
Refer to section 3 of the `Python FAQ <http://www.python.org/doc/FAQ.html>`_ for
182+
Refer to section 3 of the `Python FAQ <http://www.python.org/doc/faq>`_ for
183183
details on why you must do this.
184184

185185

Doc/library/decimal.rst

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
:mod:`decimal` --- Decimal floating point arithmetic
3-
====================================================
2+
:mod:`decimal` --- Decimal fixed point and floating point arithmetic
3+
====================================================================
44

55
.. module:: decimal
66
:synopsis: Implementation of the General Decimal Arithmetic Specification.
@@ -16,6 +16,11 @@
1616
The :mod:`decimal` module provides support for decimal floating point
1717
arithmetic. It offers several advantages over the :class:`float` datatype:
1818

19+
* Decimal "is based on a floating-point model which was designed with people
20+
in mind, and necessarily has a paramount guiding principle -- computers must
21+
provide an arithmetic that works in the same way as the arithmetic that
22+
people learn at school." -- excerpt from the decimal arithmetic specification.
23+
1924
* Decimal numbers can be represented exactly. In contrast, numbers like
2025
:const:`1.1` do not have an exact representation in binary floating point. End
2126
users typically would not expect :const:`1.1` to display as
@@ -25,7 +30,7 @@ arithmetic. It offers several advantages over the :class:`float` datatype:
2530
+ 0.1 + 0.1 - 0.3`` is exactly equal to zero. In binary floating point, the result
2631
is :const:`5.5511151231257827e-017`. While near to zero, the differences
2732
prevent reliable equality testing and differences can accumulate. For this
28-
reason, decimal would be preferred in accounting applications which have strict
33+
reason, decimal is preferred in accounting applications which have strict
2934
equality invariants.
3035

3136
* The decimal module incorporates a notion of significant places so that ``1.30
@@ -50,6 +55,13 @@ arithmetic. It offers several advantages over the :class:`float` datatype:
5055
standards. While the built-in float type exposes only a modest portion of its
5156
capabilities, the decimal module exposes all required parts of the standard.
5257
When needed, the programmer has full control over rounding and signal handling.
58+
This includes an option to enforce exact arithmetic by using exceptions
59+
to block any inexact operations.
60+
61+
* The decimal module was designed to support "without prejudice, both exact
62+
unrounded decimal arithmetic (sometimes called fixed-point arithmetic)
63+
and rounded floating-point arithmetic." -- excerpt from the decimal
64+
arithmetic specification.
5365

5466
The module design is centered around three concepts: the decimal number, the
5567
context for arithmetic, and signals.
@@ -832,7 +844,7 @@ described below. In addition, the module provides three pre-made contexts:
832844
:const:`ROUND_HALF_EVEN`. All flags are cleared. No traps are enabled (so that
833845
exceptions are not raised during computations).
834846

835-
Because the trapped are disabled, this context is useful for applications that
847+
Because the traps are disabled, this context is useful for applications that
836848
prefer to have result value of :const:`NaN` or :const:`Infinity` instead of
837849
raising exceptions. This allows an application to complete a run in the
838850
presence of conditions that would otherwise halt the program.
@@ -1245,7 +1257,7 @@ quiet or signaling :const:`NaN` always returns :const:`False` (even when doing
12451257
:const:`True`. An attempt to compare two Decimals using any of the ``<``,
12461258
``<=``, ``>`` or ``>=`` operators will raise the :exc:`InvalidOperation` signal
12471259
if either operand is a :const:`NaN`, and return :const:`False` if this signal is
1248-
trapped. Note that the General Decimal Arithmetic specification does not
1260+
not trapped. Note that the General Decimal Arithmetic specification does not
12491261
specify the behavior of direct comparisons; these rules for comparisons
12501262
involving a :const:`NaN` were taken from the IEEE 854 standard (see Table 3 in
12511263
section 5.7). To ensure strict standards-compliance, use the :meth:`compare`
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11

2-
:mod:`rational` --- Rational numbers
2+
:mod:`fractions` --- Rational numbers
33
====================================
44

5-
.. module:: rational
5+
.. module:: fractions
66
:synopsis: Rational numbers.
77
.. moduleauthor:: Jeffrey Yasskin <jyasskin at gmail.com>
88
.. sectionauthor:: Jeffrey Yasskin <jyasskin at gmail.com>
99
.. versionadded:: 2.6
1010

1111

12-
The :mod:`rational` module defines an immutable, infinite-precision
12+
The :mod:`fractions` module defines an immutable, infinite-precision
1313
Rational number class.
1414

1515

16-
.. class:: Rational(numerator=0, denominator=1)
17-
Rational(other_rational)
18-
Rational(string)
16+
.. class:: Fraction(numerator=0, denominator=1)
17+
Fraction(other_fraction)
18+
Fraction(string)
1919

2020
The first version requires that *numerator* and *denominator* are
2121
instances of :class:`numbers.Integral` and returns a new
22-
``Rational`` representing ``numerator/denominator``. If
22+
``Fraction`` representing ``numerator/denominator``. If
2323
*denominator* is :const:`0`, raises a :exc:`ZeroDivisionError`. The
24-
second version requires that *other_rational* is an instance of
25-
:class:`numbers.Rational` and returns an instance of
24+
second version requires that *other_fraction* is an instance of
25+
:class:`numbers.Fraction` and returns an instance of
2626
:class:`Rational` with the same value. The third version expects a
2727
string of the form ``[-+]?[0-9]+(/[0-9]+)?``, optionally surrounded
2828
by spaces.
@@ -31,39 +31,39 @@ Rational number class.
3131
:class:`numbers.Rational` and is immutable and hashable.
3232

3333

34-
.. method:: Rational.from_float(flt)
34+
.. method:: Fraction.from_float(flt)
3535

36-
This classmethod constructs a :class:`Rational` representing the
36+
This classmethod constructs a :class:`Fraction` representing the
3737
exact value of *flt*, which must be a :class:`float`. Beware that
38-
``Rational.from_float(0.3)`` is not the same value as ``Rational(3,
38+
``Fraction.from_float(0.3)`` is not the same value as ``Rational(3,
3939
10)``
4040

4141

42-
.. method:: Rational.from_decimal(dec)
42+
.. method:: Fraction.from_decimal(dec)
4343

44-
This classmethod constructs a :class:`Rational` representing the
44+
This classmethod constructs a :class:`Fraction` representing the
4545
exact value of *dec*, which must be a
4646
:class:`decimal.Decimal`.
4747

4848

49-
.. method:: Rational.__floor__()
49+
.. method:: Fraction.__floor__()
5050

5151
Returns the greatest :class:`int` ``<= self``. Will be accessible
5252
through :func:`math.floor` in Py3k.
5353

5454

55-
.. method:: Rational.__ceil__()
55+
.. method:: Fraction.__ceil__()
5656

5757
Returns the least :class:`int` ``>= self``. Will be accessible
5858
through :func:`math.ceil` in Py3k.
5959

6060

61-
.. method:: Rational.__round__()
62-
Rational.__round__(ndigits)
61+
.. method:: Fraction.__round__()
62+
Fraction.__round__(ndigits)
6363

6464
The first version returns the nearest :class:`int` to ``self``,
6565
rounding half to even. The second version rounds ``self`` to the
66-
nearest multiple of ``Rational(1, 10**ndigits)`` (logically, if
66+
nearest multiple of ``Fraction(1, 10**ndigits)`` (logically, if
6767
``ndigits`` is negative), again rounding half toward even. Will be
6868
accessible through :func:`round` in Py3k.
6969

Doc/library/numbers.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ Notes for type implementors
104104

105105
Implementors should be careful to make equal numbers equal and hash
106106
them to the same values. This may be subtle if there are two different
107-
extensions of the real numbers. For example, :class:`rational.Rational`
107+
extensions of the real numbers. For example, :class:`fractions.Fraction`
108108
implements :func:`hash` as follows::
109109

110110
def __hash__(self):
@@ -199,11 +199,11 @@ in :class:`complex`, and both :meth:`__radd__` s land there, so ``a+b
199199
Because most of the operations on any given type will be very similar,
200200
it can be useful to define a helper function which generates the
201201
forward and reverse instances of any given operator. For example,
202-
:class:`rational.Rational` uses::
202+
:class:`fractions.Fraction` uses::
203203

204204
def _operator_fallbacks(monomorphic_operator, fallback_operator):
205205
def forward(a, b):
206-
if isinstance(b, (int, long, Rational)):
206+
if isinstance(b, (int, long, Fraction)):
207207
return monomorphic_operator(a, b)
208208
elif isinstance(b, float):
209209
return fallback_operator(float(a), b)
@@ -215,7 +215,7 @@ forward and reverse instances of any given operator. For example,
215215
forward.__doc__ = monomorphic_operator.__doc__
216216

217217
def reverse(b, a):
218-
if isinstance(a, RationalAbc):
218+
if isinstance(a, Rational):
219219
# Includes ints.
220220
return monomorphic_operator(a, b)
221221
elif isinstance(a, numbers.Real):
@@ -231,7 +231,7 @@ forward and reverse instances of any given operator. For example,
231231

232232
def _add(a, b):
233233
"""a + b"""
234-
return Rational(a.numerator * b.denominator +
234+
return Fraction(a.numerator * b.denominator +
235235
b.numerator * a.denominator,
236236
a.denominator * b.denominator)
237237

Doc/library/pickletools.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,10 @@ probably won't find the :mod:`pickletools` module relevant.
3333
the opcode's argument; *pos* is the position at which this opcode is located.
3434
*pickle* can be a string or a file-like object.
3535

36+
.. function:: optimize(picklestring)
37+
38+
Returns a new equivalent pickle string after eliminating unused ``PUT``
39+
opcodes. The optimized pickle is shorter, takes less transmission time,
40+
requires less storage space, and unpickles more efficiently.
41+
42+
.. versionadded:: 2.6

Doc/whatsnew/2.6.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,8 @@ and comparisons.
578578

579579
:class:`Rational` numbers derive from :class:`Real`, have
580580
:attr:`numerator` and :attr:`denominator` properties, and can be
581-
converted to floats. Python 2.6 adds a simple rational-number class
582-
in the :mod:`rational` module.
581+
converted to floats. Python 2.6 adds a simple rational-number class,
582+
:class:`Fraction`, in the :mod:`fractions` module.
583583

584584
:class:`Integral` numbers derive from :class:`Rational`, and
585585
can be shifted left and right with ``<<`` and ``>>``,
@@ -598,29 +598,29 @@ one, :func:`trunc`, that's been backported to Python 2.6.
598598

599599

600600

601-
The Rational Module
601+
The Fraction Module
602602
--------------------------------------------------
603603

604604
To fill out the hierarchy of numeric types, a rational-number class
605-
has been added as the :mod:`rational` module. Rational numbers are
605+
has been added as the :mod:`fractions` module. Rational numbers are
606606
represented as a fraction; rational numbers can exactly represent
607607
numbers such as two-thirds that floating-point numbers can only
608608
approximate.
609609

610-
The :class:`Rational` constructor takes two :class:`Integral` values
610+
The :class:`Fraction` constructor takes two :class:`Integral` values
611611
that will be the numerator and denominator of the resulting fraction. ::
612612

613-
>>> from rational import Rational
614-
>>> a = Rational(2, 3)
615-
>>> b = Rational(2, 5)
613+
>>> from fractions import Fraction
614+
>>> a = Fraction(2, 3)
615+
>>> b = Fraction(2, 5)
616616
>>> float(a), float(b)
617617
(0.66666666666666663, 0.40000000000000002)
618618
>>> a+b
619-
rational.Rational(16,15)
619+
Fraction(16, 15)
620620
>>> a/b
621-
rational.Rational(5,3)
621+
Fraction(5, 3)
622622

623-
The :mod:`rational` module is based upon an implementation by Sjoerd
623+
The :mod:`fractions` module is based upon an implementation by Sjoerd
624624
Mullender that was in Python's :file:`Demo/classes/` directory for a
625625
long time. This implementation was significantly updated by Jeffrey
626626
Yaskin.

Lib/decimal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ def _cmp(self, other):
802802
# != comparisons involving a NaN always return True
803803
# <, >, <= and >= comparisons involving a (quiet or signaling)
804804
# NaN signal InvalidOperation, and return False if the
805-
# InvalidOperation is trapped.
805+
# InvalidOperation is not trapped.
806806
#
807807
# This behavior is designed to conform as closely as possible to
808808
# that specified by IEEE 754.

0 commit comments

Comments
 (0)