Skip to content

Commit 87f5945

Browse files
Merge branch 'master' into sqlite-no-hasattr
2 parents 4585ae8 + 1426daa commit 87f5945

File tree

118 files changed

+1691
-876
lines changed

Some content is hidden

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

118 files changed

+1691
-876
lines changed

.travis.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ matrix:
4040
# compiler here and the other to run the coverage build. Clang is preferred
4141
# in this instance for its better error messages.
4242
env: TESTING=cpython
43+
addons:
44+
apt:
45+
packages:
46+
- xvfb
4347
- os: linux
4448
language: python
4549
# Build the docs against a stable version of Python so code bugs don't hold up doc-related PRs.
@@ -70,6 +74,7 @@ matrix:
7074
apt:
7175
packages:
7276
- lcov
77+
- xvfb
7378
before_script:
7479
- ./configure
7580
- make coverage -s -j4
@@ -79,7 +84,7 @@ matrix:
7984
- ./venv/bin/python -m test.pythoninfo
8085
script:
8186
# Skip tests that re-run the entire test suite.
82-
- ./venv/bin/python -m coverage run --pylib -m test --fail-env-changed -uall,-cpu -x test_multiprocessing_fork -x test_multiprocessing_forkserver -x test_multiprocessing_spawn -x test_concurrent_futures
87+
- xvfb-run ./venv/bin/python -m coverage run --pylib -m test --fail-env-changed -uall,-cpu -x test_multiprocessing_fork -x test_multiprocessing_forkserver -x test_multiprocessing_spawn -x test_concurrent_futures
8388
after_script: # Probably should be after_success once test suite updated to run under coverage.py.
8489
# Make the `coverage` command available to Codecov w/ a version of Python that can parse all source files.
8590
- source ./venv/bin/activate
@@ -150,7 +155,7 @@ script:
150155
# Check that all symbols exported by libpython start with "Py" or "_Py"
151156
- make smelly
152157
# `-r -w` implicitly provided through `make buildbottest`.
153-
- make buildbottest TESTOPTS="-j4 -uall,-cpu"
158+
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then XVFB_RUN=xvfb-run; fi; $XVFB_RUN make buildbottest TESTOPTS="-j4 -uall,-cpu"
154159

155160
notifications:
156161
email: false
File renamed without changes.

Doc/howto/functional.rst

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -273,23 +273,24 @@ dictionary's keys::
273273

274274
>>> m = {'Jan': 1, 'Feb': 2, 'Mar': 3, 'Apr': 4, 'May': 5, 'Jun': 6,
275275
... 'Jul': 7, 'Aug': 8, 'Sep': 9, 'Oct': 10, 'Nov': 11, 'Dec': 12}
276-
>>> for key in m: #doctest: +SKIP
276+
>>> for key in m:
277277
... print(key, m[key])
278-
Mar 3
278+
Jan 1
279279
Feb 2
280-
Aug 8
281-
Sep 9
280+
Mar 3
282281
Apr 4
282+
May 5
283283
Jun 6
284284
Jul 7
285-
Jan 1
286-
May 5
285+
Aug 8
286+
Sep 9
287+
Oct 10
287288
Nov 11
288289
Dec 12
289-
Oct 10
290290

291-
Note that the order is essentially random, because it's based on the hash
292-
ordering of the objects in the dictionary.
291+
Note that starting with Python 3.7, dictionary iteration order is guaranteed
292+
to be the same as the insertion order. In earlier versions, the behaviour was
293+
unspecified and could vary between implementations.
293294

294295
Applying :func:`iter` to a dictionary always loops over the keys, but
295296
dictionaries have methods that return other iterators. If you want to iterate
@@ -301,8 +302,8 @@ The :func:`dict` constructor can accept an iterator that returns a finite stream
301302
of ``(key, value)`` tuples:
302303

303304
>>> L = [('Italy', 'Rome'), ('France', 'Paris'), ('US', 'Washington DC')]
304-
>>> dict(iter(L)) #doctest: +SKIP
305-
{'Italy': 'Rome', 'US': 'Washington DC', 'France': 'Paris'}
305+
>>> dict(iter(L))
306+
{'Italy': 'Rome', 'France': 'Paris', 'US': 'Washington DC'}
306307

307308
Files also support iteration by calling the :meth:`~io.TextIOBase.readline`
308309
method until there are no more lines in the file. This means you can read each

Doc/library/contextlib.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,22 @@ Functions and classes provided:
152152

153153
.. function:: nullcontext(enter_result=None)
154154

155-
Return a context manager that returns enter_result from ``__enter__``, but
155+
Return a context manager that returns *enter_result* from ``__enter__``, but
156156
otherwise does nothing. It is intended to be used as a stand-in for an
157157
optional context manager, for example::
158158

159+
def myfunction(arg, ignore_exceptions=False):
160+
if ignore_exceptions:
161+
# Use suppress to ignore all exceptions.
162+
cm = contextlib.suppress(Exception)
163+
else:
164+
# Do not ignore any exceptions, cm has no effect.
165+
cm = contextlib.nullcontext()
166+
with cm:
167+
# Do something
168+
169+
An example using *enter_result*::
170+
159171
def process_file(file_or_path):
160172
if isinstance(file_or_path, str):
161173
# If string, open file

Doc/library/ctypes.rst

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,22 @@ As we can easily check, our array is sorted now::
10251025
1 5 7 33 99
10261026
>>>
10271027

1028+
The function factories can be used as decorator factories, so we may as well
1029+
write::
1030+
1031+
>>> @CFUNCTYPE(c_int, POINTER(c_int), POINTER(c_int))
1032+
... def py_cmp_func(a, b):
1033+
... print("py_cmp_func", a[0], b[0])
1034+
... return a[0] - b[0]
1035+
...
1036+
>>> qsort(ia, len(ia), sizeof(c_int), py_cmp_func)
1037+
py_cmp_func 5 1
1038+
py_cmp_func 33 99
1039+
py_cmp_func 7 33
1040+
py_cmp_func 1 7
1041+
py_cmp_func 5 7
1042+
>>>
1043+
10281044
.. note::
10291045

10301046
Make sure you keep references to :func:`CFUNCTYPE` objects as long as they
@@ -1577,7 +1593,9 @@ Foreign functions can also be created by instantiating function prototypes.
15771593
Function prototypes are similar to function prototypes in C; they describe a
15781594
function (return type, argument types, calling convention) without defining an
15791595
implementation. The factory functions must be called with the desired result
1580-
type and the argument types of the function.
1596+
type and the argument types of the function, and can be used as decorator
1597+
factories, and as such, be applied to functions through the ``@wrapper`` syntax.
1598+
See :ref:`ctypes-callback-functions` for examples.
15811599

15821600

15831601
.. function:: CFUNCTYPE(restype, *argtypes, use_errno=False, use_last_error=False)

Doc/library/dataclasses.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ Mutable default values
532532
class C:
533533
x = []
534534
def add(self, element):
535-
self.x += element
535+
self.x.append(element)
536536

537537
o1 = C()
538538
o2 = C()

Doc/library/email.parser.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ in the top-level :mod:`email` package namespace.
246246
Removed the *strict* argument. Added the *policy* keyword.
247247

248248

249-
.. function:: message_from_binary_file(fp, _class=None, *,
249+
.. function:: message_from_binary_file(fp, _class=None, *, \
250250
policy=policy.compat32)
251251

252252
Return a message object structure tree from an open binary :term:`file

Doc/library/exceptions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ The following exceptions are the exceptions that are usually raised.
525525

526526
.. exception:: ValueError
527527

528-
Raised when a built-in operation or function receives an argument that has the
528+
Raised when an operation or function receives an argument that has the
529529
right type but an inappropriate value, and the situation is not described by a
530530
more precise exception such as :exc:`IndexError`.
531531

Doc/library/functions.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ are always available. They are listed here in alphabetical order.
241241
interactive statement (in the latter case, expression statements that
242242
evaluate to something other than ``None`` will be printed).
243243

244-
The optional arguments *flags* and *dont_inherit* control which future
245-
statements (see :pep:`236`) affect the compilation of *source*. If neither
244+
The optional arguments *flags* and *dont_inherit* control which :ref:`future
245+
statements <future>` affect the compilation of *source*. If neither
246246
is present (or both are zero) the code is compiled with those future
247247
statements that are in effect in the code that is calling :func:`compile`. If the
248248
*flags* argument is given and *dont_inherit* is not (or is zero) then the

Doc/library/platform.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ Mac OS Platform
243243
Unix Platforms
244244
--------------
245245

246-
.. function:: libc_ver(executable=sys.executable, lib='', version='', chunksize=2048)
246+
.. function:: libc_ver(executable=sys.executable, lib='', version='', chunksize=16384)
247247

248248
Tries to determine the libc version against which the file executable (defaults
249249
to the Python interpreter) is linked. Returns a tuple of strings ``(lib,

Doc/library/sqlite3.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ Connection Objects
346346
called as the SQL function. If *deterministic* is true, the created function
347347
is marked as `deterministic <https://sqlite.org/deterministic.html>`_, which
348348
allows SQLite to perform additional optimizations. This flag is supported by
349-
SQLite 3.8.3 or higher, ``sqlite3.NotSupportedError`` will be raised if used
349+
SQLite 3.8.3 or higher, :exc:`NotSupportedError` will be raised if used
350350
with older versions.
351351

352352
The function can return any of the types supported by SQLite: bytes, str, int,
@@ -835,6 +835,13 @@ Exceptions
835835
disconnect occurs, the data source name is not found, a transaction could
836836
not be processed, etc. It is a subclass of :exc:`DatabaseError`.
837837

838+
.. exception:: NotSupportedError
839+
840+
Exception raised in case a method or database API was used which is not
841+
supported by the database, e.g. calling the :meth:`~Connection.rollback`
842+
method on a connection that does not support transaction or has
843+
transactions turned off. It is a subclass of :exc:`DatabaseError`.
844+
838845

839846
.. _sqlite3-types:
840847

Doc/library/stdtypes.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4220,12 +4220,17 @@ pairs within braces, for example: ``{'jack': 4098, 'sjoerd': 4127}`` or ``{4098:
42204220

42214221
.. method:: popitem()
42224222

4223-
Remove and return an arbitrary ``(key, value)`` pair from the dictionary.
4223+
Remove and return a ``(key, value)`` pair from the dictionary.
4224+
Pairs are returned in :abbr:`LIFO (last-in, first-out)` order.
42244225

42254226
:meth:`popitem` is useful to destructively iterate over a dictionary, as
42264227
often used in set algorithms. If the dictionary is empty, calling
42274228
:meth:`popitem` raises a :exc:`KeyError`.
42284229

4230+
.. versionchanged:: 3.7
4231+
LIFO order is now guaranteed. In prior versions, :meth:`popitem` would
4232+
return an arbitrary key/value pair.
4233+
42294234
.. method:: setdefault(key[, default])
42304235

42314236
If *key* is in the dictionary, return its value. If not, insert *key*

Doc/library/unittest.mock.rst

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,12 +1825,12 @@ sentinel
18251825

18261826
.. data:: sentinel
18271827

1828-
The ``sentinel`` object provides a convenient way of providing unique
1829-
objects for your tests.
1828+
The ``sentinel`` object provides a convenient way of providing unique
1829+
objects for your tests.
18301830

1831-
Attributes are created on demand when you access them by name. Accessing
1832-
the same attribute will always return the same object. The objects
1833-
returned have a sensible repr so that test failure messages are readable.
1831+
Attributes are created on demand when you access them by name. Accessing
1832+
the same attribute will always return the same object. The objects
1833+
returned have a sensible repr so that test failure messages are readable.
18341834

18351835
.. versionchanged:: 3.7
18361836
The ``sentinel`` attributes now preserve their identity when they are
@@ -2070,22 +2070,22 @@ mock_open
20702070

20712071
.. function:: mock_open(mock=None, read_data=None)
20722072

2073-
A helper function to create a mock to replace the use of :func:`open`. It works
2074-
for :func:`open` called directly or used as a context manager.
2075-
2076-
The *mock* argument is the mock object to configure. If ``None`` (the
2077-
default) then a :class:`MagicMock` will be created for you, with the API limited
2078-
to methods or attributes available on standard file handles.
2079-
2080-
*read_data* is a string for the :meth:`~io.IOBase.read`,
2081-
:meth:`~io.IOBase.readline`, and :meth:`~io.IOBase.readlines` methods
2082-
of the file handle to return. Calls to those methods will take data from
2083-
*read_data* until it is depleted. The mock of these methods is pretty
2084-
simplistic: every time the *mock* is called, the *read_data* is rewound to
2085-
the start. If you need more control over the data that you are feeding to
2086-
the tested code you will need to customize this mock for yourself. When that
2087-
is insufficient, one of the in-memory filesystem packages on `PyPI
2088-
<https://pypi.org>`_ can offer a realistic filesystem for testing.
2073+
A helper function to create a mock to replace the use of :func:`open`. It works
2074+
for :func:`open` called directly or used as a context manager.
2075+
2076+
The *mock* argument is the mock object to configure. If ``None`` (the
2077+
default) then a :class:`MagicMock` will be created for you, with the API limited
2078+
to methods or attributes available on standard file handles.
2079+
2080+
*read_data* is a string for the :meth:`~io.IOBase.read`,
2081+
:meth:`~io.IOBase.readline`, and :meth:`~io.IOBase.readlines` methods
2082+
of the file handle to return. Calls to those methods will take data from
2083+
*read_data* until it is depleted. The mock of these methods is pretty
2084+
simplistic: every time the *mock* is called, the *read_data* is rewound to
2085+
the start. If you need more control over the data that you are feeding to
2086+
the tested code you will need to customize this mock for yourself. When that
2087+
is insufficient, one of the in-memory filesystem packages on `PyPI
2088+
<https://pypi.org>`_ can offer a realistic filesystem for testing.
20892089

20902090
.. versionchanged:: 3.4
20912091
Added :meth:`~io.IOBase.readline` and :meth:`~io.IOBase.readlines` support.

Doc/tutorial/inputoutput.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ printing space-separated values. There are several ways to format output.
4141
::
4242

4343
>>> yes_votes = 42_572_654 ; no_votes = 43_132_495
44-
>>> percentage = (yes_votes/(yes_votes+no_votes)
45-
>>> '{:-9} YES votes {:2.2%}'.format(yes_votes, percentage))
44+
>>> percentage = yes_votes/(yes_votes+no_votes)
45+
>>> '{:-9} YES votes {:2.2%}'.format(yes_votes, percentage)
4646
' 42572654 YES votes 49.67%'
4747

4848
* Finally, you can do all the string handling yourself by using string slicing and
@@ -338,7 +338,7 @@ automatically fail. ::
338338
>>> f.read()
339339
Traceback (most recent call last):
340340
File "<stdin>", line 1, in <module>
341-
ValueError: I/O operation on closed file
341+
ValueError: I/O operation on closed file.
342342

343343

344344
.. _tut-filemethods:

Doc/whatsnew/3.7.rst

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,8 +1304,8 @@ Host name validation can be customized with
13041304
.. note::
13051305
The improved host name check requires a *libssl* implementation compatible
13061306
with OpenSSL 1.0.2 or 1.1. Consequently, OpenSSL 0.9.8 and 1.0.1 are no
1307-
longer supported. The ssl module is mostly compatible with LibreSSL 2.7.2
1308-
and newer.
1307+
longer supported (see :ref:`37-platform-support-removals` for more details).
1308+
The ssl module is mostly compatible with LibreSSL 2.7.2 and newer.
13091309

13101310
The ``ssl`` module no longer sends IP addresses in SNI TLS extension.
13111311
(Contributed by Christian Heimes in :issue:`32185`.)
@@ -2069,10 +2069,33 @@ or higher. (Contributed by Serhiy Storchaka in :issue:`27867`.)
20692069
(Contributed by Antoine Pitrou in :issue:`16500`.)
20702070

20712071

2072+
.. _37-platform-support-removals:
2073+
20722074
Platform Support Removals
20732075
=========================
20742076

2075-
FreeBSD 9 and older are no longer officially supported.
2077+
* FreeBSD 9 and older are no longer officially supported.
2078+
* For full Unicode support, including within extension modules, \*nix platforms
2079+
are now expected to provide at least one of ``C.UTF-8`` (full locale),
2080+
``C.utf8`` (full locale) or ``UTF-8`` (``LC_CTYPE``-only locale) as an
2081+
alternative to the legacy ``ASCII``-based ``C`` locale.
2082+
* OpenSSL 0.9.8 and 1.0.1 are no longer supported, which means building CPython
2083+
3.7 with SSL/TLS support on older platforms still using these versions
2084+
requires custom build options that link to a more recent version of OpenSSL.
2085+
2086+
Notably, this issue affects the Debian 8 (aka "jessie") and Ubuntu 14.04
2087+
(aka "Trusty") LTS Linux distributions, as they still use OpenSSL 1.0.1 by
2088+
default.
2089+
2090+
Debian 9 ("stretch") and Ubuntu 16.04 ("xenial"), as well as recent releases
2091+
of other LTS Linux releases (e.g. RHEL/CentOS 7.5, SLES 12-SP3), use OpenSSL
2092+
1.0.2 or later, and remain supported in the default build configuration.
2093+
2094+
CPython's own :source:`CI configuration file <.travis.yml>` provides an
2095+
example of using the SSL
2096+
:source:`compatibility testing infrastructure <Tools/ssl/multissltests.py>` in
2097+
CPython's test suite to build and link against OpenSSL 1.1.0 rather than an
2098+
outdated system provided OpenSSL.
20762099

20772100

20782101
API and Feature Removals

Doc/whatsnew/3.8.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ Optimizations
127127
first introduced in Python 3.4. It offers better performance and smaller
128128
size compared to Protocol 3 available since Python 3.0.
129129

130+
* Removed one ``Py_ssize_t`` member from ``PyGC_Head``. All GC tracked
131+
objects (e.g. tuple, list, dict) size is reduced 4 or 8 bytes.
132+
(Contributed by Inada Naoki in :issue:`33597`)
133+
130134

131135
Build and C API Changes
132136
=======================
@@ -135,6 +139,21 @@ Build and C API Changes
135139
``const char *`` rather of ``char *``.
136140
(Contributed by Serhiy Storchaka in :issue:`33818`.)
137141

142+
* The duality of ``Modules/Setup.dist`` and ``Modules/Setup`` has been
143+
removed. Previously, when updating the CPython source tree, one had
144+
to manually copy ``Modules/Setup.dist`` (inside the source tree) to
145+
``Modules/Setup`` (inside the build tree) in order to reflect any changes
146+
upstream. This was of a small benefit to packagers at the expense of
147+
a frequent annoyance to developers following CPython development, as
148+
forgetting to copy the file could produce build failures.
149+
150+
Now the build system always reads from ``Modules/Setup`` inside the source
151+
tree. People who want to customize that file are encouraged to maintain
152+
their changes in a git fork of CPython or as patch files, as they would do
153+
for any other change to the source tree.
154+
155+
(Contributed by Antoine Pitrou in :issue:`32430`.)
156+
138157

139158
Deprecated
140159
==========
@@ -201,6 +220,10 @@ Changes in the Python API
201220
* :func:`shutil.copyfile` default buffer size on Windows was changed from
202221
16 KiB to 1 MiB.
203222

223+
* ``PyGC_Head`` struct is changed completely. All code touched the
224+
struct member should be rewritten. (See :issue:`33597`)
225+
226+
204227
CPython bytecode changes
205228
------------------------
206229

0 commit comments

Comments
 (0)