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

Skip to content

Commit 69cfcab

Browse files
Merge.
2 parents 2008a8f + e6c1eb9 commit 69cfcab

62 files changed

Lines changed: 1612 additions & 449 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Doc/library/argparse.rst

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -351,18 +351,20 @@ Note that most parent parsers will specify ``add_help=False``. Otherwise, the
351351
:class:`ArgumentParser` will see two ``-h/--help`` options (one in the parent
352352
and one in the child) and raise an error.
353353

354+
.. note::
355+
You must fully initialize the parsers before passing them via ``parents=``.
356+
If you change the parent parsers after the child parser, those changes will
357+
not be reflected in the child.
358+
354359

355360
formatter_class
356361
^^^^^^^^^^^^^^^
357362

358363
:class:`ArgumentParser` objects allow the help formatting to be customized by
359-
specifying an alternate formatting class. Currently, there are three such
360-
classes: :class:`argparse.RawDescriptionHelpFormatter`,
361-
:class:`argparse.RawTextHelpFormatter` and
362-
:class:`argparse.ArgumentDefaultsHelpFormatter`. The first two allow more
363-
control over how textual descriptions are displayed, while the last
364-
automatically adds information about argument default values.
364+
specifying an alternate formatting class.
365365

366+
:class:`RawDescriptionHelpFormatter` and :class:`RawTextHelpFormatter` give
367+
more control over how textual descriptions are displayed.
366368
By default, :class:`ArgumentParser` objects line-wrap the description_ and
367369
epilog_ texts in command-line help messages::
368370

@@ -386,7 +388,7 @@ epilog_ texts in command-line help messages::
386388
likewise for this epilog whose whitespace will be cleaned up and whose words
387389
will be wrapped across a couple lines
388390

389-
Passing :class:`argparse.RawDescriptionHelpFormatter` as ``formatter_class=``
391+
Passing :class:`RawDescriptionHelpFormatter` as ``formatter_class=``
390392
indicates that description_ and epilog_ are already correctly formatted and
391393
should not be line-wrapped::
392394

@@ -412,11 +414,11 @@ should not be line-wrapped::
412414
optional arguments:
413415
-h, --help show this help message and exit
414416

415-
:class:`RawTextHelpFormatter` maintains whitespace for all sorts of help text
417+
:class:`RawTextHelpFormatter` maintains whitespace for all sorts of help text,
416418
including argument descriptions.
417419

418-
The other formatter class available, :class:`ArgumentDefaultsHelpFormatter`,
419-
will add information about the default value of each of the arguments::
420+
:class:`ArgumentDefaultsHelpFormatter` automatically adds information about
421+
default values to each of the argument help messages::
420422

421423
>>> parser = argparse.ArgumentParser(
422424
... prog='PROG',
@@ -433,6 +435,25 @@ will add information about the default value of each of the arguments::
433435
-h, --help show this help message and exit
434436
--foo FOO FOO! (default: 42)
435437

438+
:class:`MetavarTypeHelpFormatter` uses the name of the type_ argument for each
439+
argument as as the display name for its values (rather than using the dest_
440+
as the regular formatter does)::
441+
442+
>>> parser = argparse.ArgumentParser(
443+
... prog='PROG',
444+
... formatter_class=argparse.MetavarTypeHelpFormatter)
445+
>>> parser.add_argument('--foo', type=int)
446+
>>> parser.add_argument('bar', type=float)
447+
>>> parser.print_help()
448+
usage: PROG [-h] [--foo int] float
449+
450+
positional arguments:
451+
float
452+
453+
optional arguments:
454+
-h, --help show this help message and exit
455+
--foo int
456+
436457

437458
conflict_handler
438459
^^^^^^^^^^^^^^^^
@@ -1314,13 +1335,24 @@ of :data:`sys.argv`. This can be accomplished by passing a list of strings to
13141335
Namespace(accumulate=<built-in function sum>, integers=[1, 2, 3, 4])
13151336

13161337

1317-
Custom namespaces
1318-
^^^^^^^^^^^^^^^^^
1338+
The Namespace object
1339+
^^^^^^^^^^^^^^^^^^^^
1340+
1341+
By default, :meth:`parse_args` will return a new object of type :class:`Namespace`
1342+
where the necessary attributes have been set. This class is deliberately simple,
1343+
just an :class:`object` subclass with a readable string representation. If you
1344+
prefer to have dict-like view of the attributes, you can use the standard Python
1345+
idiom via :func:`vars`::
1346+
1347+
>>> parser = argparse.ArgumentParser()
1348+
>>> parser.add_argument('--foo')
1349+
>>> args = parser.parse_args(['--foo', 'BAR'])
1350+
>>> vars(args)
1351+
{'foo': 'BAR'}
13191352

13201353
It may also be useful to have an :class:`ArgumentParser` assign attributes to an
1321-
already existing object, rather than the newly-created :class:`Namespace` object
1322-
that is normally used. This can be achieved by specifying the ``namespace=``
1323-
keyword argument::
1354+
already existing object, rather than a new :class:`Namespace` object. This can
1355+
be achieved by specifying the ``namespace=`` keyword argument::
13241356

13251357
>>> class C:
13261358
... pass

Doc/library/collections.abc.rst

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ example, whether it is hashable or whether it is a mapping.
2828
Collections Abstract Base Classes
2929
---------------------------------
3030

31-
The collections module offers the following ABCs:
31+
The collections module offers the following :term:`ABCs <abstract base class>`:
3232

3333
========================= ===================== ====================== ====================================================
34-
ABC Inherits Abstract Methods Mixin Methods
34+
ABC Inherits from Abstract Methods Mixin Methods
3535
========================= ===================== ====================== ====================================================
3636
:class:`Container` ``__contains__``
3737
:class:`Hashable` ``__hash__``
@@ -44,35 +44,77 @@ ABC Inherits Abstract Methods Mixin
4444
:class:`Iterable`, ``index``, and ``count``
4545
:class:`Container`
4646

47-
:class:`MutableSequence` :class:`Sequence` ``__setitem__`` Inherited Sequence methods and
47+
:class:`MutableSequence` :class:`Sequence` ``__setitem__`` Inherited :class:`Sequence` methods and
4848
``__delitem__``, ``append``, ``reverse``, ``extend``, ``pop``,
49-
and ``insert`` ``remove``, ``clear``, and ``__iadd__``
49+
``insert`` ``remove``, ``clear``, and ``__iadd__``
5050

5151
:class:`Set` :class:`Sized`, ``__le__``, ``__lt__``, ``__eq__``, ``__ne__``,
5252
:class:`Iterable`, ``__gt__``, ``__ge__``, ``__and__``, ``__or__``,
5353
:class:`Container` ``__sub__``, ``__xor__``, and ``isdisjoint``
5454

55-
:class:`MutableSet` :class:`Set` ``add`` and Inherited Set methods and
55+
:class:`MutableSet` :class:`Set` ``add``, Inherited :class:`Set` methods and
5656
``discard`` ``clear``, ``pop``, ``remove``, ``__ior__``,
5757
``__iand__``, ``__ixor__``, and ``__isub__``
5858

5959
:class:`Mapping` :class:`Sized`, ``__getitem__`` ``__contains__``, ``keys``, ``items``, ``values``,
6060
:class:`Iterable`, ``get``, ``__eq__``, and ``__ne__``
6161
:class:`Container`
6262

63-
:class:`MutableMapping` :class:`Mapping` ``__setitem__`` and Inherited Mapping methods and
63+
:class:`MutableMapping` :class:`Mapping` ``__setitem__``, Inherited :class:`Mapping` methods and
6464
``__delitem__`` ``pop``, ``popitem``, ``clear``, ``update``,
6565
and ``setdefault``
6666

6767

6868
:class:`MappingView` :class:`Sized` ``__len__``
69-
:class:`KeysView` :class:`MappingView`, ``__contains__``,
70-
:class:`Set` ``__iter__``
7169
:class:`ItemsView` :class:`MappingView`, ``__contains__``,
7270
:class:`Set` ``__iter__``
71+
:class:`KeysView` :class:`MappingView`, ``__contains__``,
72+
:class:`Set` ``__iter__``
7373
:class:`ValuesView` :class:`MappingView` ``__contains__``, ``__iter__``
7474
========================= ===================== ====================== ====================================================
7575

76+
77+
.. class:: Container
78+
Hashable
79+
Sized
80+
Callable
81+
82+
ABCs for classes that provide respectively the methods :meth:`__contains__`,
83+
:meth:`__hash__`, :meth:`__len__`, and :meth:`__call__`.
84+
85+
.. class:: Iterable
86+
87+
ABC for classes that provide the :meth:`__iter__` method.
88+
See also the definition of :term:`iterable`.
89+
90+
.. class:: Iterator
91+
92+
ABC for classes that provide the :meth:`__iter__` and :meth:`next` methods.
93+
See also the definition of :term:`iterator`.
94+
95+
.. class:: Sequence
96+
MutableSequence
97+
98+
ABCs for read-only and mutable :term:`sequences <sequence>`.
99+
100+
.. class:: Set
101+
MutableSet
102+
103+
ABCs for read-only and mutable sets.
104+
105+
.. class:: Mapping
106+
MutableMapping
107+
108+
ABCs for read-only and mutable :term:`mappings <mapping>`.
109+
110+
.. class:: MappingView
111+
ItemsView
112+
KeysView
113+
ValuesView
114+
115+
ABCs for mapping, items, keys, and values :term:`views <view>`.
116+
117+
76118
These ABCs allow us to ask classes or instances if they provide
77119
particular functionality, for example::
78120

Doc/library/compileall.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ compile Python sources.
6868
.. versionchanged:: 3.2
6969
Added the ``-i``, ``-b`` and ``-h`` options.
7070

71+
There is no command-line option to control the optimization level used by the
72+
:func:`compile` function, because the Python interpreter itself already
73+
provides the option: :program:`python -O -m compileall`.
7174

7275
Public functions
7376
----------------

Doc/library/email.parser.rst

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,21 +102,16 @@ as a string. :class:`HeaderParser` has the same API as the :class:`Parser`
102102
class.
103103

104104

105-
.. class:: Parser(_class=email.message.Message, strict=None)
105+
.. class:: Parser(_class=email.message.Message)
106106

107107
The constructor for the :class:`Parser` class takes an optional argument
108108
*_class*. This must be a callable factory (such as a function or a class), and
109109
it is used whenever a sub-message object needs to be created. It defaults to
110110
:class:`~email.message.Message` (see :mod:`email.message`). The factory will
111111
be called without arguments.
112112

113-
The optional *strict* flag is ignored.
114-
115-
.. deprecated:: 2.4
116-
Because the :class:`Parser` class is a backward compatible API wrapper
117-
around the new-in-Python 2.4 :class:`FeedParser`, *all* parsing is
118-
effectively non-strict. You should simply stop passing a *strict* flag to
119-
the :class:`Parser` constructor.
113+
.. versionchanged:: 3.2
114+
Removed the *strict* argument that was deprecated in 2.4.
120115

121116
The other public :class:`Parser` methods are:
122117

Doc/library/http.cookiejar.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ cookies (assumes Unix/Netscape convention for location of the cookies file)::
722722

723723
import os, http.cookiejar, urllib.request
724724
cj = http.cookiejar.MozillaCookieJar()
725-
cj.load(os.path.join(os.environ["HOME"], ".netscape/cookies.txt"))
725+
cj.load(os.path.join(os.path.expanduser("~"), ".netscape", "cookies.txt"))
726726
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
727727
r = opener.open("http://example.com/")
728728

Doc/library/itertools.rst

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Iterator Arguments Results
4646
==================== ============================ ================================================= =============================================================
4747
Iterator Arguments Results Example
4848
==================== ============================ ================================================= =============================================================
49-
:func:`accumulate` p p0, p0+p1, p0+p1+p2, ... ``accumulate([1,2,3,4,5]) --> 1 3 6 10 15``
49+
:func:`accumulate` p [,func] p0, p0+p1, p0+p1+p2, ... ``accumulate([1,2,3,4,5]) --> 1 3 6 10 15``
5050
:func:`chain` p, q, ... p0, p1, ... plast, q0, q1, ... ``chain('ABC', 'DEF') --> A B C D E F``
5151
:func:`compress` data, selectors (d[0] if s[0]), (d[1] if s[1]), ... ``compress('ABCDEF', [1,0,1,0,1,1]) --> A C E F``
5252
:func:`dropwhile` pred, seq seq[n], seq[n+1], starting when pred fails ``dropwhile(lambda x: x<5, [1,4,6,4,1]) --> 6 4 1``
@@ -84,23 +84,46 @@ The following module functions all construct and return iterators. Some provide
8484
streams of infinite length, so they should only be accessed by functions or
8585
loops that truncate the stream.
8686

87-
.. function:: accumulate(iterable)
87+
.. function:: accumulate(iterable[, func])
8888

8989
Make an iterator that returns accumulated sums. Elements may be any addable
90-
type including :class:`Decimal` or :class:`Fraction`. Equivalent to::
90+
type including :class:`Decimal` or :class:`Fraction`. If the optional
91+
*func* argument is supplied, it should be a function of two arguments
92+
and it will be used instead of addition.
9193

92-
def accumulate(iterable):
94+
Equivalent to::
95+
96+
def accumulate(iterable, func=operator.add):
9397
'Return running totals'
9498
# accumulate([1,2,3,4,5]) --> 1 3 6 10 15
99+
# accumulate([1,2,3,4,5], operator.mul) --> 1 2 6 24 120
95100
it = iter(iterable)
96101
total = next(it)
97102
yield total
98103
for element in it:
99-
total = total + element
104+
total = func(total, element)
100105
yield total
101106

107+
Uses for the *func* argument include :func:`min` for a running minimum,
108+
:func:`max` for a running maximum, and :func:`operator.mul` for a running
109+
product::
110+
111+
>>> data = [3, 4, 6, 2, 1, 9, 0, 7, 5, 8]
112+
>>> list(accumulate(data, operator.mul)) # running product
113+
[3, 12, 72, 144, 144, 1296, 0, 0, 0, 0]
114+
>>> list(accumulate(data, max)) # running maximum
115+
[3, 4, 6, 6, 6, 9, 9, 9, 9, 9]
116+
117+
# Amortize a 5% loan of 1000 with 4 annual payments of 90
118+
>>> cashflows = [1000, -90, -90, -90, -90]
119+
>>> list(accumulate(cashflows, lambda bal, pmt: bal*1.05 + pmt))
120+
[1000, 960.0, 918.0, 873.9000000000001, 827.5950000000001]
121+
102122
.. versionadded:: 3.2
103123

124+
.. versionchanged:: 3.3
125+
Added the optional *func* parameter.
126+
104127
.. function:: chain(*iterables)
105128

106129
Make an iterator that returns elements from the first iterable until it is

Doc/library/readline.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ normally be executed automatically during interactive sessions from the user's
196196

197197
import os
198198
import readline
199-
histfile = os.path.join(os.environ["HOME"], ".pyhist")
199+
histfile = os.path.join(os.path.expanduser("~"), ".pyhist")
200200
try:
201201
readline.read_history_file(histfile)
202202
except IOError:

Doc/library/sys.rst

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -227,33 +227,21 @@ always available.
227227
The struct sequence *flags* exposes the status of command line flags. The
228228
attributes are read only.
229229

230-
+------------------------------+------------------------------------------+
231-
| attribute | flag |
232-
+==============================+==========================================+
233-
| :const:`debug` | -d |
234-
+------------------------------+------------------------------------------+
235-
| :const:`division_warning` | -Q |
236-
+------------------------------+------------------------------------------+
237-
| :const:`inspect` | -i |
238-
+------------------------------+------------------------------------------+
239-
| :const:`interactive` | -i |
240-
+------------------------------+------------------------------------------+
241-
| :const:`optimize` | -O or -OO |
242-
+------------------------------+------------------------------------------+
243-
| :const:`dont_write_bytecode` | -B |
244-
+------------------------------+------------------------------------------+
245-
| :const:`no_user_site` | -s |
246-
+------------------------------+------------------------------------------+
247-
| :const:`no_site` | -S |
248-
+------------------------------+------------------------------------------+
249-
| :const:`ignore_environment` | -E |
250-
+------------------------------+------------------------------------------+
251-
| :const:`verbose` | -v |
252-
+------------------------------+------------------------------------------+
253-
| :const:`bytes_warning` | -b |
254-
+------------------------------+------------------------------------------+
255-
| :const:`quiet` | -q |
256-
+------------------------------+------------------------------------------+
230+
============================= =============================
231+
attribute flag
232+
============================= =============================
233+
:const:`debug` :option:`-d`
234+
:const:`inspect` :option:`-i`
235+
:const:`interactive` :option:`-i`
236+
:const:`optimize` :option:`-O` or :option:`-OO`
237+
:const:`dont_write_bytecode` :option:`-B`
238+
:const:`no_user_site` :option:`-s`
239+
:const:`no_site` :option:`-S`
240+
:const:`ignore_environment` :option:`-E`
241+
:const:`verbose` :option:`-v`
242+
:const:`bytes_warning` :option:`-b`
243+
:const:`quiet` :option:`-q`
244+
============================= =============================
257245

258246
.. versionchanged:: 3.2
259247
Added ``quiet`` attribute for the new :option:`-q` flag.

Doc/tutorial/interactive.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,7 @@ interpreter. ::
123123
# bound to the Esc key by default (you can change it - see readline docs).
124124
#
125125
# Store the file in ~/.pystartup, and set an environment variable to point
126-
# to it: "export PYTHONSTARTUP=/home/user/.pystartup" in bash.
127-
#
128-
# Note that PYTHONSTARTUP does *not* expand "~", so you have to put in the
129-
# full path to your home directory.
126+
# to it: "export PYTHONSTARTUP=~/.pystartup" in bash.
130127

131128
import atexit
132129
import os

Doc/whatsnew/3.2.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,11 +1499,11 @@ filenames:
14991499
>>> os.fsencode(filename)
15001500
b'Sehensw\xc3\xbcrdigkeiten'
15011501

1502-
Some operating systems allow direct access to the unencoded bytes in the
1502+
Some operating systems allow direct access to encoded bytes in the
15031503
environment. If so, the :attr:`os.supports_bytes_environ` constant will be
15041504
true.
15051505

1506-
For direct access to unencoded environment variables (if available),
1506+
For direct access to encoded environment variables (if available),
15071507
use the new :func:`os.getenvb` function or use :data:`os.environb`
15081508
which is a bytes version of :data:`os.environ`.
15091509

0 commit comments

Comments
 (0)