Skip to content

Commit dc80fda

Browse files
committed
Merge branch 'main' into special_for_iter2
2 parents 0751228 + e4e8895 commit dc80fda

File tree

59 files changed

+1160
-503
lines changed

Some content is hidden

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

59 files changed

+1160
-503
lines changed

Doc/c-api/frame.rst

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ See also :ref:`Reflection <reflection>`.
2727
Return a :term:`strong reference`, or ``NULL`` if *frame* has no outer
2828
frame.
2929
30-
*frame* must not be ``NULL``.
31-
3230
.. versionadded:: 3.9
3331
3432
@@ -38,8 +36,6 @@ See also :ref:`Reflection <reflection>`.
3836
3937
Return a :term:`strong reference`. The result cannot be ``NULL``.
4038
41-
*frame* must not be ``NULL``.
42-
4339
.. versionadded:: 3.11
4440
4541
@@ -49,7 +45,7 @@ See also :ref:`Reflection <reflection>`.
4945
5046
Return a :term:`strong reference`.
5147
52-
*frame* must not be ``NULL``. The result (frame code) cannot be ``NULL``.
48+
The result (frame code) cannot be ``NULL``.
5349
5450
.. versionadded:: 3.9
5551
@@ -62,8 +58,6 @@ See also :ref:`Reflection <reflection>`.
6258
6359
Return a :term:`strong reference`, or ``NULL``.
6460
65-
*frame* must not be ``NULL``.
66-
6761
.. versionadded:: 3.11
6862
6963
@@ -73,19 +67,15 @@ See also :ref:`Reflection <reflection>`.
7367
7468
Return a :term:`strong reference`. The result cannot be ``NULL``.
7569
76-
*frame* must not be ``NULL``.
77-
7870
.. versionadded:: 3.11
7971
8072
8173
.. c:function:: int PyFrame_GetLasti(PyFrameObject *frame)
8274
83-
Get the *frame*'s ``f_lasti`` attribute (:class:`dict`).
75+
Get the *frame*'s ``f_lasti`` attribute.
8476
8577
Returns -1 if ``frame.f_lasti`` is ``None``.
8678
87-
*frame* must not be ``NULL``.
88-
8979
.. versionadded:: 3.11
9080
9181
@@ -95,13 +85,9 @@ See also :ref:`Reflection <reflection>`.
9585
9686
Return a :term:`strong reference`.
9787
98-
*frame* must not be ``NULL``.
99-
10088
.. versionadded:: 3.11
10189
10290
10391
.. c:function:: int PyFrame_GetLineNumber(PyFrameObject *frame)
10492
10593
Return the line number that *frame* is currently executing.
106-
107-
*frame* must not be ``NULL``.

Doc/library/argparse.rst

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,75 @@ module also automatically generates help and usage messages and issues errors
2626
when users give the program invalid arguments.
2727

2828

29+
Summary
30+
-------
31+
32+
Core Functionality
33+
^^^^^^^^^^^^^^^^^^
34+
35+
The :mod:`argparse` module's support for command-line interfaces is built
36+
from the following:
37+
38+
The :class:`argparse.ArgumentParser` creates a new :class:`ArgumentParser`
39+
object. Commonly used arguments include prog_, description_, and
40+
formatter_class_. For example, the user can create an instance of
41+
:class:`ArgumentParser` through the following::
42+
43+
>>> parser = argparse.ArgumentParser(prog='PROG', description='DESC',
44+
... formatter_class=argparse.RawDescriptionHelpFormatter)
45+
46+
The :func:`ArgumentParser.add_argument` is a function that is used
47+
to define how a single command-line argument should be parsed. Commonly used
48+
arguments include `name or flags`_, action_, default_, type_, required_,
49+
and help_. An example of the function :func:`ArgumentParser.add_argument`
50+
is as follows::
51+
52+
>>> parser.add_argument('-v', '--verbose', action='store_true',
53+
... help='Show various debugging information')
54+
55+
56+
Basic Usage of :func:`add_argument`
57+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
58+
59+
60+
**Name or Flags Type**
61+
62+
====================== ===========================
63+
Type Example
64+
====================== ===========================
65+
Positional ``'foo'``
66+
Optional ``'-v'``, ``'--verbose'``
67+
====================== ===========================
68+
69+
70+
**Basic Arguments:**
71+
72+
====================== =========================================================== =========================================================================================================================
73+
Name Description Keywords
74+
====================== =========================================================== =========================================================================================================================
75+
action_ Specifies how an argument should be handled ``'store'``, ``'store_const'``, ``'store_true'``, ``'append'``, ``'append_const'``, ``'count'``, ``'help'``, ``'version'``
76+
default_ Default value used when an argument is not provided
77+
type_ Automatically converts an argument to the given type :class:`int`, :class:`float`, :class:`bool`, ``argparse.FileType('w')``, ``callable function``
78+
help_ Help message of an argument
79+
====================== =========================================================== =========================================================================================================================
80+
81+
82+
83+
**Advanced Arguments:**
84+
85+
====================== =========================================================== =======================================================================================================================
86+
Name Description Keywords
87+
====================== =========================================================== =======================================================================================================================
88+
nargs_ Associates a single action with the number of arguments ``N`` (:class:`int`), ``'?'``, ``'*'``, ``'+'``, ``argparse.REMAINDER``
89+
const_ Stores constant values of names or flags
90+
choices_ A container that lists the possible values ``['foo', 'bar']``, ``range(1, 10)``, Any object that supports ``in`` operator
91+
required_ Indicates if an optional argument is required or not ``True``, ``False``
92+
metavar_ An alternative display name for the argument
93+
dest_ Specifies name of attribute to be used in ``parse_args()``
94+
====================== =========================================================== =======================================================================================================================
95+
96+
97+
2998
Example
3099
-------
31100

@@ -196,6 +265,8 @@ ArgumentParser objects
196265
The following sections describe how each of these are used.
197266

198267

268+
.. _prog:
269+
199270
prog
200271
^^^^
201272

@@ -293,6 +364,8 @@ The ``%(prog)s`` format specifier is available to fill in the program name in
293364
your usage messages.
294365

295366

367+
.. _description:
368+
296369
description
297370
^^^^^^^^^^^
298371

@@ -373,6 +446,8 @@ and one in the child) and raise an error.
373446
not be reflected in the child.
374447

375448

449+
.. _formatter_class:
450+
376451
formatter_class
377452
^^^^^^^^^^^^^^^
378453

@@ -716,6 +791,8 @@ The add_argument() method
716791
The following sections describe how each of these are used.
717792

718793

794+
.. _name_or_flags:
795+
719796
name or flags
720797
^^^^^^^^^^^^^
721798

@@ -749,6 +826,8 @@ be positional::
749826
PROG: error: the following arguments are required: bar
750827

751828

829+
.. _action:
830+
752831
action
753832
^^^^^^
754833

@@ -884,6 +963,9 @@ An example of a custom action::
884963

885964
For more details, see :class:`Action`.
886965

966+
967+
.. _nargs:
968+
887969
nargs
888970
^^^^^
889971

@@ -971,6 +1053,8 @@ is determined by the action_. Generally this means a single command-line argume
9711053
will be consumed and a single item (not a list) will be produced.
9721054

9731055

1056+
.. _const:
1057+
9741058
const
9751059
^^^^^
9761060

@@ -997,6 +1081,8 @@ the various :class:`ArgumentParser` actions. The two most common uses of it are
9971081
``const=None`` by default, including when ``action='append_const'`` or
9981082
``action='store_const'``.
9991083

1084+
.. _default:
1085+
10001086
default
10011087
^^^^^^^
10021088

@@ -1055,6 +1141,8 @@ command-line argument was not present::
10551141
Namespace(foo='1')
10561142

10571143

1144+
.. _type:
1145+
10581146
type
10591147
^^^^
10601148

@@ -1124,6 +1212,8 @@ For type checkers that simply check against a fixed set of values, consider
11241212
using the choices_ keyword instead.
11251213

11261214

1215+
.. _choices:
1216+
11271217
choices
11281218
^^^^^^^
11291219

@@ -1166,6 +1256,8 @@ from *dest*. This is usually what you want because the user never sees the
11661256
many choices), just specify an explicit metavar_.
11671257

11681258

1259+
.. _required:
1260+
11691261
required
11701262
^^^^^^^^
11711263

@@ -1192,6 +1284,8 @@ present at the command line.
11921284
*options* to be *optional*, and thus they should be avoided when possible.
11931285

11941286

1287+
.. _help:
1288+
11951289
help
11961290
^^^^
11971291

@@ -1247,6 +1341,8 @@ setting the ``help`` value to ``argparse.SUPPRESS``::
12471341
-h, --help show this help message and exit
12481342

12491343

1344+
.. _metavar:
1345+
12501346
metavar
12511347
^^^^^^^
12521348

@@ -1311,6 +1407,8 @@ arguments::
13111407
--foo bar baz
13121408

13131409

1410+
.. _dest:
1411+
13141412
dest
13151413
^^^^
13161414

Doc/library/codecs.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1426,7 +1426,7 @@ Internationalized Domain Names (IDN)). It builds upon the ``punycode`` encoding
14261426
and :mod:`stringprep`.
14271427

14281428
If you need the IDNA 2008 standard from :rfc:`5891` and :rfc:`5895`, use the
1429-
third-party `idna module <https://pypi.org/project/idna/>_`.
1429+
third-party `idna module <https://pypi.org/project/idna/>`_.
14301430

14311431
These RFCs together define a protocol to support non-ASCII characters in domain
14321432
names. A domain name containing non-ASCII characters (such as

Doc/library/functools.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,23 @@ The :mod:`functools` module defines the following functions:
436436
... for i, elem in enumerate(arg):
437437
... print(i, elem)
438438

439+
:data:`types.UnionType` and :data:`typing.Union` can also be used::
440+
441+
>>> @fun.register
442+
... def _(arg: int | float, verbose=False):
443+
... if verbose:
444+
... print("Strength in numbers, eh?", end=" ")
445+
... print(arg)
446+
...
447+
>>> from typing import Union
448+
>>> @fun.register
449+
... def _(arg: Union[list, set], verbose=False):
450+
... if verbose:
451+
... print("Enumerate this:")
452+
... for i, elem in enumerate(arg):
453+
... print(i, elem)
454+
...
455+
439456
For code which doesn't use type annotations, the appropriate type
440457
argument can be passed explicitly to the decorator itself::
441458

@@ -535,6 +552,10 @@ The :mod:`functools` module defines the following functions:
535552
.. versionchanged:: 3.7
536553
The :func:`register` attribute now supports using type annotations.
537554

555+
.. versionchanged:: 3.11
556+
The :func:`register` attribute now supports :data:`types.UnionType`
557+
and :data:`typing.Union` as type annotations.
558+
538559

539560
.. class:: singledispatchmethod(func)
540561

Doc/library/multiprocessing.rst

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1676,7 +1676,7 @@ Manager processes will be shutdown as soon as they are garbage collected or
16761676
their parent process exits. The manager classes are defined in the
16771677
:mod:`multiprocessing.managers` module:
16781678

1679-
.. class:: BaseManager([address[, authkey]])
1679+
.. class:: BaseManager(address=None, authkey=None, serializer='pickle', ctx=None, *, shutdown_timeout=1.0)
16801680

16811681
Create a BaseManager object.
16821682

@@ -1691,6 +1691,20 @@ their parent process exits. The manager classes are defined in the
16911691
*authkey* is ``None`` then ``current_process().authkey`` is used.
16921692
Otherwise *authkey* is used and it must be a byte string.
16931693

1694+
*serializer* must be ``'pickle'`` (use :mod:`pickle` serialization) or
1695+
``'xmlrpclib'`` (use :mod:`xmlrpc.client` serialization).
1696+
1697+
*ctx* is a context object, or ``None`` (use the current context). See the
1698+
:func:`get_context` function.
1699+
1700+
*shutdown_timeout* is a timeout in seconds used to wait until the process
1701+
used by the manager completes in the :meth:`shutdown` method. If the
1702+
shutdown times out, the process is terminated. If terminating the process
1703+
also times out, the process is killed.
1704+
1705+
.. versionchanged: 3.11
1706+
Added the *shutdown_timeout* parameter.
1707+
16941708
.. method:: start([initializer[, initargs]])
16951709

16961710
Start a subprocess to start the manager. If *initializer* is not ``None``

Doc/library/socket.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ The following functions all create :ref:`socket objects <socket-objects>`.
660660
Windows support added.
661661

662662

663-
.. function:: create_connection(address[, timeout[, source_address]])
663+
.. function:: create_connection(address[, timeout[, source_address[, all_errors]]])
664664

665665
Connect to a TCP service listening on the internet *address* (a 2-tuple
666666
``(host, port)``), and return the socket object. This is a higher-level
@@ -679,9 +679,18 @@ The following functions all create :ref:`socket objects <socket-objects>`.
679679
socket to bind to as its source address before connecting. If host or port
680680
are '' or 0 respectively the OS default behavior will be used.
681681

682+
When a connection cannot be created, an exception is raised. By default,
683+
it is the exception from the last address in the list. If *all_errors*
684+
is ``True``, it is an :exc:`ExceptionGroup` containing the errors of all
685+
attempts.
686+
682687
.. versionchanged:: 3.2
683688
*source_address* was added.
684689

690+
.. versionchanged:: 3.11
691+
*all_errors* was added.
692+
693+
685694
.. function:: create_server(address, *, family=AF_INET, backlog=None, reuse_port=False, dualstack_ipv6=False)
686695

687696
Convenience function which creates a TCP socket bound to *address* (a 2-tuple

0 commit comments

Comments
 (0)