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

Skip to content

Commit 6ebe78f

Browse files
committed
Merged revisions 67654,67676-67677,67681,67692,67725,67761,67784-67785,67787-67788,67802,67848-67850,67862-67864,67880,67882 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r67654 | georg.brandl | 2008-12-07 16:42:09 -0600 (Sun, 07 Dec 2008) | 2 lines #4457: rewrite __import__() documentation. ........ r67676 | benjamin.peterson | 2008-12-08 20:03:03 -0600 (Mon, 08 Dec 2008) | 1 line specify how things are copied ........ r67677 | benjamin.peterson | 2008-12-08 20:05:11 -0600 (Mon, 08 Dec 2008) | 1 line revert unrelated change to installer script ........ r67681 | jeremy.hylton | 2008-12-09 15:03:10 -0600 (Tue, 09 Dec 2008) | 2 lines Add simple unittests for Request ........ r67692 | amaury.forgeotdarc | 2008-12-10 18:03:42 -0600 (Wed, 10 Dec 2008) | 2 lines #1030250: correctly pass the dry_run option to the mkpath() function. ........ r67725 | benjamin.peterson | 2008-12-12 22:02:20 -0600 (Fri, 12 Dec 2008) | 1 line fix incorrect example ........ r67761 | benjamin.peterson | 2008-12-14 11:26:04 -0600 (Sun, 14 Dec 2008) | 1 line fix missing bracket ........ r67784 | georg.brandl | 2008-12-15 02:33:58 -0600 (Mon, 15 Dec 2008) | 2 lines #4446: document "platforms" argument for setup(). ........ r67785 | georg.brandl | 2008-12-15 02:36:11 -0600 (Mon, 15 Dec 2008) | 2 lines #4611: fix typo. ........ r67787 | georg.brandl | 2008-12-15 02:58:59 -0600 (Mon, 15 Dec 2008) | 2 lines #4578: fix has_key() usage in compiler package. ........ r67788 | georg.brandl | 2008-12-15 03:07:39 -0600 (Mon, 15 Dec 2008) | 2 lines #4568: remove limitation in varargs callback example. ........ r67802 | amaury.forgeotdarc | 2008-12-15 16:29:14 -0600 (Mon, 15 Dec 2008) | 4 lines #3632: the "pyo" macro from gdbinit can now run when the GIL is released. Patch by haypo. ........ r67848 | benjamin.peterson | 2008-12-18 20:28:56 -0600 (Thu, 18 Dec 2008) | 1 line fix typo ........ r67849 | benjamin.peterson | 2008-12-18 20:31:35 -0600 (Thu, 18 Dec 2008) | 1 line _call_method -> _callmethod and _get_value to _getvalue ........ r67850 | raymond.hettinger | 2008-12-19 03:06:07 -0600 (Fri, 19 Dec 2008) | 9 lines Fix-up and clean-up docs for int.bit_length(). * Replace dramatic footnote with in-line comment about possible round-off errors in logarithms of large numbers. * Add comments to the pure python code equivalent. * replace floor() with int() in the mathematical equivalent so the type is correct (should be an int, not a float). * add abs() to the mathematical equivalent so that it matches the previous line that it is supposed to be equivalent to. * make one combined example with a negative input. ........ r67862 | benjamin.peterson | 2008-12-19 20:48:02 -0600 (Fri, 19 Dec 2008) | 1 line copy sentence from docstring ........ r67863 | benjamin.peterson | 2008-12-19 20:51:26 -0600 (Fri, 19 Dec 2008) | 1 line add headings ........ r67864 | benjamin.peterson | 2008-12-19 20:57:19 -0600 (Fri, 19 Dec 2008) | 1 line beef up docstring ........ r67880 | benjamin.peterson | 2008-12-20 16:49:24 -0600 (Sat, 20 Dec 2008) | 1 line remove redundant sentence ........ r67882 | benjamin.peterson | 2008-12-20 16:59:49 -0600 (Sat, 20 Dec 2008) | 1 line add some recent releases to the list ........
1 parent f767050 commit 6ebe78f

16 files changed

Lines changed: 173 additions & 98 deletions

File tree

Doc/distutils/setupscript.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,8 @@ This information includes:
561561
+----------------------+---------------------------+-----------------+--------+
562562
| ``classifiers`` | a list of classifiers | list of strings | \(4) |
563563
+----------------------+---------------------------+-----------------+--------+
564+
| ``platforms`` | a list of platforms | list of strings | |
565+
+----------------------+---------------------------+-----------------+--------+
564566

565567
Notes:
566568

Doc/extending/extending.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ memory and should be avoided completely. [#]_
882882
The advantage of borrowing over owning a reference is that you don't need to
883883
take care of disposing of the reference on all possible paths through the code
884884
--- in other words, with a borrowed reference you don't run the risk of leaking
885-
when a premature exit is taken. The disadvantage of borrowing over leaking is
885+
when a premature exit is taken. The disadvantage of borrowing over owning is
886886
that there are some subtle situations where in seemingly correct code a borrowed
887887
reference can be used after the owner from which it was borrowed has in fact
888888
disposed of it.

Doc/howto/functional.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -677,11 +677,10 @@ indexes at which certain conditions are met::
677677
if line.strip() == '':
678678
print('Blank line at line #%i' % i)
679679

680-
681-
``sorted(iterable, [cmp=None], [key=None], [reverse=False)`` collects all the
682-
elements of the iterable into a list, sorts the list, and returns the sorted
683-
result. The ``cmp``, ``key``, and ``reverse`` arguments are passed through to
684-
the constructed list's ``.sort()`` method. ::
680+
``sorted(iterable, [key=None], [reverse=False])`` collects all the elements of
681+
the iterable into a list, sorts the list, and returns the sorted result. The
682+
``key``, and ``reverse`` arguments are passed through to the constructed list's
683+
``.sort()`` method. ::
685684

686685
>>> import random
687686
>>> # Generate 8 random numbers between [0, 10000)

Doc/library/functions.rst

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,47 +1172,64 @@ are always available. They are listed here in alphabetical order.
11721172
This is an advanced function that is not needed in everyday Python
11731173
programming.
11741174

1175-
The function is invoked by the :keyword:`import` statement. It mainly exists
1176-
so that you can replace it with another function that has a compatible
1177-
interface, in order to change the semantics of the :keyword:`import`
1178-
statement. See the built-in module :mod:`imp`, which defines some useful
1179-
operations out of which you can build your own :func:`__import__` function.
1180-
1181-
For example, the statement ``import spam`` results in the following call:
1182-
``__import__('spam', globals(), locals(), [], -1)``; the statement
1183-
``from spam.ham import eggs`` results in ``__import__('spam.ham', globals(),
1184-
locals(), ['eggs'], -1)``. Note that even though ``locals()`` and ``['eggs']``
1185-
are passed in as arguments, the :func:`__import__` function does not set the
1186-
local variable named ``eggs``; this is done by subsequent code that is generated
1187-
for the import statement. (In fact, the standard implementation does not use
1188-
its *locals* argument at all, and uses its *globals* only to determine the
1189-
package context of the :keyword:`import` statement.)
1175+
This function is invoked by the :keyword:`import` statement. It can be
1176+
replaced (by importing the :mod:`builtins` module and assigning to
1177+
``builtins.__import__``) in order to change semantics of the
1178+
:keyword:`import` statement, but nowadays it is usually simpler to use import
1179+
hooks (see :pep:`302`). Direct use of :func:`__import__` is rare, except in
1180+
cases where you want to import a module whose name is only known at runtime.
1181+
1182+
The function imports the module *name*, potentially using the given *globals*
1183+
and *locals* to determine how to interpret the name in a package context.
1184+
The *fromlist* gives the names of objects or submodules that should be
1185+
imported from the module given by *name*. The standard implementation does
1186+
not use its *locals* argument at all, and uses its *globals* only to
1187+
determine the package context of the :keyword:`import` statement.
1188+
1189+
*level* specifies whether to use absolute or relative imports. The default
1190+
is ``-1`` which indicates both absolute and relative imports will be
1191+
attempted. ``0`` means only perform absolute imports. Positive values for
1192+
*level* indicate the number of parent directories to search relative to the
1193+
directory of the module calling :func:`__import__`.
11901194

11911195
When the *name* variable is of the form ``package.module``, normally, the
11921196
top-level package (the name up till the first dot) is returned, *not* the
11931197
module named by *name*. However, when a non-empty *fromlist* argument is
1194-
given, the module named by *name* is returned. This is done for
1195-
compatibility with the :term:`bytecode` generated for the different kinds of import
1196-
statement; when using ``import spam.ham.eggs``, the top-level package
1197-
:mod:`spam` must be placed in the importing namespace, but when using ``from
1198-
spam.ham import eggs``, the ``spam.ham`` subpackage must be used to find the
1199-
``eggs`` variable. As a workaround for this behavior, use :func:`getattr` to
1200-
extract the desired components. For example, you could define the following
1201-
helper::
1202-
1203-
def my_import(name):
1204-
mod = __import__(name)
1205-
components = name.split('.')
1206-
for comp in components[1:]:
1207-
mod = getattr(mod, comp)
1208-
return mod
1209-
1210-
*level* specifies whether to use absolute or relative imports. The default is
1211-
``-1`` which indicates both absolute and relative imports will be attempted.
1212-
``0`` means only perform absolute imports. Positive values for *level* indicate
1213-
the number of parent directories to search relative to the directory of the
1214-
module calling :func:`__import__`.
1198+
given, the module named by *name* is returned.
12151199

1200+
For example, the statement ``import spam`` results in bytecode resembling the
1201+
following code::
1202+
1203+
spam = __import__('spam', globals(), locals(), [], -1)
1204+
1205+
The statement ``import spam.ham`` results in this call::
1206+
1207+
spam = __import__('spam.ham', globals(), locals(), [], -1)
1208+
1209+
Note how :func:`__import__` returns the toplevel module here because this is
1210+
the object that is bound to a name by the :keyword:`import` statement.
1211+
1212+
On the other hand, the statement ``from spam.ham import eggs, sausage as
1213+
saus`` results in ::
1214+
1215+
_temp = __import__('spam.ham', globals(), locals(), ['eggs', 'sausage'], -1)
1216+
eggs = _temp.eggs
1217+
saus = _temp.sausage
1218+
1219+
Here, the ``spam.ham`` module is returned from :func:`__import__`. From this
1220+
object, the names to import are retrieved and assigned to their respective
1221+
names.
1222+
1223+
If you simply want to import a module (potentially within a package) by name,
1224+
you can get it from :data:`sys.modules`::
1225+
1226+
>>> import sys
1227+
>>> name = 'foo.bar.baz'
1228+
>>> __import__(name)
1229+
<module 'foo' from ...>
1230+
>>> baz = sys.modules[name]
1231+
>>> baz
1232+
<module 'foo.bar.baz' from ...>
12161233

12171234
.. rubric:: Footnotes
12181235

Doc/library/math.rst

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ was generated in the first place.
2121
The following functions are provided by this module. Except when explicitly
2222
noted otherwise, all return values are floats.
2323

24-
Number-theoretic and representation functions:
2524

25+
Number-theoretic and representation functions
26+
---------------------------------------------
2627

2728
.. function:: ceil(x)
2829

@@ -110,8 +111,8 @@ Number-theoretic and representation functions:
110111

111112
.. function:: modf(x)
112113

113-
Return the fractional and integer parts of *x*. Both results carry the sign of
114-
*x*, and both are floats.
114+
Return the fractional and integer parts of *x*. Both results carry the sign
115+
of *x* and are floats.
115116

116117

117118
.. function:: trunc(x)
@@ -131,7 +132,9 @@ Python floats typically carry no more than 53 bits of precision (the same as the
131132
platform C double type), in which case any float *x* with ``abs(x) >= 2**52``
132133
necessarily has no fractional bits.
133134

134-
Power and logarithmic functions:
135+
136+
Power and logarithmic functions
137+
-------------------------------
135138

136139
.. function:: exp(x)
137140

@@ -169,7 +172,8 @@ Power and logarithmic functions:
169172

170173
Return the square root of *x*.
171174

172-
Trigonometric functions:
175+
Trigonometric functions
176+
-----------------------
173177

174178

175179
.. function:: acos(x)
@@ -217,7 +221,8 @@ Trigonometric functions:
217221

218222
Return the tangent of *x* radians.
219223

220-
Angular conversion:
224+
Angular conversion
225+
------------------
221226

222227

223228
.. function:: degrees(x)
@@ -229,7 +234,8 @@ Angular conversion:
229234

230235
Converts angle *x* from degrees to radians.
231236

232-
Hyperbolic functions:
237+
Hyperbolic functions
238+
--------------------
233239

234240

235241
.. function:: acosh(x)
@@ -262,9 +268,8 @@ Hyperbolic functions:
262268
Return the hyperbolic tangent of *x*.
263269

264270

265-
266-
The module also defines two mathematical constants:
267-
271+
Constants
272+
=========
268273

269274
.. data:: pi
270275

Doc/library/multiprocessing.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,13 +1436,13 @@ itself. This means, for example, that one shared object can contain a second::
14361436

14371437
Proxy objects are instances of subclasses of :class:`BaseProxy`.
14381438

1439-
.. method:: _call_method(methodname[, args[, kwds]])
1439+
.. method:: _callmethod(methodname[, args[, kwds]])
14401440

14411441
Call and return the result of a method of the proxy's referent.
14421442

14431443
If ``proxy`` is a proxy whose referent is ``obj`` then the expression ::
14441444

1445-
proxy._call_method(methodname, args, kwds)
1445+
proxy._callmethod(methodname, args, kwds)
14461446

14471447
will evaluate the expression ::
14481448

@@ -1455,26 +1455,26 @@ itself. This means, for example, that one shared object can contain a second::
14551455
argument of :meth:`BaseManager.register`.
14561456

14571457
If an exception is raised by the call, then then is re-raised by
1458-
:meth:`_call_method`. If some other exception is raised in the manager's
1458+
:meth:`_callmethod`. If some other exception is raised in the manager's
14591459
process then this is converted into a :exc:`RemoteError` exception and is
1460-
raised by :meth:`_call_method`.
1460+
raised by :meth:`_callmethod`.
14611461

14621462
Note in particular that an exception will be raised if *methodname* has
14631463
not been *exposed*
14641464

1465-
An example of the usage of :meth:`_call_method`::
1465+
An example of the usage of :meth:`_callmethod`::
14661466

14671467
>>> l = manager.list(range(10))
1468-
>>> l._call_method('__len__')
1468+
>>> l._callmethod('__len__')
14691469
10
1470-
>>> l._call_method('__getslice__', (2, 7)) # equiv to `l[2:7]`
1470+
>>> l._callmethod('__getslice__', (2, 7)) # equiv to `l[2:7]`
14711471
[2, 3, 4, 5, 6]
1472-
>>> l._call_method('__getitem__', (20,)) # equiv to `l[20]`
1472+
>>> l._callmethod('__getitem__', (20,)) # equiv to `l[20]`
14731473
Traceback (most recent call last):
14741474
...
14751475
IndexError: list index out of range
14761476

1477-
.. method:: _get_value()
1477+
.. method:: _getvalue()
14781478

14791479
Return a copy of the referent.
14801480

Doc/library/optparse.rst

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,36 +1625,33 @@ directly).
16251625
Nevertheless, here's a stab at a callback for an option with variable
16261626
arguments::
16271627

1628-
def vararg_callback(option, opt_str, value, parser):
1629-
assert value is None
1630-
done = 0
1631-
value = []
1632-
rargs = parser.rargs
1633-
while rargs:
1634-
arg = rargs[0]
1635-
1636-
# Stop if we hit an arg like "--foo", "-a", "-fx", "--file=f",
1637-
# etc. Note that this also stops on "-3" or "-3.0", so if
1638-
# your option takes numeric values, you will need to handle
1639-
# this.
1640-
if ((arg[:2] == "--" and len(arg) > 2) or
1641-
(arg[:1] == "-" and len(arg) > 1 and arg[1] != "-")):
1642-
break
1643-
else:
1644-
value.append(arg)
1645-
del rargs[0]
1646-
1647-
setattr(parser.values, option.dest, value)
1628+
def vararg_callback(option, opt_str, value, parser):
1629+
assert value is None
1630+
value = []
1631+
1632+
def floatable(str):
1633+
try:
1634+
float(str)
1635+
return True
1636+
except ValueError:
1637+
return False
1638+
1639+
for arg in parser.rargs:
1640+
# stop on --foo like options
1641+
if arg[:2] == "--" and len(arg) > 2:
1642+
break
1643+
# stop on -a, but not on -3 or -3.0
1644+
if arg[:1] == "-" and len(arg) > 1 and not floatable(arg):
1645+
break
1646+
value.append(arg)
1647+
1648+
del parser.rargs[:len(value)]
1649+
setattr(parser.values, option.dest, value))
16481650

16491651
[...]
16501652
parser.add_option("-c", "--callback", dest="vararg_attr",
16511653
action="callback", callback=vararg_callback)
16521654

1653-
The main weakness with this particular implementation is that negative numbers
1654-
in the arguments following ``"-c"`` will be interpreted as further options
1655-
(probably causing an error), rather than as arguments to ``"-c"``. Fixing this
1656-
is left as an exercise for the reader.
1657-
16581655

16591656
.. _optparse-extending-optparse:
16601657

Doc/library/shutil.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ copying and removal. For operations on individual files, see also the
139139
Recursively move a file or directory to another location.
140140

141141
If the destination is on the current filesystem, then simply use rename.
142-
Otherwise, copy src to the dst and then remove src.
142+
Otherwise, copy src (with :func:`copy2`) to the dst and then remove src.
143143

144144

145145
.. exception:: Error

Doc/library/signal.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ The variables defined in the :mod:`signal` module are:
5252

5353
.. data:: SIG_DFL
5454

55-
This is one of two standard signal handling options; it will simply perform the
56-
default function for the signal. For example, on most systems the default
57-
action for :const:`SIGQUIT` is to dump core and exit, while the default action
58-
for :const:`SIGCLD` is to simply ignore it.
55+
This is one of two standard signal handling options; it will simply perform
56+
the default function for the signal. For example, on most systems the
57+
default action for :const:`SIGQUIT` is to dump core and exit, while the
58+
default action for :const:`SIGCHLD` is to simply ignore it.
5959

6060

6161
.. data:: SIG_IGN

Doc/library/stdtypes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ Additional Methods on Integer Types
442442
Equivalent to::
443443

444444
def bit_length(self):
445-
s = bin(self) # binary representation: bin(-37) --> '-0b100101'
445+
s = bin(x) # binary representation: bin(-37) --> '-0b100101'
446446
s = s.lstrip('-0b') # remove leading zeros and minus sign
447447
return len(s) # len('100101') --> 6
448448

0 commit comments

Comments
 (0)