Skip to content

Commit 7f9f400

Browse files
author
Anselm Kruis
committed
Merge branch master into master-slp
2 parents de40a38 + ef3a676 commit 7f9f400

File tree

221 files changed

+5251
-2498
lines changed

Some content is hidden

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

221 files changed

+5251
-2498
lines changed

.hgtags

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ afb86a6eab458e22c2c6ba83eba903ee7aadc35b v3.3.6-slp
165165
95a0bb8bd61d303fa324127abc1dbcec437e0bc5 v3.2.6-slp
166166
69dd528ca6255a66c37cc5cf680e8357d108b036 v3.4.3rc1
167167
b4cbecbc0781e89a309d03b60a1f75f8499250e6 v3.4.3
168+
04f3f725896c6961212c3a12e8ac25be6958f4fa v3.4.4rc1
168169
5d4b6a57d5fd7564bf73f3db0e46fe5eeb00bcd8 v3.5.0a1
169170
0337bd7ebcb6559d69679bc7025059ad1ce4f432 v3.5.0a2
170171
82656e28b5e5c4ae48d8dd8b5f0d7968908a82b6 v3.5.0a3
@@ -178,3 +179,5 @@ cc15d736d860303b9da90d43cd32db39bab048df v3.5.0rc2
178179
66ed52375df802f9d0a34480daaa8ce79fc41313 v3.5.0rc3
179180
2d033fedfa7f1e325fd14ccdaa9cb42155da206f v3.5.0rc4
180181
374f501f4567b7595f2ad7798aa09afa2456bb28 v3.5.0
182+
948ef16a69513ba1ff15c9d7d0b012b949df4c80 v3.5.1rc1
183+
37a07cee5969e6d3672583187a73cf636ff28e1b v3.5.1

Doc/c-api/arg.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ Other objects
322322
``Py_CLEANUP_SUPPORTED`` was added.
323323

324324
``p`` (:class:`bool`) [int]
325-
Tests the value passed in for truth (a boolean **p**\redicate) and converts
325+
Tests the value passed in for truth (a boolean **p**\ redicate) and converts
326326
the result to its equivalent C true/false integer value.
327327
Sets the int to 1 if the expression was true and 0 if it was false.
328328
This accepts any valid Python value. See :ref:`truth` for more

Doc/c-api/init.rst

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Initializing and finalizing the interpreter
2525
triple: module; search; path
2626
single: PySys_SetArgv()
2727
single: PySys_SetArgvEx()
28-
single: Py_Finalize()
28+
single: Py_FinalizeEx()
2929
3030
Initialize the Python interpreter. In an application embedding Python, this
3131
should be called before using any other Python/C API functions; with the
@@ -34,7 +34,7 @@ Initializing and finalizing the interpreter
3434
modules :mod:`builtins`, :mod:`__main__` and :mod:`sys`. It also initializes
3535
the module search path (``sys.path``). It does not set ``sys.argv``; use
3636
:c:func:`PySys_SetArgvEx` for that. This is a no-op when called for a second time
37-
(without calling :c:func:`Py_Finalize` first). There is no return value; it is a
37+
(without calling :c:func:`Py_FinalizeEx` first). There is no return value; it is a
3838
fatal error if the initialization fails.
3939

4040

@@ -48,19 +48,20 @@ Initializing and finalizing the interpreter
4848
.. c:function:: int Py_IsInitialized()
4949
5050
Return true (nonzero) when the Python interpreter has been initialized, false
51-
(zero) if not. After :c:func:`Py_Finalize` is called, this returns false until
51+
(zero) if not. After :c:func:`Py_FinalizeEx` is called, this returns false until
5252
:c:func:`Py_Initialize` is called again.
5353
5454
55-
.. c:function:: void Py_Finalize()
55+
.. c:function:: int Py_FinalizeEx()
5656
5757
Undo all initializations made by :c:func:`Py_Initialize` and subsequent use of
5858
Python/C API functions, and destroy all sub-interpreters (see
5959
:c:func:`Py_NewInterpreter` below) that were created and not yet destroyed since
6060
the last call to :c:func:`Py_Initialize`. Ideally, this frees all memory
6161
allocated by the Python interpreter. This is a no-op when called for a second
62-
time (without calling :c:func:`Py_Initialize` again first). There is no return
63-
value; errors during finalization are ignored.
62+
time (without calling :c:func:`Py_Initialize` again first). Normally the
63+
return value is 0. If there were errors during finalization
64+
(flushing buffered data), -1 is returned.
6465
6566
This function is provided for a number of reasons. An embedding application
6667
might want to restart Python without having to restart the application itself.
@@ -79,7 +80,15 @@ Initializing and finalizing the interpreter
7980
freed. Some memory allocated by extension modules may not be freed. Some
8081
extensions may not work properly if their initialization routine is called more
8182
than once; this can happen if an application calls :c:func:`Py_Initialize` and
82-
:c:func:`Py_Finalize` more than once.
83+
:c:func:`Py_FinalizeEx` more than once.
84+
85+
.. versionadded:: 3.6
86+
87+
88+
.. c:function:: void Py_Finalize()
89+
90+
This is a backwards-compatible version of :c:func:`Py_FinalizeEx` that
91+
disregards the return value.
8392
8493
8594
Process-wide parameters
@@ -107,7 +116,7 @@ Process-wide parameters
107116
Note that :data:`sys.stderr` always uses the "backslashreplace" error
108117
handler, regardless of this (or any other) setting.
109118
110-
If :c:func:`Py_Finalize` is called, this function will need to be called
119+
If :c:func:`Py_FinalizeEx` is called, this function will need to be called
111120
again in order to affect subsequent calls to :c:func:`Py_Initialize`.
112121
113122
Returns 0 if successful, a nonzero value on error (e.g. calling after the
@@ -918,7 +927,7 @@ using the following functions:
918927
entry.)
919928
920929
.. index::
921-
single: Py_Finalize()
930+
single: Py_FinalizeEx()
922931
single: Py_Initialize()
923932
924933
Extension modules are shared between (sub-)interpreters as follows: the first
@@ -928,22 +937,22 @@ using the following functions:
928937
and filled with the contents of this copy; the extension's ``init`` function is
929938
not called. Note that this is different from what happens when an extension is
930939
imported after the interpreter has been completely re-initialized by calling
931-
:c:func:`Py_Finalize` and :c:func:`Py_Initialize`; in that case, the extension's
940+
:c:func:`Py_FinalizeEx` and :c:func:`Py_Initialize`; in that case, the extension's
932941
``initmodule`` function *is* called again.
933942
934943
.. index:: single: close() (in module os)
935944
936945
937946
.. c:function:: void Py_EndInterpreter(PyThreadState *tstate)
938947
939-
.. index:: single: Py_Finalize()
948+
.. index:: single: Py_FinalizeEx()
940949
941950
Destroy the (sub-)interpreter represented by the given thread state. The given
942951
thread state must be the current thread state. See the discussion of thread
943952
states below. When the call returns, the current thread state is *NULL*. All
944953
thread states associated with this interpreter are destroyed. (The global
945954
interpreter lock must be held before calling this function and is still held
946-
when it returns.) :c:func:`Py_Finalize` will destroy all sub-interpreters that
955+
when it returns.) :c:func:`Py_FinalizeEx` will destroy all sub-interpreters that
947956
haven't been explicitly destroyed at that point.
948957
949958

Doc/c-api/intro.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,9 +578,9 @@ Sometimes, it is desirable to "uninitialize" Python. For instance, the
578578
application may want to start over (make another call to
579579
:c:func:`Py_Initialize`) or the application is simply done with its use of
580580
Python and wants to free memory allocated by Python. This can be accomplished
581-
by calling :c:func:`Py_Finalize`. The function :c:func:`Py_IsInitialized` returns
581+
by calling :c:func:`Py_FinalizeEx`. The function :c:func:`Py_IsInitialized` returns
582582
true if Python is currently in the initialized state. More information about
583-
these functions is given in a later chapter. Notice that :c:func:`Py_Finalize`
583+
these functions is given in a later chapter. Notice that :c:func:`Py_FinalizeEx`
584584
does *not* free all memory allocated by the Python interpreter, e.g. memory
585585
allocated by extension modules currently cannot be released.
586586

Doc/c-api/sys.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,20 +212,24 @@ Process Control
212212
.. c:function:: void Py_Exit(int status)
213213
214214
.. index::
215-
single: Py_Finalize()
215+
single: Py_FinalizeEx()
216216
single: exit()
217217
218-
Exit the current process. This calls :c:func:`Py_Finalize` and then calls the
219-
standard C library function ``exit(status)``.
218+
Exit the current process. This calls :c:func:`Py_FinalizeEx` and then calls the
219+
standard C library function ``exit(status)``. If :c:func:`Py_FinalizeEx`
220+
indicates an error, the exit status is set to 120.
221+
222+
.. versionchanged:: 3.6
223+
Errors from finalization no longer ignored.
220224
221225
222226
.. c:function:: int Py_AtExit(void (*func) ())
223227
224228
.. index::
225-
single: Py_Finalize()
229+
single: Py_FinalizeEx()
226230
single: cleanup functions
227231
228-
Register a cleanup function to be called by :c:func:`Py_Finalize`. The cleanup
232+
Register a cleanup function to be called by :c:func:`Py_FinalizeEx`. The cleanup
229233
function will be called with no arguments and should return no value. At most
230234
32 cleanup functions can be registered. When the registration is successful,
231235
:c:func:`Py_AtExit` returns ``0``; on failure, it returns ``-1``. The cleanup

Doc/extending/embedding.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ perform some operation on a file. ::
6767
Py_Initialize();
6868
PyRun_SimpleString("from time import time,ctime\n"
6969
"print('Today is', ctime(time()))\n");
70-
Py_Finalize();
70+
if (Py_FinalizeEx() < 0) {
71+
exit(120);
72+
}
7173
PyMem_RawFree(program);
7274
return 0;
7375
}
@@ -76,7 +78,7 @@ The :c:func:`Py_SetProgramName` function should be called before
7678
:c:func:`Py_Initialize` to inform the interpreter about paths to Python run-time
7779
libraries. Next, the Python interpreter is initialized with
7880
:c:func:`Py_Initialize`, followed by the execution of a hard-coded Python script
79-
that prints the date and time. Afterwards, the :c:func:`Py_Finalize` call shuts
81+
that prints the date and time. Afterwards, the :c:func:`Py_FinalizeEx` call shuts
8082
the interpreter down, followed by the end of the program. In a real program,
8183
you may want to get the Python script from another source, perhaps a text-editor
8284
routine, a file, or a database. Getting the Python code from a file can better

Doc/glossary.rst

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,14 @@ Glossary
308308
A synonym for :term:`file object`.
309309

310310
finder
311-
An object that tries to find the :term:`loader` for a module. It must
312-
implement either a method named :meth:`find_loader` or a method named
313-
:meth:`find_module`. See :pep:`302` and :pep:`420` for details and
314-
:class:`importlib.abc.Finder` for an :term:`abstract base class`.
311+
An object that tries to find the :term:`loader` for a module that is
312+
being imported.
313+
314+
Since Python 3.3, there are two types of finder: :term:`meta path finders
315+
<meta path finder>` for use with :data:`sys.meta_path`, and :term:`path
316+
entry finders <path entry finder>` for use with :data:`sys.path_hooks`.
317+
318+
See :pep:`302`, :pep:`420` and :pep:`451` for much more detail.
315319

316320
floor division
317321
Mathematical division that rounds down to nearest integer. The floor
@@ -593,10 +597,13 @@ Glossary
593597
:class:`collections.OrderedDict` and :class:`collections.Counter`.
594598

595599
meta path finder
596-
A finder returned by a search of :data:`sys.meta_path`. Meta path
600+
A :term:`finder` returned by a search of :data:`sys.meta_path`. Meta path
597601
finders are related to, but different from :term:`path entry finders
598602
<path entry finder>`.
599603

604+
See :class:`importlib.abc.MetaPathFinder` for the methods that meta path
605+
finders implement.
606+
600607
metaclass
601608
The class of a class. Class definitions create a class name, a class
602609
dictionary, and a list of base classes. The metaclass is responsible for
@@ -630,7 +637,7 @@ Glossary
630637

631638
module spec
632639
A namespace containing the import-related information used to load a
633-
module.
640+
module. An instance of :class:`importlib.machinery.ModuleSpec`.
634641

635642
MRO
636643
See :term:`method resolution order`.
@@ -757,6 +764,9 @@ Glossary
757764
(i.e. a :term:`path entry hook`) which knows how to locate modules given
758765
a :term:`path entry`.
759766

767+
See :class:`importlib.abc.PathEntryFinder` for the methods that path entry
768+
finders implement.
769+
760770
path entry hook
761771
A callable on the :data:`sys.path_hook` list which returns a :term:`path
762772
entry finder` if it knows how to find modules on a specific :term:`path

Doc/howto/clinic.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,18 +1249,18 @@ Here's the simplest example of a custom converter, from ``Modules/zlibmodule.c``
12491249

12501250
/*[python input]
12511251

1252-
class uint_converter(CConverter):
1252+
class capped_uint_converter(CConverter):
12531253
type = 'unsigned int'
1254-
converter = 'uint_converter'
1254+
converter = 'capped_uint_converter'
12551255

12561256
[python start generated code]*/
1257-
/*[python end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/
1257+
/*[python end generated code: output=da39a3ee5e6b4b0d input=35521e4e733823c7]*/
12581258

1259-
This block adds a converter to Argument Clinic named ``uint``. Parameters
1260-
declared as ``uint`` will be declared as type ``unsigned int``, and will
1261-
be parsed by the ``'O&'`` format unit, which will call the ``uint_converter``
1262-
converter function.
1263-
``uint`` variables automatically support default values.
1259+
This block adds a converter to Argument Clinic named ``capped_uint``. Parameters
1260+
declared as ``capped_uint`` will be declared as type ``unsigned int``, and will
1261+
be parsed by the ``'O&'`` format unit, which will call the
1262+
``capped_uint_converter`` converter function. ``capped_uint`` variables
1263+
automatically support default values.
12641264

12651265
More sophisticated custom converters can insert custom C code to
12661266
handle initialization and cleanup.

Doc/howto/urllib2.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ library. ::
115115
'language' : 'Python' }
116116

117117
data = urllib.parse.urlencode(values)
118-
data = data.encode('utf-8') # data should be bytes
118+
data = data.encode('ascii') # data should be bytes
119119
req = urllib.request.Request(url, data)
120120
with urllib.request.urlopen(req) as response:
121121
the_page = response.read()
@@ -180,8 +180,8 @@ Explorer [#]_. ::
180180
'language' : 'Python' }
181181
headers = { 'User-Agent' : user_agent }
182182

183-
data = urllib.parse.urlencode(values)
184-
data = data.encode('utf-8')
183+
data = urllib.parse.urlencode(values)
184+
data = data.encode('ascii')
185185
req = urllib.request.Request(url, data, headers)
186186
with urllib.request.urlopen(req) as response:
187187
the_page = response.read()

Doc/includes/run-func.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ main(int argc, char *argv[])
6363
fprintf(stderr, "Failed to load \"%s\"\n", argv[1]);
6464
return 1;
6565
}
66-
Py_Finalize();
66+
if (Py_FinalizeEx() < 0) {
67+
return 120;
68+
}
6769
return 0;
6870
}

0 commit comments

Comments
 (0)