@@ -357,8 +357,8 @@ It is meant to formalize existing optimizations which were already done
357357for various classes.
358358Any extension type implementing a callable can use this protocol.
359359
360- This is currently provisional,
361- the aim is to make it fully public in Python 3.9.
360+ This is currently provisional.
361+ The aim is to make it fully public in Python 3.9.
362362
363363See :pep: `590 ` for a full description.
364364
@@ -447,7 +447,7 @@ Other Language Changes
447447 an instance of the subclass, rather than the base class. This also affects
448448 the return type of operations whose implementation (directly or indirectly)
449449 uses :class: `datetime.timedelta ` arithmetic, such as
450- :meth: `datetime.datetime.astimezone `.
450+ :meth: `~ datetime.datetime.astimezone `.
451451 (Contributed by Paul Ganssle in :issue: `32417 `.)
452452
453453* When the Python interpreter is interrupted by Ctrl-C (SIGINT) and the
@@ -531,6 +531,13 @@ Other Language Changes
531531
532532 (Contributed by Jörn Heissler in :issue: `35224 `.)
533533
534+ * The :meth: `object.__reduce__ ` method can now return a tuple from two to
535+ six elements long. Formerly, five was the limit. The new, optional sixth
536+ element is a callable with a ``(obj, state) `` signature. This allows the
537+ direct control over the state-updating behavior of a specific object. If
538+ not *None *, this callable will have priority over the object's
539+ :meth: `~__setstate__ ` method.
540+ (Contributed by Pierre Glaser and Olivier Grisel in :issue: `35900 `.)
534541
535542New Modules
536543===========
@@ -581,8 +588,8 @@ The :func:`ast.parse` function has some new flags:
581588 comments" (returned for function definition AST nodes);
582589
583590* ``feature_version=(3, N) `` allows specifying an earlier Python 3
584- version. ( For example, ``feature_version=(3, 4) `` will treat
585- `` async `` and `` await `` as non-reserved words.)
591+ version. For example, ``feature_version=(3, 4) `` will treat
592+ :keyword: ` async ` and :keyword: ` await ` as non-reserved words.
586593
587594(Contributed by Guido van Rossum in :issue: `35766 `.)
588595
@@ -632,14 +639,39 @@ marked with the ``CO_COROUTINE`` flag may then be returned.
632639collections
633640-----------
634641
635- The :meth: `_asdict() ` method for :func: `collections.namedtuple ` now returns
636- a :class: `dict ` instead of a :class: `collections.OrderedDict `. This works because
637- regular dicts have guaranteed ordering since Python 3.7. If the extra
638- features of :class: `OrderedDict ` are required, the suggested remediation is
639- to cast the result to the desired type: ``OrderedDict(nt._asdict()) ``.
642+ The :meth: `~collections.somenamedtuple._asdict ` method for
643+ :func: `collections.namedtuple ` now returns a :class: `dict ` instead of a
644+ :class: `collections.OrderedDict `. This works because regular dicts have
645+ guaranteed ordering since Python 3.7. If the extra features of
646+ :class: `OrderedDict ` are required, the suggested remediation is to cast the
647+ result to the desired type: ``OrderedDict(nt._asdict()) ``.
640648(Contributed by Raymond Hettinger in :issue: `35864 `.)
641649
642650
651+ cProfile
652+ --------
653+
654+ The :class: `cProfile.Profile <profile.Profile> ` class can now be used as a context manager.
655+ Profile a block of code by running::
656+
657+ import cProfile
658+
659+ with cProfile.Profile() as profiler:
660+ # code to be profiled
661+ ...
662+
663+ (Contributed by Scott Sanderson in :issue: `29235 `.)
664+
665+
666+ csv
667+ ---
668+
669+ The :class: `csv.DictReader ` now returns instances of :class: `dict ` instead of
670+ a :class: `collections.OrderedDict `. The tool is now faster and uses less
671+ memory while still preserving the field order.
672+ (Contributed by Michael Seek in :issue: `34003 `.)
673+
674+
643675curses
644676-------
645677
@@ -702,6 +734,30 @@ cached for the life of the instance. ::
702734(Contributed by Carl Meyer in :issue: `21145 `)
703735
704736
737+ Added a new :func: `functools.singledispatchmethod ` decorator that converts
738+ methods into :term: `generic functions <generic function> ` using
739+ :term: `single dispatch `::
740+
741+ from functools import singledispatchmethod
742+ from contextlib import suppress
743+
744+ class TaskManager:
745+
746+ def __init__(self, tasks):
747+ self.tasks = list(tasks)
748+
749+ @singledispatchmethod
750+ def discard(self, value):
751+ with suppress(ValueError):
752+ self.tasks.remove(value)
753+
754+ @discard.register(list)
755+ def _(self, tasks):
756+ targets = set(tasks)
757+ self.tasks = [x for x in self.tasks if x not in targets]
758+
759+ (Contributed by Ethan Smith in :issue: `32380 `)
760+
705761gc
706762--
707763
@@ -729,7 +785,7 @@ for certain types of invalid or corrupt gzip files.
729785:issue: `6584 `.)
730786
731787
732- idlelib and IDLE
788+ IDLE and idlelib
733789----------------
734790
735791Output over N lines (50 by default) is squeezed down to a button.
@@ -745,12 +801,19 @@ They also re-appear in the box for the next customized run. One can also
745801suppress the normal Shell main module restart. (Contributed by Cheryl
746802Sabella, Terry Jan Reedy, and others in :issue: `5680 ` and :issue: `37627 `.)
747803
748- Add optional line numbers for IDLE editor windows. Windows
804+ Added optional line numbers for IDLE editor windows. Windows
749805open without line numbers unless set otherwise in the General
750806tab of the configuration dialog. Line numbers for an existing
751807window are shown and hidden in the Options menu.
752808(Contributed by Tal Einat and Saimadhav Heblikar in :issue: `17535 `.)
753809
810+ OS native encoding is now used for converting between Python strings and Tcl
811+ objects. This allows IDLE to work with emoji and other non-BMP characters.
812+ These characters can be displayed or copied and pasted to or from the
813+ clipboard. Converting strings from Tcl to Python and back now never fails.
814+ (Many people worked on this for eight years but the problem was finally
815+ solved by Serhiy Storchaka in :issue: `13153 `.)
816+
754817The changes above have been backported to 3.7 maintenance releases.
755818
756819
@@ -781,13 +844,44 @@ fails. The exception is ignored silently by default in release build.
781844(Contributed by Victor Stinner in :issue: `18748 `.)
782845
783846
847+ itertools
848+ ---------
849+
850+ The :func: `itertools.accumulate ` function added an option *initial * keyword
851+ argument to specify an initial value::
852+
853+ >>> from itertools import accumulate
854+ >>> list(accumulate([10, 5, 30, 15], initial=1000))
855+ [1000, 1010, 1015, 1045, 1060]
856+
857+ (Contributed by Lisa Roach in :issue: `34659 `.)
858+
859+
784860json.tool
785861---------
786862
787- Add option ``--json-lines `` to parse every input line as separate JSON object.
863+ Add option ``--json-lines `` to parse every input line as a separate JSON object.
788864(Contributed by Weipeng Hong in :issue: `31553 `.)
789865
790866
867+ logging
868+ -------
869+
870+ Added a *force * keyword argument to :func: `logging.basicConfig() `
871+ When set to *True *, any existing handlers attached
872+ to the root logger are removed and closed before carrying out the
873+ configuration specified by the other arguments.
874+
875+ This solves a long-standing problem. Once a logger or *basicConfig() * had
876+ been called, subsequent calls to *basicConfig() * were silently ignored.
877+ This made it difficult to update, experiment with, or teach the various
878+ logging configuration options using the interactive prompt or a Jupyter
879+ notebook.
880+
881+ (Suggested by Raymond Hettinger, implemented by Dong-hee Na, and
882+ reviewed by Vinay Sajip in :issue: `33897 `.)
883+
884+
791885math
792886----
793887
@@ -809,7 +903,28 @@ numbers::
809903
810904(Contributed by Pablo Galindo in :issue: `35606 `.)
811905
812- Added new function :func: `math.isqrt ` for computing integer square roots.
906+ Added two new combinatoric functions :func: `math.perm ` and :func: `math.comb `::
907+
908+ >>> math.perm(10, 3) # Permutations of 10 things taken 3 at a time
909+ 720
910+ >>> math.comb(10, 3) # Combinations of 10 things taken 3 at a time
911+ 120
912+
913+ (Contributed by Yash Aggarwal, Keller Fuchs, Serhiy Storchaka, and Raymond
914+ Hettinger in :issue: `37128 `, :issue: `37178 `, and :issue: `35431 `.)
915+
916+ Added a new function :func: `math.isqrt ` for computing accurate integer square
917+ roots without conversion to floating point. The new function supports
918+ arbitrarily large integers. It is faster than ``floor(sqrt(n)) `` but slower
919+ than :func: `math.sqrt `::
920+
921+ >>> r = 650320427
922+ >>> s = r ** 2
923+ >>> isqrt(s - 1) # correct
924+ 650320426
925+ >>> floor(sqrt(s - 1)) # incorrect
926+ 650320427
927+
813928(Contributed by Mark Dickinson in :issue: `36887 `.)
814929
815930The function :func: `math.factorial ` no longer accepts arguments that are not
@@ -910,11 +1025,6 @@ to a path.
9101025pickle
9111026------
9121027
913- Reduction methods can now include a 6th item in the tuple they return. This
914- item should specify a custom state-setting method that's called instead of the
915- regular ``__setstate__ `` method.
916- (Contributed by Pierre Glaser and Olivier Grisel in :issue: `35900 `.)
917-
9181028:mod: `pickle ` extensions subclassing the C-optimized :class: `~pickle.Pickler `
9191029can now override the pickling logic of functions and classes by defining the
9201030special :meth: `~pickle.Pickler.reducer_override ` method.
@@ -929,6 +1039,32 @@ NSKeyedArchiver-encoded binary plists.
9291039(Contributed by Jon Janzen in :issue: `26707 `.)
9301040
9311041
1042+ pprint
1043+ ------
1044+
1045+ The :mod: `pprint ` module added a *sort_dicts * parameter to several functions.
1046+ By default, those functions continue to sort dictionaries before rendering or
1047+ printing. However, if *sort_dicts * is set to *False *, the dictionaries retain
1048+ the order that keys were inserted. This can be useful for comparison to JSON
1049+ inputs during debugging.
1050+
1051+ In addition, there is a convenience new function, :func: `pprint.pp ` that is
1052+ like :func: `pprint.pprint ` but with *sort_dicts * defaulting to *False *::
1053+
1054+ >>> from pprint import pprint, pp
1055+ >>> d = dict(source='input.txt', operation='filter', destination='output.txt')
1056+ >>> pp(d, width=40) # Original order
1057+ {'source': 'input.txt',
1058+ 'operation': 'filter',
1059+ 'destination': 'output.txt'}
1060+ >>> pprint(d, width=40) # Keys sorted alphabetically
1061+ {'destination': 'output.txt',
1062+ 'operation': 'filter',
1063+ 'source': 'input.txt'}
1064+
1065+ (Contributed by Rémi Lapeyre in :issue: `30670 `.)
1066+
1067+
9321068py_compile
9331069----------
9341070
@@ -975,8 +1111,8 @@ The :func:`socket.if_nameindex()`, :func:`socket.if_nametoindex()`, and
9751111ssl
9761112---
9771113
978- Added :attr: `ssl.SSLContext.post_handshake_auth ` to enable and
979- :meth: `ssl.SSLSocket.verify_client_post_handshake ` to initiate TLS 1.3
1114+ Added :attr: `~ ssl.SSLContext.post_handshake_auth ` to enable and
1115+ :meth: `~ ssl.SSLSocket.verify_client_post_handshake ` to initiate TLS 1.3
9801116post-handshake authentication.
9811117(Contributed by Christian Heimes in :issue: `34670 `.)
9821118
@@ -1154,8 +1290,9 @@ the string. (Contributed by Max Belanger, David Euresti, and Greg Price in
11541290unittest
11551291--------
11561292
1157- Added :class: `AsyncMock ` to support an asynchronous version of :class: `Mock `.
1158- Appropriate new assert functions for testing have been added as well.
1293+ Added :class: `~unittest.mock.AsyncMock ` to support an asynchronous version of
1294+ :class: `~unittest.mock.Mock `. Appropriate new assert functions for testing
1295+ have been added as well.
11591296(Contributed by Lisa Roach in :issue: `26467 `).
11601297
11611298Added :func: `~unittest.addModuleCleanup() ` and
@@ -1235,6 +1372,16 @@ them in the generated tree.
12351372(Contributed by Stefan Behnel in :issue: `36676 ` and :issue: `36673 `.)
12361373
12371374
1375+ xmlrpc
1376+ ------
1377+
1378+ :class: `xmlrpc.client.ServerProxy ` now supports an optional *headers * keyword
1379+ argument for a sequence of HTTP headers to be sent with each request. Among
1380+ other things, this makes it possible to upgrade from default basic
1381+ authentication to faster session authentication.
1382+ (Contributed by Cédric Krier in :issue: `35153 `.)
1383+
1384+
12381385Optimizations
12391386=============
12401387
@@ -1458,6 +1605,11 @@ Deprecated
14581605 constant nodes.
14591606 (Contributed by Serhiy Storchaka in :issue: `36917 `.)
14601607
1608+ * The :func: `asyncio.coroutine ` :term: `decorator ` is deprecated and will be
1609+ removed in version 3.10. Instead of ``@asyncio.coroutine ``, use
1610+ :keyword: `async def ` instead.
1611+ (Contributed by Andrew Svetlov in :issue: `36921 `.)
1612+
14611613* The following functions and methods are deprecated in the :mod: `gettext `
14621614 module: :func: `~gettext.lgettext `, :func: `~gettext.ldgettext `,
14631615 :func: `~gettext.lngettext ` and :func: `~gettext.ldngettext `.
@@ -1504,7 +1656,7 @@ Deprecated
15041656 :class: `multiprocessing.managers.SharedMemoryServer `.
15051657 - *obj * in :func: `weakref.finalize `.
15061658
1507- In future releases of Python they will be :ref: `positional-only
1659+ In future releases of Python, they will be :ref: `positional-only
15081660 <positional-only_parameter>`.
15091661 (Contributed by Serhiy Storchaka in :issue: `36492 `.)
15101662
@@ -1514,6 +1666,11 @@ API and Feature Removals
15141666
15151667The following features and APIs have been removed from Python 3.8:
15161668
1669+ * Starting with Python 3.3, importing ABCs from :mod: `collections ` was
1670+ deprecated, and importing should be done from :mod: `collections.abc `. Being
1671+ able to import from collections was marked for removal in 3.8, but has been
1672+ delayed to 3.9. (See :issue: `36952 `.)
1673+
15171674* The :mod: `macpath ` module, deprecated in Python 3.7, has been removed.
15181675 (Contributed by Victor Stinner in :issue: `35471 `.)
15191676
@@ -1632,7 +1789,7 @@ Changes in the Python API
16321789 (Contributed by Eric Snow in :issue: `34651 `, modified by Christian Heimes
16331790 in :issue: `37951 `.)
16341791
1635- * The :meth: `imap.IMAP4.logout ` method no longer ignores silently arbitrary
1792+ * The :meth: `imap.IMAP4.logout ` method no longer silently ignores arbitrary
16361793 exceptions.
16371794 (Contributed by Victor Stinner in :issue: `36348 `.)
16381795
@@ -1687,7 +1844,7 @@ Changes in the Python API
16871844* The ``PyGC_Head `` struct has changed completely. All code that touched the
16881845 struct member should be rewritten. (See :issue: `33597 `.)
16891846
1690- * The `` PyInterpreterState ` ` struct has been moved into the "internal"
1847+ * The :c:type: ` PyInterpreterState ` struct has been moved into the "internal"
16911848 header files (specifically Include/internal/pycore_pystate.h). An
16921849 opaque ``PyInterpreterState `` is still available as part of the public
16931850 API (and stable ABI). The docs indicate that none of the struct's
0 commit comments