Skip to content

Commit 072c0f1

Browse files
committed
Merged revisions 59666-59679 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r59666 | christian.heimes | 2008-01-02 19:28:32 +0100 (Wed, 02 Jan 2008) | 1 line Made vs9to8 Unix compatible ........ r59669 | guido.van.rossum | 2008-01-02 20:00:46 +0100 (Wed, 02 Jan 2008) | 2 lines Patch python#1696. Don't attempt to close None in dry-run mode. ........ r59671 | jeffrey.yasskin | 2008-01-03 03:21:52 +0100 (Thu, 03 Jan 2008) | 6 lines Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just the complex_pow part), r56649, r56652, r56715, r57296, r57302, r57359, r57361, r57372, r57738, r57739, r58017, r58039, r58040, and r59390, and new documentation. The only significant difference is that round(x) returns a float to preserve backward-compatibility. See http://bugs.python.org/issue1689. ........ r59672 | christian.heimes | 2008-01-03 16:41:30 +0100 (Thu, 03 Jan 2008) | 1 line Issue python#1726: Remove Python/atof.c from PCBuild/pythoncore.vcproj ........ r59675 | guido.van.rossum | 2008-01-03 20:12:44 +0100 (Thu, 03 Jan 2008) | 4 lines Issue python#1700, reported by Nguyen Quan Son, fix by Fredruk Lundh: Regular Expression inline flags not handled correctly for some unicode characters. (Forward port from 2.5.2.) ........ r59676 | christian.heimes | 2008-01-03 21:23:15 +0100 (Thu, 03 Jan 2008) | 1 line Added math.isinf() and math.isnan() ........ r59677 | christian.heimes | 2008-01-03 22:14:48 +0100 (Thu, 03 Jan 2008) | 1 line Some build bots don't compile mathmodule. There is an issue with the long definition of pi and euler ........ r59678 | christian.heimes | 2008-01-03 23:16:32 +0100 (Thu, 03 Jan 2008) | 2 lines Modified PyImport_Import and PyImport_ImportModule to always use absolute imports by calling __import__ with an explicit level of 0 Added a new API function PyImport_ImportModuleNoBlock. It solves the problem with dead locks when mixing threads and imports ........ r59679 | christian.heimes | 2008-01-03 23:32:26 +0100 (Thu, 03 Jan 2008) | 1 line Added copysign(x, y) function to the math module ........
1 parent 1c9f437 commit 072c0f1

32 files changed

Lines changed: 383 additions & 83 deletions

Doc/c-api/utilities.rst

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ Importing Modules
184184
single: modules (in module sys)
185185

186186
This is a simplified interface to :cfunc:`PyImport_ImportModuleEx` below,
187-
leaving the *globals* and *locals* arguments set to *NULL*. When the *name*
187+
leaving the *globals* and *locals* arguments set to *NULL* and *level* set
188+
to 0. When the *name*
188189
argument contains a dot (when it specifies a submodule of a package), the
189190
*fromlist* argument is set to the list ``['*']`` so that the return value is the
190191
named module rather than the top-level package containing it as would otherwise
@@ -196,6 +197,27 @@ Importing Modules
196197
to find out. Starting with Python 2.4, a failing import of a module no longer
197198
leaves the module in ``sys.modules``.
198199

200+
.. versionchanged:: 2.6
201+
always use absolute imports
202+
203+
.. index:: single: modules (in module sys)
204+
205+
206+
.. cfunction:: PyObject* PyImport_ImportModuleNoBlock(const char *name)
207+
208+
.. index::
209+
single: `cfunc:PyImport_ImportModule`
210+
211+
This version of `cfunc:PyImport_ImportModule` does not block. It's intended
212+
to be used in C function which import other modules to execute a function.
213+
The import may block if another thread holds the import lock. The function
214+
`cfunc:PyImport_ImportModuleNoBlock` doesn't block. It first tries to fetch
215+
the module from sys.modules and falls back to `cfunc:PyImport_ImportModule`
216+
unless the the lock is hold. In the latter case the function raises an
217+
ImportError.
218+
219+
.. versionadded:: 2.6
220+
199221

200222
.. cfunction:: PyObject* PyImport_ImportModuleEx(char *name, PyObject *globals, PyObject *locals, PyObject *fromlist)
201223

@@ -214,6 +236,24 @@ Importing Modules
214236
Failing imports remove incomplete module objects, like with
215237
:cfunc:`PyImport_ImportModule`.
216238

239+
.. versionchanged:: 2.6
240+
The function is an alias for `cfunc:PyImport_ImportModuleLevel` with
241+
-1 as level, meaning relative import.
242+
243+
244+
.. cfunction:: PyObject* PyImport_ImportModuleLevel(char *name, PyObject *globals, PyObject *locals, PyObject *fromlist, int level)
245+
246+
Import a module. This is best described by referring to the built-in Python
247+
function :func:`__import__`, as the standard :func:`__import__` function calls
248+
this function directly.
249+
250+
The return value is a new reference to the imported module or top-level package,
251+
or *NULL* with an exception set on failure. Like for :func:`__import__`,
252+
the return value when a submodule of a package was requested is normally the
253+
top-level package, unless a non-empty *fromlist* was given.
254+
255+
..versionadded:: 2.5
256+
217257

218258
.. cfunction:: PyObject* PyImport_Import(PyObject *name)
219259

@@ -222,6 +262,9 @@ Importing Modules
222262
current globals. This means that the import is done using whatever import hooks
223263
are installed in the current environment.
224264

265+
.. versionchanged:: 2.6
266+
always use absolute imports
267+
225268

226269
.. cfunction:: PyObject* PyImport_ReloadModule(PyObject *m)
227270

Doc/library/functions.rst

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -915,10 +915,13 @@ available. They are listed here in alphabetical order.
915915
.. function:: round(x[, n])
916916

917917
Return the floating point value *x* rounded to *n* digits after the decimal
918-
point. If *n* is omitted, it defaults to zero. The result is a floating point
919-
number. Values are rounded to the closest multiple of 10 to the power minus
920-
*n*; if two multiples are equally close, rounding is done away from 0 (so. for
921-
example, ``round(0.5)`` is ``1.0`` and ``round(-0.5)`` is ``-1.0``).
918+
point. If *n* is omitted, it defaults to zero. Values are rounded to the
919+
closest multiple of 10 to the power minus *n*; if two multiples are equally
920+
close, rounding is done toward the even choice (so, for example, both
921+
``round(0.5)`` and ``round(-0.5)`` are ``0``, and ``round(1.5)`` is
922+
``2``). Delegates to ``x.__round__(n)``.
923+
924+
.. versionchanged:: 2.6
922925

923926

924927
.. function:: set([iterable])
@@ -1064,6 +1067,14 @@ available. They are listed here in alphabetical order.
10641067
operators such as ``super(C, self)[name]``.
10651068

10661069

1070+
.. function:: trunc(x)
1071+
1072+
Return the :class:`Real` value *x* truncated to an :class:`Integral` (usually
1073+
a long integer). Delegates to ``x.__trunc__()``.
1074+
1075+
.. versionadded:: 2.6
1076+
1077+
10671078
.. function:: tuple([iterable])
10681079

10691080
Return a tuple whose items are the same and in the same order as *iterable*'s

Doc/library/math.rst

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,17 @@ Number-theoretic and representation functions:
2626

2727
.. function:: ceil(x)
2828

29-
Return the ceiling of *x* as a float, the smallest integer value greater than or
30-
equal to *x*.
29+
Return the ceiling of *x* as a float, the smallest integer value greater than
30+
or equal to *x*. If *x* is not a float, delegates to ``x.__ceil__()``, which
31+
should return an :class:`Integral` value.
32+
33+
34+
.. function:: copysign(x, y)
35+
36+
Return *x* with the sign of *y*. ``copysign`` copies the sign bit of an IEEE
37+
754 float, ``copysign(1, -0.0)`` returns *-1.0*.
38+
39+
..versionadded:: 2.6
3140

3241

3342
.. function:: fabs(x)
@@ -37,8 +46,9 @@ Number-theoretic and representation functions:
3746

3847
.. function:: floor(x)
3948

40-
Return the floor of *x* as a float, the largest integer value less than or equal
41-
to *x*.
49+
Return the floor of *x* as a float, the largest integer value less than or
50+
equal to *x*. If *x* is not a float, delegates to ``x.__floor__()``, which
51+
should return an :class:`Integral` value.
4252

4353

4454
.. function:: fmod(x, y)
@@ -64,6 +74,23 @@ Number-theoretic and representation functions:
6474
apart" the internal representation of a float in a portable way.
6575

6676

77+
.. function:: isinf(x)
78+
79+
Checks if the float *x* is positive or negative infinite.
80+
81+
..versionadded:: 2.6
82+
83+
84+
.. function:: isnan(x)
85+
86+
Checks if the float *x* is a NaN (not a number). NaNs are part of the
87+
IEEE 754 standards. Operation like but not limited to ``inf * 0``,
88+
``inf / inf`` or any operation involving a NaN, e.g. ``nan * 1``, return
89+
a NaN.
90+
91+
..versionadded:: 2.6
92+
93+
6794
.. function:: ldexp(x, i)
6895

6996
Return ``x * (2**i)``. This is essentially the inverse of function

Doc/library/numbers.rst

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
2+
:mod:`numbers` --- Numeric abstract base classes
3+
================================================
4+
5+
.. module:: numbers
6+
:synopsis: Numeric abstract base classes (Complex, Real, Integral, etc.).
7+
8+
The :mod:`numbers` module (:pep:`3141`) defines a hierarchy of numeric abstract
9+
base classes which progressively define more operations. These concepts also
10+
provide a way to distinguish exact from inexact types. None of the types defined
11+
in this module can be instantiated.
12+
13+
14+
.. class:: Number
15+
16+
The root of the numeric hierarchy. If you just want to check if an argument
17+
*x* is a number, without caring what kind, use ``isinstance(x, Number)``.
18+
19+
20+
Exact and inexact operations
21+
----------------------------
22+
23+
.. class:: Exact
24+
25+
Subclasses of this type have exact operations.
26+
27+
As long as the result of a homogenous operation is of the same type, you can
28+
assume that it was computed exactly, and there are no round-off errors. Laws
29+
like commutativity and associativity hold.
30+
31+
32+
.. class:: Inexact
33+
34+
Subclasses of this type have inexact operations.
35+
36+
Given X, an instance of :class:`Inexact`, it is possible that ``(X + -X) + 3
37+
== 3``, but ``X + (-X + 3) == 0``. The exact form this error takes will vary
38+
by type, but it's generally unsafe to compare this type for equality.
39+
40+
41+
The numeric tower
42+
-----------------
43+
44+
.. class:: Complex
45+
46+
Subclasses of this type describe complex numbers and include the operations
47+
that work on the builtin :class:`complex` type. These are: conversions to
48+
:class:`complex` and :class:`bool`, :attr:`.real`, :attr:`.imag`, ``+``,
49+
``-``, ``*``, ``/``, :func:`abs`, :meth:`conjugate`, ``==``, and ``!=``. All
50+
except ``-`` and ``!=`` are abstract.
51+
52+
.. attribute:: Complex.real
53+
54+
Abstract. Retrieves the :class:`Real` component of this number.
55+
56+
.. attribute:: Complex.imag
57+
58+
Abstract. Retrieves the :class:`Real` component of this number.
59+
60+
.. method:: Complex.conjugate()
61+
62+
Abstract. Returns the complex conjugate. For example, ``(1+3j).conjugate() ==
63+
(1-3j)``.
64+
65+
.. class:: Real
66+
67+
To :class:`Complex`, :class:`Real` adds the operations that work on real
68+
numbers.
69+
70+
In short, those are: a conversion to :class:`float`, :func:`trunc`,
71+
:func:`round`, :func:`math.floor`, :func:`math.ceil`, :func:`divmod`, ``//``,
72+
``%``, ``<``, ``<=``, ``>``, and ``>=``.
73+
74+
Real also provides defaults for :func:`complex`, :attr:`Complex.real`,
75+
:attr:`Complex.imag`, and :meth:`Complex.conjugate`.
76+
77+
78+
.. class:: Rational
79+
80+
Subtypes both :class:`Real` and :class:`Exact`, and adds
81+
:attr:`Rational.numerator` and :attr:`Rational.denominator` properties, which
82+
should be in lowest terms. With these, it provides a default for
83+
:func:`float`.
84+
85+
.. attribute:: Rational.numerator
86+
87+
Abstract.
88+
89+
.. attribute:: Rational.denominator
90+
91+
Abstract.
92+
93+
94+
.. class:: Integral
95+
96+
Subtypes :class:`Rational` and adds a conversion to :class:`long`, the
97+
3-argument form of :func:`pow`, and the bit-string operations: ``<<``,
98+
``>>``, ``&``, ``^``, ``|``, ``~``. Provides defaults for :func:`float`,
99+
:attr:`Rational.numerator`, and :attr:`Rational.denominator`.

Doc/library/numeric.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@ Numeric and Mathematical Modules
66
********************************
77

88
The modules described in this chapter provide numeric and math-related functions
9-
and data types. The :mod:`math` and :mod:`cmath` contain various mathematical
10-
functions for floating-point and complex numbers. For users more interested in
11-
decimal accuracy than in speed, the :mod:`decimal` module supports exact
12-
representations of decimal numbers.
9+
and data types. The :mod:`numbers` module defines an abstract hierarchy of
10+
numeric types. The :mod:`math` and :mod:`cmath` modules contain various
11+
mathematical functions for floating-point and complex numbers. For users more
12+
interested in decimal accuracy than in speed, the :mod:`decimal` module supports
13+
exact representations of decimal numbers.
1314

1415
The following modules are documented in this chapter:
1516

1617

1718
.. toctree::
1819

20+
numbers.rst
1921
math.rst
2022
cmath.rst
2123
decimal.rst

Doc/reference/datamodel.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ Ellipsis
152152
object is accessed through the literal ``...`` or the built-in name
153153
``Ellipsis``. Its truth value is true.
154154

155-
Numbers
155+
:class:`numbers.Number`
156156
.. index:: object: numeric
157157

158158
These are created by numeric literals and returned as results by arithmetic
@@ -164,7 +164,7 @@ Numbers
164164
Python distinguishes between integers, floating point numbers, and complex
165165
numbers:
166166

167-
Integers
167+
:class:`numbers.Integral`
168168
.. index:: object: integer
169169

170170
These represent elements from the mathematical set of integers (positive and
@@ -202,7 +202,7 @@ Numbers
202202
operation except left shift, if it yields a result in the plain integer domain
203203
without causing overflow, will yield the same result when using mixed operands.
204204

205-
Floating point numbers
205+
:class:`numbers.Real` (:class:`float`)
206206
.. index::
207207
object: floating point
208208
pair: floating point; number
@@ -217,7 +217,7 @@ Numbers
217217
overhead of using objects in Python, so there is no reason to complicate the
218218
language with two kinds of floating point numbers.
219219

220-
Complex numbers
220+
:class:`numbers.Complex`
221221
.. index::
222222
object: complex
223223
pair: complex; number

Doc/reference/expressions.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,8 @@ float result is delivered. For example, ``10**2`` returns ``100``, but
768768
``10**-2`` returns ``0.01``.
769769

770770
Raising ``0.0`` to a negative power results in a :exc:`ZeroDivisionError`.
771-
Raising a negative number to a fractional power results in a :exc:`ValueError`.
771+
Raising a negative number to a fractional power results in a :class:`complex`
772+
number. (Since Python 2.6. In earlier versions it raised a :exc:`ValueError`.)
772773

773774

774775
.. _unary:

Include/import.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@ PyAPI_FUNC(PyObject *) PyImport_ExecCodeModuleEx(
1414
PyAPI_FUNC(PyObject *) PyImport_GetModuleDict(void);
1515
PyAPI_FUNC(PyObject *) PyImport_AddModule(const char *name);
1616
PyAPI_FUNC(PyObject *) PyImport_ImportModule(const char *name);
17+
PyAPI_FUNC(PyObject *) PyImport_ImportModuleNoBlock(const char *);
1718
PyAPI_FUNC(PyObject *) PyImport_ImportModuleLevel(char *name,
1819
PyObject *globals, PyObject *locals, PyObject *fromlist, int level);
1920

20-
/* For DLL compatibility */
21-
#undef PyImport_ImportModuleEx
22-
PyAPI_FUNC(PyObject *) PyImport_ImportModuleEx(
23-
char *name, PyObject *globals, PyObject *locals, PyObject *fromlist);
2421
#define PyImport_ImportModuleEx(n, g, l, f) \
2522
PyImport_ImportModuleLevel(n, g, l, f, -1)
2623

Include/py_curses.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static void **PyCurses_API;
9090

9191
#define import_curses() \
9292
{ \
93-
PyObject *module = PyImport_ImportModule("_curses"); \
93+
PyObject *module = PyImport_ImportModuleNoBlock("_curses"); \
9494
if (module != NULL) { \
9595
PyObject *module_dict = PyModule_GetDict(module); \
9696
PyObject *c_api_object = PyDict_GetItemString(module_dict, "_C_API"); \

Include/pyport.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,12 +335,19 @@ extern "C" {
335335
/* High precision defintion of pi and e (Euler)
336336
* The values are taken from libc6's math.h.
337337
*/
338+
#ifndef Py_MATH_PIl
339+
#define Py_MATH_PIl 3.1415926535897932384626433832795029L
340+
#endif
338341
#ifndef Py_MATH_PI
339-
#define Py_MATH_PI 3.1415926535897932384626433832795029L
342+
#define Py_MATH_PI 3.14159265358979323846
343+
#endif
344+
345+
#ifndef Py_MATH_El
346+
#define Py_MATH_El 2.7182818284590452353602874713526625L
340347
#endif
341348

342349
#ifndef Py_MATH_E
343-
#define Py_MATH_E 2.7182818284590452353602874713526625L
350+
#define Py_MATH_E 2.7182818284590452354
344351
#endif
345352

346353
/* Py_IS_NAN(X)

0 commit comments

Comments
 (0)