From 0407b7b7323ef47fd9f2f128b95d0cbc5a91fd22 Mon Sep 17 00:00:00 2001 From: Kyle Stanley Date: Wed, 2 Oct 2019 02:14:59 -0400 Subject: [PATCH 01/10] Several improvements to whatsnew 3.8 --- Doc/whatsnew/3.8.rst | 107 ++++++++++++++++++++++--------------------- 1 file changed, 56 insertions(+), 51 deletions(-) diff --git a/Doc/whatsnew/3.8.rst b/Doc/whatsnew/3.8.rst index 4cab2f7af118dd..0ea48e605931e2 100755 --- a/Doc/whatsnew/3.8.rst +++ b/Doc/whatsnew/3.8.rst @@ -405,8 +405,8 @@ Other Language Changes (Contributed by Jonathan Eunice and Serhiy Storchaka in :issue:`30688`.) -* Dict and dictviews are now iterable in reversed insertion order using - :func:`reversed`. (Contributed by Rémi Lapeyre in :issue:`33462`.) +* :class:`dict` and dictionary views are now iterable in reversed insertion + order using :func:`reversed`. (Contributed by Rémi Lapeyre in :issue:`33462`.) * The syntax allowed for keyword names in function calls was further restricted. In particular, ``f((keyword)=arg)`` is no longer allowed. It was @@ -414,8 +414,8 @@ Other Language Changes keyword argument assignment term. See :issue:`34641`. * Generalized iterable unpacking in :keyword:`yield` and - :keyword:`return` statements no longer requires enclosing parentheses. - This brings the *yield* and *return* syntax into better agreement with + :keyword:`return` statements no longer requires enclosing parenthesis. + This brings the ``yield`` and ``return`` syntax into better agreement with normal assignment syntax:: >>> def parse(family): @@ -439,7 +439,7 @@ Other Language Changes an instance of the subclass, rather than the base class. This also affects the return type of operations whose implementation (directly or indirectly) uses :class:`datetime.timedelta` arithmetic, such as - :meth:`datetime.datetime.astimezone`. + :meth:`~datetime.datetime.astimezone`. (Contributed by Paul Ganssle in :issue:`32417`.) * When the Python interpreter is interrupted by Ctrl-C (SIGINT) and the @@ -554,9 +554,10 @@ Improved Modules ast --- -AST nodes now have ``end_lineno`` and ``end_col_offset`` attributes, -which give the precise location of the end of the node. (This only -applies to nodes that have ``lineno`` and ``col_offset`` attributes.) +AST nodes now have :attr:`~ast.AST.end_lineno` and +:attr:`~ast.AST.end_col_offset` attributes, which give the precise location of +the end of the node. (This only applies to nodes that have ``lineno`` and +``col_offset`` attributes.) The :func:`ast.parse` function has some new flags: @@ -568,7 +569,7 @@ The :func:`ast.parse` function has some new flags: * ``feature_version=(3, N)`` allows specifying an earlier Python 3 version. (For example, ``feature_version=(3, 4)`` will treat - ``async`` and ``await`` as non-reserved words.) + :keyword:`async` and :keyword:`await` as non-reserved words.) New function :func:`ast.get_source_segment` returns the source code for a specific AST node. @@ -593,20 +594,21 @@ builtins The :func:`compile` built-in has been improved to accept the ``ast.PyCF_ALLOW_TOP_LEVEL_AWAIT`` flag. With this new flag passed, -:func:`compile` will allow top-level ``await``, ``async for`` and ``async with`` -constructs that are usually considered invalid syntax. Asynchronous code object -marked with the ``CO_COROUTINE`` flag may then be returned. +:func:`compile` will allow top-level :keyword:`await`, :keyword:`async for` and +:keyword:`async with` constructs that are usually considered invalid syntax. +Asynchronous code object marked with the :data:`inspect.CO_COROUTINE` flag may then be returned. (Contributed by Matthias Bussonnier in :issue:`34616`) collections ----------- -The :meth:`_asdict()` method for :func:`collections.namedtuple` now returns -a :class:`dict` instead of a :class:`collections.OrderedDict`. This works because -regular dicts have guaranteed ordering since Python 3.7. If the extra -features of :class:`OrderedDict` are required, the suggested remediation is -to cast the result to the desired type: ``OrderedDict(nt._asdict())``. +The :meth:`~collections.somenamedtuple._asdict` method for +:func:`collections.namedtuple` now returns +a :class:`dict` instead of a :class:`collections.OrderedDict`. This works +because regular dicts have guaranteed ordering since Python 3.7. If the extra +features of :class:`collections.OrderedDict` are required, the suggested +remediation is to cast the result to the desired type: ``OrderedDict(nt._asdict())``. (Contributed by Raymond Hettinger in :issue:`35864`.) @@ -682,10 +684,10 @@ The changes above have been backported to 3.7 maintenance releases. inspect ------- -The :func:`inspect.getdoc` function can now find docstrings for ``__slots__`` -if that attribute is a :class:`dict` where the values are docstrings. -This provides documentation options similar to what we already have -for :func:`property`, :func:`classmethod`, and :func:`staticmethod`:: +The :func:`inspect.getdoc` function can now find docstrings for +:attr:`~object.__slots__` if that attribute is a :class:`dict` where the values +are docstrings. This provides documentation options similar to what we already +have for :func:`property`, :func:`classmethod`, and :func:`staticmethod`:: class AudioClip: __slots__ = {'bit_rate': 'expressed in kilohertz to one decimal place', @@ -745,7 +747,7 @@ The changes above have been backported to 3.7 maintenance releases. json.tool --------- -Add option ``--json-lines`` to parse every input line as separate JSON object. +Add option ``--json-lines`` to parse every input line as separate JSON objects. (Contributed by Weipeng Hong in :issue:`31553`.) @@ -875,7 +877,7 @@ pickle Reduction methods can now include a 6th item in the tuple they return. This item should specify a custom state-setting method that's called instead of the -regular ``__setstate__`` method. +regular :meth:`object.__setstate__` method. (Contributed by Pierre Glaser and Olivier Grisel in :issue:`35900`) :mod:`pickle` extensions subclassing the C-optimized :class:`~pickle.Pickler` @@ -935,8 +937,8 @@ recursively removing their contents first. ssl --- -Added :attr:`SSLContext.post_handshake_auth` to enable and -:meth:`ssl.SSLSocket.verify_client_post_handshake` to initiate TLS 1.3 +Added :attr:`~ssl.SSLContext.post_handshake_auth` to enable and +:meth:`~ssl.SSLSocket.verify_client_post_handshake` to initiate TLS 1.3 post-handshake authentication. (Contributed by Christian Heimes in :issue:`34670`.) @@ -1096,8 +1098,9 @@ unicodedata unittest -------- -* Added :class:`AsyncMock` to support an asynchronous version of :class:`Mock`. - Appropriate new assert functions for testing have been added as well. +* Added :class:`~unittest.mock.AsyncMock` to support an asynchronous version of + :class:`~unittest.Mock`. Appropriate new assert functions for testing have + been added as well. (Contributed by Lisa Roach in :issue:`26467`). * Added :func:`~unittest.addModuleCleanup()` and @@ -1110,7 +1113,7 @@ unittest failure. (Contributed by Petter Strandmark in :issue:`35047`.) * :mod:`unittest` module gained support for coroutines to be used as test cases - with :class:`unittest.IsolatedAsyncioTestCase`. + with :class:`~unittest.IsolatedAsyncioTestCase`. (Contributed by Andrew Svetlov in :issue:`32972`.) Example:: @@ -1219,7 +1222,8 @@ Optimizations objects (e.g. tuple, list, dict) size is reduced 4 or 8 bytes. (Contributed by Inada Naoki in :issue:`33597`) -* :class:`uuid.UUID` now uses ``__slots__`` to reduce its memory footprint. +* :class:`uuid.UUID` now uses :attr:`~object.__slots__` to + reduce its memory footprint. * Improved performance of :func:`operator.itemgetter` by 33%. Optimized argument handling and added a fast path for the common case of a single @@ -1233,9 +1237,10 @@ Optimizations Joe Jevnik, Serhiy Storchaka in :issue:`32492`.) * The :class:`list` constructor does not overallocate the internal item buffer - if the input iterable has a known length (the input implements ``__len__``). - This makes the created list 12% smaller on average. (Contributed by - Raymond Hettinger and Pablo Galindo in :issue:`33234`.) + if the input iterable has a known length (the input implements + :meth:`~object.__len__`). This makes the created list 12% smaller + on average. + (Contributed by Raymond Hettinger and Pablo Galindo in :issue:`33234`.) * Doubled the speed of class variable writes. When a non-dunder attribute was updated, there was an unnecessary call to update slots. @@ -1327,12 +1332,12 @@ Build and C API Changes :c:func:`PyArg_ParseTuple` with integer converting format units like ``'i'`` will now use the :meth:`~object.__index__` special method instead of :meth:`~object.__int__`, if available. The deprecation warning will be - emitted for objects with the ``__int__()`` method but without the - ``__index__()`` method (like :class:`~decimal.Decimal` and + emitted for objects with the :meth:`~object.__int__` method but without the + :meth:`~object.__index__` method (like :class:`~decimal.Decimal` and :class:`~fractions.Fraction`). :c:func:`PyNumber_Check` will now return - ``1`` for objects implementing ``__index__()``. + ``1`` for objects implementing :meth:`~object.__index__`. :c:func:`PyNumber_Long`, :c:func:`PyNumber_Float` and - :c:func:`PyFloat_AsDouble` also now use the ``__index__()`` method if + :c:func:`PyFloat_AsDouble` also now use the meth:`object.__index__` method if available. (Contributed by Serhiy Storchaka in :issue:`36048` and :issue:`20092`.) @@ -1372,9 +1377,9 @@ Deprecated deprecated and will be prohibited in Python 3.9. (Contributed by Elvis Pranskevichus in :issue:`34075`.) -* The :meth:`__getitem__` methods of :class:`xml.dom.pulldom.DOMEventStream`, - :class:`wsgiref.util.FileWrapper` and :class:`fileinput.FileInput` have been - deprecated. +* The :meth:`object.__getitem__` methods of + :class:`~xml.dom.pulldom.DOMEventStream`, :class:`wsgiref.util.FileWrapper` + and :class:`fileinput.FileInput` have been deprecated. Implementations of these methods have been ignoring their *index* parameter, and returning the next item instead. @@ -1382,8 +1387,8 @@ Deprecated (Contributed by Berker Peksag in :issue:`9372`.) * The :class:`typing.NamedTuple` class has deprecated the ``_field_types`` - attribute in favor of the ``__annotations__`` attribute which has the same - information. (Contributed by Raymond Hettinger in :issue:`36320`.) + attribute in favor of the :attr:`~object.__annotations__` attribute which has + the same information. (Contributed by Raymond Hettinger in :issue:`36320`.) * :mod:`ast` classes ``Num``, ``Str``, ``Bytes``, ``NameConstant`` and ``Ellipsis`` are considered deprecated and will be removed in future Python @@ -1510,9 +1515,9 @@ that may require changes to your code. Changes in Python behavior -------------------------- -* Yield expressions (both ``yield`` and ``yield from`` clauses) are now disallowed - in comprehensions and generator expressions (aside from the iterable expression - in the leftmost :keyword:`!for` clause). +* :ref:`Yield expressions ` (both :keyword:`yield` and ``yield from`` + clauses) are now disallowed in comprehensions and generator expressions + (aside from the iterable expression in the leftmost :keyword:`!for` clause). (Contributed by Serhiy Storchaka in :issue:`10544`.) * The compiler now produces a :exc:`SyntaxWarning` when identity checks @@ -1527,11 +1532,11 @@ Changes in Python behavior raised when getting the attribute from the type dictionary are no longer ignored. (Contributed by Serhiy Storchaka in :issue:`35459`.) -* Removed ``__str__`` implementations from builtin types :class:`bool`, - :class:`int`, :class:`float`, :class:`complex` and few classes from - the standard library. They now inherit ``__str__()`` from :class:`object`. - As result, defining the ``__repr__()`` method in the subclass of these - classes will affect their string representation. +* Removed :meth:`~object.__str__` implementations from builtin types + :class:`bool`, :class:`int`, :class:`float`, :class:`complex` and few classes + from the standard library. They now inherit :meth:`~object.__str__` from + :class:`object`. As result, defining the :meth:`~object.__repr__` method + in the subclass of these classes will affect their string representation. (Contributed by Serhiy Storchaka in :issue:`36793`.) * On AIX, :attr:`sys.platform` doesn't contain the major version anymore. @@ -1568,7 +1573,7 @@ Changes in the Python API (Contributed by Eric Snow in :issue:`34651`, modified by Christian Heimes in :issue:`37951`.) -* The :meth:`imap.IMAP4.logout` method no longer ignores silently arbitrary +* The :meth:`imaplib.IMAP4.logout` method no longer ignores silently arbitrary exceptions. * The function :func:`platform.popen` has been removed, it was deprecated since @@ -1622,7 +1627,7 @@ Changes in the Python API * The ``PyGC_Head`` struct has changed completely. All code that touched the struct member should be rewritten. (See :issue:`33597`) -* The ``PyInterpreterState`` struct has been moved into the "internal" +* The :c:type:`PyInterpreterState` struct has been moved into the "internal" header files (specifically Include/internal/pycore_pystate.h). An opaque ``PyInterpreterState`` is still available as part of the public API (and stable ABI). The docs indicate that none of the struct's From 30129c25c98d962b2768361aa22a2faba6a5fafc Mon Sep 17 00:00:00 2001 From: Kyle Stanley Date: Wed, 2 Oct 2019 02:23:10 -0400 Subject: [PATCH 02/10] Fix line width --- Doc/whatsnew/3.8.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.8.rst b/Doc/whatsnew/3.8.rst index 0ea48e605931e2..230268efd660fb 100755 --- a/Doc/whatsnew/3.8.rst +++ b/Doc/whatsnew/3.8.rst @@ -596,7 +596,8 @@ The :func:`compile` built-in has been improved to accept the ``ast.PyCF_ALLOW_TOP_LEVEL_AWAIT`` flag. With this new flag passed, :func:`compile` will allow top-level :keyword:`await`, :keyword:`async for` and :keyword:`async with` constructs that are usually considered invalid syntax. -Asynchronous code object marked with the :data:`inspect.CO_COROUTINE` flag may then be returned. +Asynchronous code object marked with the :data:`inspect.CO_COROUTINE` flag may +then be returned. (Contributed by Matthias Bussonnier in :issue:`34616`) From 2da2059de4f831054340d9293b3d89af26e2a8d2 Mon Sep 17 00:00:00 2001 From: Kyle Stanley Date: Wed, 2 Oct 2019 02:28:51 -0400 Subject: [PATCH 03/10] Fix sphinx role --- Doc/whatsnew/3.8.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/whatsnew/3.8.rst b/Doc/whatsnew/3.8.rst index 230268efd660fb..cf3db542edce73 100755 --- a/Doc/whatsnew/3.8.rst +++ b/Doc/whatsnew/3.8.rst @@ -1338,8 +1338,8 @@ Build and C API Changes :class:`~fractions.Fraction`). :c:func:`PyNumber_Check` will now return ``1`` for objects implementing :meth:`~object.__index__`. :c:func:`PyNumber_Long`, :c:func:`PyNumber_Float` and - :c:func:`PyFloat_AsDouble` also now use the meth:`object.__index__` method if - available. + :c:func:`PyFloat_AsDouble` also now use the :meth:`object.__index__` method + if available. (Contributed by Serhiy Storchaka in :issue:`36048` and :issue:`20092`.) * Heap-allocated type objects will now increase their reference count From a6abf444e50700016de20465aa1606ee35cc28f1 Mon Sep 17 00:00:00 2001 From: Kyle Stanley Date: Wed, 2 Oct 2019 02:32:25 -0400 Subject: [PATCH 04/10] Fix sphinx role --- Doc/whatsnew/3.8.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.8.rst b/Doc/whatsnew/3.8.rst index cf3db542edce73..17890b3602bf44 100755 --- a/Doc/whatsnew/3.8.rst +++ b/Doc/whatsnew/3.8.rst @@ -1100,7 +1100,7 @@ unittest -------- * Added :class:`~unittest.mock.AsyncMock` to support an asynchronous version of - :class:`~unittest.Mock`. Appropriate new assert functions for testing have + :class:`~unittest.mock.Mock`. Appropriate new assert functions for testing have been added as well. (Contributed by Lisa Roach in :issue:`26467`). From 1abee7b36a0c41f7bdfa9f5e242d59bd60b0acc0 Mon Sep 17 00:00:00 2001 From: Kyle Stanley Date: Sat, 5 Oct 2019 15:58:37 -0400 Subject: [PATCH 05/10] Grammar fix --- Doc/whatsnew/3.8.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.8.rst b/Doc/whatsnew/3.8.rst index 17890b3602bf44..2ed6e2a374755f 100755 --- a/Doc/whatsnew/3.8.rst +++ b/Doc/whatsnew/3.8.rst @@ -596,7 +596,7 @@ The :func:`compile` built-in has been improved to accept the ``ast.PyCF_ALLOW_TOP_LEVEL_AWAIT`` flag. With this new flag passed, :func:`compile` will allow top-level :keyword:`await`, :keyword:`async for` and :keyword:`async with` constructs that are usually considered invalid syntax. -Asynchronous code object marked with the :data:`inspect.CO_COROUTINE` flag may +Asynchronous code objects marked with the :data:`inspect.CO_COROUTINE` flag may then be returned. (Contributed by Matthias Bussonnier in :issue:`34616`) From a018f9ad34e9062a5aef06ea9bccca0bec35330d Mon Sep 17 00:00:00 2001 From: Kyle Stanley Date: Sat, 5 Oct 2019 16:05:07 -0400 Subject: [PATCH 06/10] Grammar Fixes --- Doc/whatsnew/3.8.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/whatsnew/3.8.rst b/Doc/whatsnew/3.8.rst index 2ed6e2a374755f..88ddc166a5f57a 100755 --- a/Doc/whatsnew/3.8.rst +++ b/Doc/whatsnew/3.8.rst @@ -748,7 +748,7 @@ The changes above have been backported to 3.7 maintenance releases. json.tool --------- -Add option ``--json-lines`` to parse every input line as separate JSON objects. +Add option ``--json-lines`` to parse every input line as a separate JSON object. (Contributed by Weipeng Hong in :issue:`31553`.) @@ -1574,7 +1574,7 @@ Changes in the Python API (Contributed by Eric Snow in :issue:`34651`, modified by Christian Heimes in :issue:`37951`.) -* The :meth:`imaplib.IMAP4.logout` method no longer ignores silently arbitrary +* The :meth:`imaplib.IMAP4.logout` method no longer silently ignores arbitrary exceptions. * The function :func:`platform.popen` has been removed, it was deprecated since From fd6fd07f1b2e6427e93c83086c15de7790a754f5 Mon Sep 17 00:00:00 2001 From: Kyle Stanley Date: Sat, 5 Oct 2019 22:47:32 -0400 Subject: [PATCH 07/10] Apply suggestions --- Doc/whatsnew/3.8.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/whatsnew/3.8.rst b/Doc/whatsnew/3.8.rst index 88ddc166a5f57a..fa057c152465f4 100755 --- a/Doc/whatsnew/3.8.rst +++ b/Doc/whatsnew/3.8.rst @@ -405,7 +405,7 @@ Other Language Changes (Contributed by Jonathan Eunice and Serhiy Storchaka in :issue:`30688`.) -* :class:`dict` and dictionary views are now iterable in reversed insertion +* :class:`dict` and :term:`dictionary view`s are now iterable in reversed insertion order using :func:`reversed`. (Contributed by Rémi Lapeyre in :issue:`33462`.) * The syntax allowed for keyword names in function calls was further @@ -414,7 +414,7 @@ Other Language Changes keyword argument assignment term. See :issue:`34641`. * Generalized iterable unpacking in :keyword:`yield` and - :keyword:`return` statements no longer requires enclosing parenthesis. + :keyword:`return` statements no longer requires enclosing parentheses. This brings the ``yield`` and ``return`` syntax into better agreement with normal assignment syntax:: From ad0c22c86d114f1c974963cb80c5915d7314af53 Mon Sep 17 00:00:00 2001 From: Kyle Stanley Date: Sat, 5 Oct 2019 22:50:04 -0400 Subject: [PATCH 08/10] Fix word wrapping from suggestion --- Doc/whatsnew/3.8.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Doc/whatsnew/3.8.rst b/Doc/whatsnew/3.8.rst index fa057c152465f4..ac2961855aa258 100755 --- a/Doc/whatsnew/3.8.rst +++ b/Doc/whatsnew/3.8.rst @@ -405,8 +405,9 @@ Other Language Changes (Contributed by Jonathan Eunice and Serhiy Storchaka in :issue:`30688`.) -* :class:`dict` and :term:`dictionary view`s are now iterable in reversed insertion - order using :func:`reversed`. (Contributed by Rémi Lapeyre in :issue:`33462`.) +* :class:`dict` and :term:`dictionary view`s are now iterable in reversed + insertion order using :func:`reversed`. + (Contributed by Rémi Lapeyre in :issue:`33462`.) * The syntax allowed for keyword names in function calls was further restricted. In particular, ``f((keyword)=arg)`` is no longer allowed. It was From 7e9c550dc1988170eb6a51ac8a744363854fd8c8 Mon Sep 17 00:00:00 2001 From: Kyle Stanley Date: Sat, 5 Oct 2019 23:15:57 -0400 Subject: [PATCH 09/10] Fix Sphinx role --- Doc/whatsnew/3.8.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/whatsnew/3.8.rst b/Doc/whatsnew/3.8.rst index ac2961855aa258..58a347c2045b42 100755 --- a/Doc/whatsnew/3.8.rst +++ b/Doc/whatsnew/3.8.rst @@ -405,8 +405,8 @@ Other Language Changes (Contributed by Jonathan Eunice and Serhiy Storchaka in :issue:`30688`.) -* :class:`dict` and :term:`dictionary view`s are now iterable in reversed - insertion order using :func:`reversed`. +* :class:`dict` and :term:`dictionary views ` are now iterable + in reversed insertion order using :func:`reversed`. (Contributed by Rémi Lapeyre in :issue:`33462`.) * The syntax allowed for keyword names in function calls was further From f101ad177dc51de165f327d8061ac5bac526b5ed Mon Sep 17 00:00:00 2001 From: Kyle Stanley Date: Sun, 6 Oct 2019 01:33:17 -0400 Subject: [PATCH 10/10] Fix sphinx role --- Doc/whatsnew/3.8.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.8.rst b/Doc/whatsnew/3.8.rst index 58a347c2045b42..66c3882820e1b2 100755 --- a/Doc/whatsnew/3.8.rst +++ b/Doc/whatsnew/3.8.rst @@ -405,7 +405,7 @@ Other Language Changes (Contributed by Jonathan Eunice and Serhiy Storchaka in :issue:`30688`.) -* :class:`dict` and :term:`dictionary views ` are now iterable +* :class:`dict` and :term:`dictionary views ` are now iterable in reversed insertion order using :func:`reversed`. (Contributed by Rémi Lapeyre in :issue:`33462`.)