@@ -357,8 +357,8 @@ It is meant to formalize existing optimizations which were already done
357
357
for various classes.
358
358
Any extension type implementing a callable can use this protocol.
359
359
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.
362
362
363
363
See :pep: `590 ` for a full description.
364
364
@@ -447,7 +447,7 @@ Other Language Changes
447
447
an instance of the subclass, rather than the base class. This also affects
448
448
the return type of operations whose implementation (directly or indirectly)
449
449
uses :class: `datetime.timedelta ` arithmetic, such as
450
- :meth: `datetime.datetime.astimezone `.
450
+ :meth: `~ datetime.datetime.astimezone `.
451
451
(Contributed by Paul Ganssle in :issue: `32417 `.)
452
452
453
453
* When the Python interpreter is interrupted by Ctrl-C (SIGINT) and the
@@ -531,6 +531,13 @@ Other Language Changes
531
531
532
532
(Contributed by Jörn Heissler in :issue: `35224 `.)
533
533
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 `.)
534
541
535
542
New Modules
536
543
===========
@@ -581,8 +588,8 @@ The :func:`ast.parse` function has some new flags:
581
588
comments" (returned for function definition AST nodes);
582
589
583
590
* ``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.
586
593
587
594
(Contributed by Guido van Rossum in :issue: `35766 `.)
588
595
@@ -632,14 +639,39 @@ marked with the ``CO_COROUTINE`` flag may then be returned.
632
639
collections
633
640
-----------
634
641
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()) ``.
640
648
(Contributed by Raymond Hettinger in :issue: `35864 `.)
641
649
642
650
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
+
643
675
curses
644
676
-------
645
677
@@ -702,6 +734,30 @@ cached for the life of the instance. ::
702
734
(Contributed by Carl Meyer in :issue: `21145 `)
703
735
704
736
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
+
705
761
gc
706
762
--
707
763
@@ -729,7 +785,7 @@ for certain types of invalid or corrupt gzip files.
729
785
:issue: `6584 `.)
730
786
731
787
732
- idlelib and IDLE
788
+ IDLE and idlelib
733
789
----------------
734
790
735
791
Output 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
745
801
suppress the normal Shell main module restart. (Contributed by Cheryl
746
802
Sabella, Terry Jan Reedy, and others in :issue: `5680 ` and :issue: `37627 `.)
747
803
748
- Add optional line numbers for IDLE editor windows. Windows
804
+ Added optional line numbers for IDLE editor windows. Windows
749
805
open without line numbers unless set otherwise in the General
750
806
tab of the configuration dialog. Line numbers for an existing
751
807
window are shown and hidden in the Options menu.
752
808
(Contributed by Tal Einat and Saimadhav Heblikar in :issue: `17535 `.)
753
809
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
+
754
817
The changes above have been backported to 3.7 maintenance releases.
755
818
756
819
@@ -781,13 +844,44 @@ fails. The exception is ignored silently by default in release build.
781
844
(Contributed by Victor Stinner in :issue: `18748 `.)
782
845
783
846
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
+
784
860
json.tool
785
861
---------
786
862
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.
788
864
(Contributed by Weipeng Hong in :issue: `31553 `.)
789
865
790
866
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
+
791
885
math
792
886
----
793
887
@@ -809,7 +903,28 @@ numbers::
809
903
810
904
(Contributed by Pablo Galindo in :issue: `35606 `.)
811
905
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
+
813
928
(Contributed by Mark Dickinson in :issue: `36887 `.)
814
929
815
930
The function :func: `math.factorial ` no longer accepts arguments that are not
@@ -910,11 +1025,6 @@ to a path.
910
1025
pickle
911
1026
------
912
1027
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
-
918
1028
:mod: `pickle ` extensions subclassing the C-optimized :class: `~pickle.Pickler `
919
1029
can now override the pickling logic of functions and classes by defining the
920
1030
special :meth: `~pickle.Pickler.reducer_override ` method.
@@ -929,6 +1039,32 @@ NSKeyedArchiver-encoded binary plists.
929
1039
(Contributed by Jon Janzen in :issue: `26707 `.)
930
1040
931
1041
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
+
932
1068
py_compile
933
1069
----------
934
1070
@@ -975,8 +1111,8 @@ The :func:`socket.if_nameindex()`, :func:`socket.if_nametoindex()`, and
975
1111
ssl
976
1112
---
977
1113
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
980
1116
post-handshake authentication.
981
1117
(Contributed by Christian Heimes in :issue: `34670 `.)
982
1118
@@ -1154,8 +1290,9 @@ the string. (Contributed by Max Belanger, David Euresti, and Greg Price in
1154
1290
unittest
1155
1291
--------
1156
1292
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.
1159
1296
(Contributed by Lisa Roach in :issue: `26467 `).
1160
1297
1161
1298
Added :func: `~unittest.addModuleCleanup() ` and
@@ -1235,6 +1372,16 @@ them in the generated tree.
1235
1372
(Contributed by Stefan Behnel in :issue: `36676 ` and :issue: `36673 `.)
1236
1373
1237
1374
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
+
1238
1385
Optimizations
1239
1386
=============
1240
1387
@@ -1458,6 +1605,11 @@ Deprecated
1458
1605
constant nodes.
1459
1606
(Contributed by Serhiy Storchaka in :issue: `36917 `.)
1460
1607
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
+
1461
1613
* The following functions and methods are deprecated in the :mod: `gettext `
1462
1614
module: :func: `~gettext.lgettext `, :func: `~gettext.ldgettext `,
1463
1615
:func: `~gettext.lngettext ` and :func: `~gettext.ldngettext `.
@@ -1504,7 +1656,7 @@ Deprecated
1504
1656
:class: `multiprocessing.managers.SharedMemoryServer `.
1505
1657
- *obj * in :func: `weakref.finalize `.
1506
1658
1507
- In future releases of Python they will be :ref: `positional-only
1659
+ In future releases of Python, they will be :ref: `positional-only
1508
1660
<positional-only_parameter>`.
1509
1661
(Contributed by Serhiy Storchaka in :issue: `36492 `.)
1510
1662
@@ -1514,6 +1666,11 @@ API and Feature Removals
1514
1666
1515
1667
The following features and APIs have been removed from Python 3.8:
1516
1668
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
+
1517
1674
* The :mod: `macpath ` module, deprecated in Python 3.7, has been removed.
1518
1675
(Contributed by Victor Stinner in :issue: `35471 `.)
1519
1676
@@ -1632,7 +1789,7 @@ Changes in the Python API
1632
1789
(Contributed by Eric Snow in :issue: `34651 `, modified by Christian Heimes
1633
1790
in :issue: `37951 `.)
1634
1791
1635
- * The :meth: `imap.IMAP4.logout ` method no longer ignores silently arbitrary
1792
+ * The :meth: `imap.IMAP4.logout ` method no longer silently ignores arbitrary
1636
1793
exceptions.
1637
1794
(Contributed by Victor Stinner in :issue: `36348 `.)
1638
1795
@@ -1687,7 +1844,7 @@ Changes in the Python API
1687
1844
* The ``PyGC_Head `` struct has changed completely. All code that touched the
1688
1845
struct member should be rewritten. (See :issue: `33597 `.)
1689
1846
1690
- * The `` PyInterpreterState ` ` struct has been moved into the "internal"
1847
+ * The :c:type: ` PyInterpreterState ` struct has been moved into the "internal"
1691
1848
header files (specifically Include/internal/pycore_pystate.h). An
1692
1849
opaque ``PyInterpreterState `` is still available as part of the public
1693
1850
API (and stable ABI). The docs indicate that none of the struct's
0 commit comments