@@ -355,8 +355,8 @@ It is meant to formalize existing optimizations which were already done
355355for various classes.
356356Any extension type implementing a callable can use this protocol.
357357
358- This is currently provisional,
359- the aim is to make it fully public in Python 3.9.
358+ This is currently provisional.
359+ The aim is to make it fully public in Python 3.9.
360360
361361See :pep: `590 ` for a full description.
362362
@@ -445,7 +445,7 @@ Other Language Changes
445445 an instance of the subclass, rather than the base class. This also affects
446446 the return type of operations whose implementation (directly or indirectly)
447447 uses :class: `datetime.timedelta ` arithmetic, such as
448- :meth: `datetime.datetime.astimezone `.
448+ :meth: `~ datetime.datetime.astimezone `.
449449 (Contributed by Paul Ganssle in :issue: `32417 `.)
450450
451451* When the Python interpreter is interrupted by Ctrl-C (SIGINT) and the
@@ -529,6 +529,13 @@ Other Language Changes
529529
530530 (Contributed by Jörn Heissler in :issue: `35224 `.)
531531
532+ * The :meth: `object.__reduce__ ` method can now return a tuple from two to
533+ six elements long. Formerly, five was the limit. The new, optional sixth
534+ element is a callable with a ``(obj, state) `` signature. This allows the
535+ direct control over the state-updating behavior of a specific object. If
536+ not *None *, this callable will have priority over the object's
537+ :meth: `~__setstate__ ` method.
538+ (Contributed by Pierre Glaser and Olivier Grisel in :issue: `35900 `.)
532539
533540New Modules
534541===========
@@ -579,8 +586,8 @@ The :func:`ast.parse` function has some new flags:
579586 comments" (returned for function definition AST nodes);
580587
581588* ``feature_version=(3, N) `` allows specifying an earlier Python 3
582- version. ( For example, ``feature_version=(3, 4) `` will treat
583- `` async `` and `` await `` as non-reserved words.)
589+ version. For example, ``feature_version=(3, 4) `` will treat
590+ :keyword: ` async ` and :keyword: ` await ` as non-reserved words.
584591
585592(Contributed by Guido van Rossum in :issue: `35766 `.)
586593
@@ -630,14 +637,39 @@ marked with the ``CO_COROUTINE`` flag may then be returned.
630637collections
631638-----------
632639
633- The :meth: `_asdict() ` method for :func: `collections.namedtuple ` now returns
634- a :class: `dict ` instead of a :class: `collections.OrderedDict `. This works because
635- regular dicts have guaranteed ordering since Python 3.7. If the extra
636- features of :class: `OrderedDict ` are required, the suggested remediation is
637- to cast the result to the desired type: ``OrderedDict(nt._asdict()) ``.
640+ The :meth: `~collections.somenamedtuple._asdict ` method for
641+ :func: `collections.namedtuple ` now returns a :class: `dict ` instead of a
642+ :class: `collections.OrderedDict `. This works because regular dicts have
643+ guaranteed ordering since Python 3.7. If the extra features of
644+ :class: `OrderedDict ` are required, the suggested remediation is to cast the
645+ result to the desired type: ``OrderedDict(nt._asdict()) ``.
638646(Contributed by Raymond Hettinger in :issue: `35864 `.)
639647
640648
649+ cProfile
650+ --------
651+
652+ The :class: `cProfile.Profile <profile.Profile> ` class can now be used as a context manager.
653+ Profile a block of code by running::
654+
655+ import cProfile
656+
657+ with cProfile.Profile() as profiler:
658+ # code to be profiled
659+ ...
660+
661+ (Contributed by Scott Sanderson in :issue: `29235 `.)
662+
663+
664+ csv
665+ ---
666+
667+ The :class: `csv.DictReader ` now returns instances of :class: `dict ` instead of
668+ a :class: `collections.OrderedDict `. The tool is now faster and uses less
669+ memory while still preserving the field order.
670+ (Contributed by Michael Seek in :issue: `34003 `.)
671+
672+
641673curses
642674-------
643675
@@ -700,6 +732,30 @@ cached for the life of the instance. ::
700732(Contributed by Carl Meyer in :issue: `21145 `)
701733
702734
735+ Added a new :func: `functools.singledispatchmethod ` decorator that converts
736+ methods into :term: `generic functions <generic function> ` using
737+ :term: `single dispatch `::
738+
739+ from functools import singledispatchmethod
740+ from contextlib import suppress
741+
742+ class TaskManager:
743+
744+ def __init__(self, tasks):
745+ self.tasks = list(tasks)
746+
747+ @singledispatchmethod
748+ def discard(self, value):
749+ with suppress(ValueError):
750+ self.tasks.remove(value)
751+
752+ @discard.register(list)
753+ def _(self, tasks):
754+ targets = set(tasks)
755+ self.tasks = [x for x in self.tasks if x not in targets]
756+
757+ (Contributed by Ethan Smith in :issue: `32380 `)
758+
703759gc
704760--
705761
@@ -727,7 +783,7 @@ for certain types of invalid or corrupt gzip files.
727783:issue: `6584 `.)
728784
729785
730- idlelib and IDLE
786+ IDLE and idlelib
731787----------------
732788
733789Output over N lines (50 by default) is squeezed down to a button.
@@ -743,12 +799,19 @@ They also re-appear in the box for the next customized run. One can also
743799suppress the normal Shell main module restart. (Contributed by Cheryl
744800Sabella, Terry Jan Reedy, and others in :issue: `5680 ` and :issue: `37627 `.)
745801
746- Add optional line numbers for IDLE editor windows. Windows
802+ Added optional line numbers for IDLE editor windows. Windows
747803open without line numbers unless set otherwise in the General
748804tab of the configuration dialog. Line numbers for an existing
749805window are shown and hidden in the Options menu.
750806(Contributed by Tal Einat and Saimadhav Heblikar in :issue: `17535 `.)
751807
808+ OS native encoding is now used for converting between Python strings and Tcl
809+ objects. This allows IDLE to work with emoji and other non-BMP characters.
810+ These characters can be displayed or copied and pasted to or from the
811+ clipboard. Converting strings from Tcl to Python and back now never fails.
812+ (Many people worked on this for eight years but the problem was finally
813+ solved by Serhiy Storchaka in :issue: `13153 `.)
814+
752815The changes above have been backported to 3.7 maintenance releases.
753816
754817
@@ -779,13 +842,44 @@ fails. The exception is ignored silently by default in release build.
779842(Contributed by Victor Stinner in :issue: `18748 `.)
780843
781844
845+ itertools
846+ ---------
847+
848+ The :func: `itertools.accumulate ` function added an option *initial * keyword
849+ argument to specify an initial value::
850+
851+ >>> from itertools import accumulate
852+ >>> list(accumulate([10, 5, 30, 15], initial=1000))
853+ [1000, 1010, 1015, 1045, 1060]
854+
855+ (Contributed by Lisa Roach in :issue: `34659 `.)
856+
857+
782858json.tool
783859---------
784860
785- Add option ``--json-lines `` to parse every input line as separate JSON object.
861+ Add option ``--json-lines `` to parse every input line as a separate JSON object.
786862(Contributed by Weipeng Hong in :issue: `31553 `.)
787863
788864
865+ logging
866+ -------
867+
868+ Added a *force * keyword argument to :func: `logging.basicConfig() `
869+ When set to *True *, any existing handlers attached
870+ to the root logger are removed and closed before carrying out the
871+ configuration specified by the other arguments.
872+
873+ This solves a long-standing problem. Once a logger or *basicConfig() * had
874+ been called, subsequent calls to *basicConfig() * were silently ignored.
875+ This made it difficult to update, experiment with, or teach the various
876+ logging configuration options using the interactive prompt or a Jupyter
877+ notebook.
878+
879+ (Suggested by Raymond Hettinger, implemented by Dong-hee Na, and
880+ reviewed by Vinay Sajip in :issue: `33897 `.)
881+
882+
789883math
790884----
791885
@@ -807,7 +901,28 @@ numbers::
807901
808902(Contributed by Pablo Galindo in :issue: `35606 `.)
809903
810- Added new function :func: `math.isqrt ` for computing integer square roots.
904+ Added two new combinatoric functions :func: `math.perm ` and :func: `math.comb `::
905+
906+ >>> math.perm(10, 3) # Permutations of 10 things taken 3 at a time
907+ 720
908+ >>> math.comb(10, 3) # Combinations of 10 things taken 3 at a time
909+ 120
910+
911+ (Contributed by Yash Aggarwal, Keller Fuchs, Serhiy Storchaka, and Raymond
912+ Hettinger in :issue: `37128 `, :issue: `37178 `, and :issue: `35431 `.)
913+
914+ Added a new function :func: `math.isqrt ` for computing accurate integer square
915+ roots without conversion to floating point. The new function supports
916+ arbitrarily large integers. It is faster than ``floor(sqrt(n)) `` but slower
917+ than :func: `math.sqrt `::
918+
919+ >>> r = 650320427
920+ >>> s = r ** 2
921+ >>> isqrt(s - 1) # correct
922+ 650320426
923+ >>> floor(sqrt(s - 1)) # incorrect
924+ 650320427
925+
811926(Contributed by Mark Dickinson in :issue: `36887 `.)
812927
813928The function :func: `math.factorial ` no longer accepts arguments that are not
@@ -908,11 +1023,6 @@ to a path.
9081023pickle
9091024------
9101025
911- Reduction methods can now include a 6th item in the tuple they return. This
912- item should specify a custom state-setting method that's called instead of the
913- regular ``__setstate__ `` method.
914- (Contributed by Pierre Glaser and Olivier Grisel in :issue: `35900 `.)
915-
9161026:mod: `pickle ` extensions subclassing the C-optimized :class: `~pickle.Pickler `
9171027can now override the pickling logic of functions and classes by defining the
9181028special :meth: `~pickle.Pickler.reducer_override ` method.
@@ -927,6 +1037,32 @@ NSKeyedArchiver-encoded binary plists.
9271037(Contributed by Jon Janzen in :issue: `26707 `.)
9281038
9291039
1040+ pprint
1041+ ------
1042+
1043+ The :mod: `pprint ` module added a *sort_dicts * parameter to several functions.
1044+ By default, those functions continue to sort dictionaries before rendering or
1045+ printing. However, if *sort_dicts * is set to *False *, the dictionaries retain
1046+ the order that keys were inserted. This can be useful for comparison to JSON
1047+ inputs during debugging.
1048+
1049+ In addition, there is a convenience new function, :func: `pprint.pp ` that is
1050+ like :func: `pprint.pprint ` but with *sort_dicts * defaulting to *False *::
1051+
1052+ >>> from pprint import pprint, pp
1053+ >>> d = dict(source='input.txt', operation='filter', destination='output.txt')
1054+ >>> pp(d, width=40) # Original order
1055+ {'source': 'input.txt',
1056+ 'operation': 'filter',
1057+ 'destination': 'output.txt'}
1058+ >>> pprint(d, width=40) # Keys sorted alphabetically
1059+ {'destination': 'output.txt',
1060+ 'operation': 'filter',
1061+ 'source': 'input.txt'}
1062+
1063+ (Contributed by Rémi Lapeyre in :issue: `30670 `.)
1064+
1065+
9301066py_compile
9311067----------
9321068
@@ -973,8 +1109,8 @@ The :func:`socket.if_nameindex()`, :func:`socket.if_nametoindex()`, and
9731109ssl
9741110---
9751111
976- Added :attr: `ssl.SSLContext.post_handshake_auth ` to enable and
977- :meth: `ssl.SSLSocket.verify_client_post_handshake ` to initiate TLS 1.3
1112+ Added :attr: `~ ssl.SSLContext.post_handshake_auth ` to enable and
1113+ :meth: `~ ssl.SSLSocket.verify_client_post_handshake ` to initiate TLS 1.3
9781114post-handshake authentication.
9791115(Contributed by Christian Heimes in :issue: `34670 `.)
9801116
@@ -1152,8 +1288,9 @@ the string. (Contributed by Max Belanger, David Euresti, and Greg Price in
11521288unittest
11531289--------
11541290
1155- Added :class: `AsyncMock ` to support an asynchronous version of :class: `Mock `.
1156- Appropriate new assert functions for testing have been added as well.
1291+ Added :class: `~unittest.mock.AsyncMock ` to support an asynchronous version of
1292+ :class: `~unittest.mock.Mock `. Appropriate new assert functions for testing
1293+ have been added as well.
11571294(Contributed by Lisa Roach in :issue: `26467 `).
11581295
11591296Added :func: `~unittest.addModuleCleanup() ` and
@@ -1233,6 +1370,16 @@ them in the generated tree.
12331370(Contributed by Stefan Behnel in :issue: `36676 ` and :issue: `36673 `.)
12341371
12351372
1373+ xmlrpc
1374+ ------
1375+
1376+ :class: `xmlrpc.client.ServerProxy ` now supports an optional *headers * keyword
1377+ argument for a sequence of HTTP headers to be sent with each request. Among
1378+ other things, this makes it possible to upgrade from default basic
1379+ authentication to faster session authentication.
1380+ (Contributed by Cédric Krier in :issue: `35153 `.)
1381+
1382+
12361383Optimizations
12371384=============
12381385
@@ -1456,6 +1603,11 @@ Deprecated
14561603 constant nodes.
14571604 (Contributed by Serhiy Storchaka in :issue: `36917 `.)
14581605
1606+ * The :func: `asyncio.coroutine ` :term: `decorator ` is deprecated and will be
1607+ removed in version 3.10. Instead of ``@asyncio.coroutine ``, use
1608+ :keyword: `async def ` instead.
1609+ (Contributed by Andrew Svetlov in :issue: `36921 `.)
1610+
14591611* The following functions and methods are deprecated in the :mod: `gettext `
14601612 module: :func: `~gettext.lgettext `, :func: `~gettext.ldgettext `,
14611613 :func: `~gettext.lngettext ` and :func: `~gettext.ldngettext `.
@@ -1502,7 +1654,7 @@ Deprecated
15021654 :class: `multiprocessing.managers.SharedMemoryServer `.
15031655 - *obj * in :func: `weakref.finalize `.
15041656
1505- In future releases of Python they will be :ref: `positional-only
1657+ In future releases of Python, they will be :ref: `positional-only
15061658 <positional-only_parameter>`.
15071659 (Contributed by Serhiy Storchaka in :issue: `36492 `.)
15081660
@@ -1512,6 +1664,11 @@ API and Feature Removals
15121664
15131665The following features and APIs have been removed from Python 3.8:
15141666
1667+ * Starting with Python 3.3, importing ABCs from :mod: `collections ` was
1668+ deprecated, and importing should be done from :mod: `collections.abc `. Being
1669+ able to import from collections was marked for removal in 3.8, but has been
1670+ delayed to 3.9. (See :issue: `36952 `.)
1671+
15151672* The :mod: `macpath ` module, deprecated in Python 3.7, has been removed.
15161673 (Contributed by Victor Stinner in :issue: `35471 `.)
15171674
@@ -1630,7 +1787,7 @@ Changes in the Python API
16301787 (Contributed by Eric Snow in :issue: `34651 `, modified by Christian Heimes
16311788 in :issue: `37951 `.)
16321789
1633- * The :meth: `imap.IMAP4.logout ` method no longer ignores silently arbitrary
1790+ * The :meth: `imap.IMAP4.logout ` method no longer silently ignores arbitrary
16341791 exceptions.
16351792 (Contributed by Victor Stinner in :issue: `36348 `.)
16361793
@@ -1685,7 +1842,7 @@ Changes in the Python API
16851842* The ``PyGC_Head `` struct has changed completely. All code that touched the
16861843 struct member should be rewritten. (See :issue: `33597 `.)
16871844
1688- * The `` PyInterpreterState ` ` struct has been moved into the "internal"
1845+ * The :c:type: ` PyInterpreterState ` struct has been moved into the "internal"
16891846 header files (specifically Include/internal/pycore_pystate.h). An
16901847 opaque ``PyInterpreterState `` is still available as part of the public
16911848 API (and stable ABI). The docs indicate that none of the struct's
0 commit comments