From 43b965d3d274f269576d880f1332c94463481ccf Mon Sep 17 00:00:00 2001 From: Elvis Pranskevichus Date: Thu, 10 Nov 2016 13:19:32 -0500 Subject: [PATCH 2/2] Issue #28635: What's New in Python 3.6 updates --- Doc/whatsnew/3.6.rst | 1071 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 851 insertions(+), 220 deletions(-) diff --git a/Doc/whatsnew/3.6.rst b/Doc/whatsnew/3.6.rst index 2337823..3b58e9e 100644 --- a/Doc/whatsnew/3.6.rst +++ b/Doc/whatsnew/3.6.rst @@ -87,7 +87,7 @@ CPython implementation improvements: * The :ref:`dict ` type has been reimplemented to use a :ref:`faster, more compact representation ` - similar to the `PyPy dict implementation`_. This resulted in dictionaries + similar to the `PyPy dict implementation`_. This resulted in dictionaries using 20% to 25% less memory when compared to Python 3.5. * Customization of class creation has been simplified with the @@ -96,27 +96,49 @@ CPython implementation improvements: * The class attibute definition order is :ref:`now preserved `. -* The order of elements in ``**kwargs`` now corresponds to the order in - the function signature: - :ref:`Preserving Keyword Argument Order `. +* The order of elements in ``**kwargs`` now + :ref:`corresponds to the order ` in which keyword + arguments were passed to the function. -* DTrace and SystemTap :ref:`probing support `. +* DTrace and SystemTap :ref:`probing support ` has + been added. + +* The new :ref:`PYTHONMALLOC ` environment variable + can now be used to debug the interpreter memory allocation and access + errors. Significant improvements in the standard library: +* The :mod:`asyncio` module has received new features, significant + usability and performance improvements, and a fair amount of bug fixes. + Starting with Python 3.6 the ``asyncio`` module is no longer provisional + and its API is considered stable. + * A new :ref:`file system path protocol ` has been implemented to support :term:`path-like objects `. All standard library functions operating on paths have been updated to work with the new protocol. -* The overhead of :mod:`asyncio` implementation has been reduced by - up to 50% thanks to the new C implementation of the :class:`asyncio.Future` - and :class:`asyncio.Task` classes and other optimizations. +* The :mod:`datetime` module has gained support for + :ref:`Local Time Disambiguation `. + +* The :mod:`typing` module received a number of + :ref:`improvements ` and is no longer provisional. + +* The :mod:`tracemalloc` module has been significantly reworked + and is now used to provide better output for :exc:`ResourceWarning`s + as well as provide better diagnostics for memory allocation errors. + See the :ref:`PYTHONMALLOC section ` for more + information. Security improvements: +* The new :mod:`secrets` module has been added to simplify the generation of + cryptographically strong pseudo-random numbers suitable for + managing secrets such as account authentication, tokens, and similar. + * On Linux, :func:`os.urandom` now blocks until the system urandom entropy pool is initialized to increase the security. See the :pep:`524` for the rationale. @@ -153,26 +175,6 @@ Windows improvements: more information. -A complete list of PEP's implemented in Python 3.6: - -* :pep:`468`, :ref:`Preserving Keyword Argument Order ` -* :pep:`487`, :ref:`Simpler customization of class creation ` -* :pep:`495`, Local Time Disambiguation -* :pep:`498`, :ref:`Formatted string literals ` -* :pep:`506`, Adding A Secrets Module To The Standard Library -* :pep:`509`, :ref:`Add a private version to dict ` -* :pep:`515`, :ref:`Underscores in Numeric Literals ` -* :pep:`519`, :ref:`Adding a file system path protocol ` -* :pep:`520`, :ref:`Preserving Class Attribute Definition Order ` -* :pep:`523`, :ref:`Adding a frame evaluation API to CPython ` -* :pep:`524`, Make os.urandom() blocking on Linux (during system startup) -* :pep:`525`, Asynchronous Generators (provisional) -* :pep:`526`, :ref:`Syntax for Variable Annotations (provisional) ` -* :pep:`528`, :ref:`Change Windows console encoding to UTF-8 (provisional) ` -* :pep:`529`, :ref:`Change Windows filesystem encoding to UTF-8 (provisional) ` -* :pep:`530`, Asynchronous Comprehensions - - .. _PyPy dict implementation: https://morepypy.blogspot.com/2015/01/faster-more-memory-efficient-and-more.html @@ -185,7 +187,7 @@ PEP 498: Formatted string literals ---------------------------------- :pep:`498` introduces a new kind of string literals: *f-strings*, or -*formatted string literals*. +:ref:`formatted string literals `. Formatted string literals are prefixed with ``'f'`` and are similar to the format strings accepted by :meth:`str.format`. They contain replacement @@ -196,6 +198,11 @@ which are evaluated at run time, and then formatted using the >>> name = "Fred" >>> f"He said his name is {name}." 'He said his name is Fred.' + >>> width = 10 + >>> precision = 4 + >>> value = decimal.Decimal("12.34567") + >>> f"result: {value:{width}.{precision}}" # nested fields + 'result: 12.35' .. seealso:: @@ -258,6 +265,18 @@ Single underscores are allowed between digits and after any base specifier. Leading, trailing, or multiple underscores in a row are not allowed. +The :ref:`string formatting ` language also now has support +for the ``'_'`` option to signal the use of an underscore for a thousands +separator for floating point presentation types and for integer +presentation type ``'d'``. For integer presentation types ``'b'``, +``'o'``, ``'x'``, and ``'X'``, underscores will be inserted every 4 +digits:: + + >>> '{:_}'.format(1000000) + '1_000_000' + >>> '{:_x}'.format(0xFFFFFFFF) + 'ffff_ffff' + .. seealso:: :pep:`515` -- Underscores in Numeric Literals @@ -302,7 +321,7 @@ comprehensions and generator expressions:: Additionally, ``await`` expressions are supported in all kinds of comprehensions:: - result = [await fun() for fun in funcs] + result = [await fun() for fun in funcs if await condition()] .. seealso:: @@ -319,17 +338,18 @@ It is now possible to customize subclass creation without using a metaclass. The new ``__init_subclass__`` classmethod will be called on the base class whenever a new subclass is created:: - >>> class QuestBase: - ... # this is implicitly a @classmethod - ... def __init_subclass__(cls, swallow, **kwargs): - ... cls.swallow = swallow - ... super().__init_subclass__(**kwargs) + class PluginBase: + subclasses = [] - >>> class Quest(QuestBase, swallow="african"): - ... pass + def __init_subclass__(cls, **kwargs): + super().__init_subclass__(**kwargs) + cls.subclasses.append(cls) - >>> Quest.swallow - 'african' + class Plugin1(PluginBase): + pass + + class Plugin2(PluginBase): + pass .. seealso:: @@ -345,31 +365,36 @@ PEP 487: Descriptor Protocol Enhancements ----------------------------------------- :pep:`487` extends the descriptor protocol has to include the new optional -``__set_name__`` method. Whenever a new class is defined, the new method -will be called on all descriptors included in the definition, providing +:meth:`~object.__set_name__` method. Whenever a new class is defined, the new +method will be called on all descriptors included in the definition, providing them with a reference to the class being defined and the name given to the -descriptor within the class namespace. - -.. seealso:: +descriptor within the class namespace. In other words, instances of +descriptors can now know the attribute name of the descriptor in the +owner class:: - :pep:`487` -- Simpler customization of class creation - PEP written and implemented by Martin Teichmann. + class IntField: + def __get__(self, instance, owner): + return instance.__dict__[self.name] - :ref:`Feature documentation ` - - -.. _whatsnew36-pep506: + def __set__(self, instance, value): + if not isinstance(value, int): + raise ValueError(f'expecting integer in {self.name}') + instance.__dict__[self.name] = value -PEP 506: Adding A Secrets Module To The Standard Library --------------------------------------------------------- + # this is the new initializer: + def __set_name__(self, owner, name): + self.name = name + class Model: + int_field = IntField() .. seealso:: - :pep:`506` -- Adding A Secrets Module To The Standard Library - PEP written and implemented by Steven D'Aprano. + :pep:`487` -- Simpler customization of class creation + PEP written and implemented by Martin Teichmann. + :ref:`Feature documentation ` .. _whatsnew36-pep519: @@ -401,9 +426,8 @@ object. The built-in :func:`open` function has been updated to accept :class:`os.PathLike` objects as have all relevant functions in the -:mod:`os` and :mod:`os.path` modules. :c:func:`PyUnicode_FSConverter` -and :c:func:`PyUnicode_FSConverter` have been changed to accept -path-like objects. The :class:`os.DirEntry` class +:mod:`os` and :mod:`os.path` modules, as well as most functions and +classes in the standard library. The :class:`os.DirEntry` class and relevant classes in :mod:`pathlib` have also been updated to implement :class:`os.PathLike`. @@ -439,6 +463,43 @@ pre-existing code:: PEP written by Brett Cannon and Koos Zevenhoven. +.. _whatsnew36-pep495: + +PEP 495: Local Time Disambiguation +---------------------------------- + +In most world locations, there have been and will be times when local clocks +are moved back. In those times, intervals are introduced in which local +clocks show the same time twice in the same day. In these situations, the +information displayed on a local clock (or stored in a Python datetime +instance) is insufficient to identify a particular moment in time. + +:pep:`495` adds the new *fold* attribute to instances of +:class:`datetime.datetime` and :class:`datetime.time` classes to differentiate +between two moments in time for which local times are the same:: + + >>> u0 = datetime(2016, 11, 6, 4, tzinfo=timezone.utc) + >>> for i in range(4): + ... u = u0 + i*HOUR + ... t = u.astimezone(Eastern) + ... print(u.time(), 'UTC =', t.time(), t.tzname(), t.fold) + ... + 04:00:00 UTC = 00:00:00 EDT 0 + 05:00:00 UTC = 01:00:00 EDT 0 + 06:00:00 UTC = 01:00:00 EST 1 + 07:00:00 UTC = 02:00:00 EST 0 + +The values of the :attr:`fold ` attribute have the +value `0` all instances except those that represent the second +(chronologically) moment in time in an ambiguous case. + +.. seealso:: + + :pep:`495` -- Local Time Disambiguation + PEP written by Alexander Belopolsky and Tim Peters, implementation + by Alexander Belopolsky. + + .. _whatsnew36-pep529: PEP 529: Change Windows filesystem encoding to UTF-8 @@ -489,10 +550,11 @@ PEP 520: Preserving Class Attribute Definition Order Attributes in a class definition body have a natural ordering: the same order in which the names appear in the source. This order is now -preserved in the new class's ``__dict__`` attribute. +preserved in the new class's :attr:`~object.__dict__` attribute. Also, the effective default class *execution* namespace (returned from -``type.__prepare__()``) is now an insertion-order-preserving mapping. +:ref:`type.__prepare__() `) is now an insertion-order-preserving +mapping. .. seealso:: @@ -523,16 +585,16 @@ The :ref:`dict ` type now uses a "compact" representation `pioneered by PyPy `_. The memory usage of the new :func:`dict` is between 20% and 25% smaller compared to Python 3.5. -:pep:`468` (Preserving the order of ``**kwargs`` in a function.) is -implemented by this. The order-preserving aspect of this new -implementation is considered an implementation detail and should -not be relied upon (this may change in the future, but it is desired -to have this new dict implementation in the language for a few -releases before changing the language spec to mandate + +The order-preserving aspect of this new implementation is considered an +implementation detail and should not be relied upon (this may change in +the future, but it is desired to have this new dict implementation in +the language for a few releases before changing the language spec to mandate order-preserving semantics for all current and future Python implementations; this also helps preserve backwards-compatibility with older versions of the language where random iteration order is still in effect, e.g. Python 3.5). + (Contributed by INADA Naoki in :issue:`27350`. Idea `originally suggested by Raymond Hettinger `_.) @@ -545,7 +607,7 @@ PEP 523: Adding a frame evaluation API to CPython While Python provides extensive support to customize how code executes, one place it has not done so is in the evaluation of frame -objects. If you wanted some way to intercept frame evaluation in +objects. If you wanted some way to intercept frame evaluation in Python there really wasn't any way without directly manipulating function pointers for defined functions. @@ -567,17 +629,7 @@ API will change with Python as necessary. PEP written by Brett Cannon and Dino Viehland. -.. _whatsnew36-pep509: - -PEP 509: Add a private version to dict --------------------------------------- - -Add a new private version to the builtin ``dict`` type, incremented at -each dictionary creation and at each dictionary change, to implement -fast guards on namespaces. - -(Contributed by Victor Stinner in :issue:`26058`.) - +.. _whatsnew36-pythonmalloc: PYTHONMALLOC environment variable --------------------------------- @@ -691,34 +743,77 @@ Some smaller changes made to the core Python language are: * Long sequences of repeated traceback lines are now abbreviated as ``"[Previous line repeated {count} more times]"`` (see - :ref:`py36-traceback` for an example). + :ref:`whatsnew36-traceback` for an example). (Contributed by Emanuel Barry in :issue:`26823`.) * Import now raises the new exception :exc:`ModuleNotFoundError` (subclass of :exc:`ImportError`) when it cannot find a module. Code that current checks for ImportError (in try-except) will still work. + (Contributed by Eric Snow in :issue:`15767`.) + +* Class methods relying on zero-argument ``super()`` will now work correctly + when called from metaclass methods during class creation. + (Contributed by Martin Teichmann in :issue:`23722`.) New Modules =========== +.. _whatsnew36-pep506: + secrets ------- -The new :mod:`secrets` module. +The main purpose of the new :mod:`secrets` module is to provide an obvious way +to reliably generate cryptographically strong pseudo-random values suitable +for managing secrets, such as account authentication, tokens, and similar. + +.. warning:: + + Note that the pseudo-random generators in the :mod:`random` module + should *NOT* be used for security purposes. Use :mod:`secrets` + on Python 3.6+ and :func:`os.urandom()` on Python 3.5 and earlier. + +.. seealso:: + + :pep:`506` -- Adding A Secrets Module To The Standard Library + PEP written and implemented by Steven D'Aprano. Improved Modules ================ +array +----- + +Exhausted iterators of :class:`array.array` will now stay exhausted even +if the iterated array is extended. This is consistent with the behavior +of other mutable sequences. + +Contributed by Serhiy Storchaka in :issue:`26492`. + +ast +--- + +The new :class:`ast.Constant` AST node has been added. It can be used +by external AST optimizers for the purposes of constant folding. + +Contributed by Victor Stinner in :issue:`26146`. + + asyncio ------- -Since the :mod:`asyncio` module is :term:`provisional `, -all changes introduced in Python 3.6 have also been backported to Python -3.5.x. +Starting with Python 3.6 the ``asyncio`` is no longer provisional and its +API is considered stable. + +Notable changes in the :mod:`asyncio` module since Python 3.5.0 +(all backported to 3.5.x due to the provisional status): -Notable changes in the :mod:`asyncio` module since Python 3.5.0: +* The :func:`~asyncio.get_event_loop` function has been changed to + always return the currently running loop when called from couroutines + and callbacks. + (Contributed by Yury Selivanov in :issue:`28613`.) * The :func:`~asyncio.ensure_future` function and all functions that use it, such as :meth:`loop.run_until_complete() `, @@ -742,54 +837,165 @@ Notable changes in the :mod:`asyncio` module since Python 3.5.0: loop implementations, such as `uvloop `_, to provide a faster :class:`asyncio.Future` implementation. - (Contributed by Yury Selivanov.) + (Contributed by Yury Selivanov in :issue:`27041`.) * New :meth:`loop.get_exception_handler() ` method to get the current exception handler. - (Contributed by Yury Selivanov.) + (Contributed by Yury Selivanov in :issue:`27040`.) * New :meth:`StreamReader.readuntil() ` method to read data from the stream until a separator bytes sequence appears. (Contributed by Mark Korenberg.) +* The performance of :meth:`StreamReader.readexactly() ` + has been improved. + (Contributed by Mark Korenberg in :issue:`28370`.) + * The :meth:`loop.getaddrinfo() ` method is optimized to avoid calling the system ``getaddrinfo`` function if the address is already resolved. (Contributed by A. Jesse Jiryu Davis.) +* The :meth:`BaseEventLoop.stop() ` + method has been changed to stop the loop immediately after + the current iteration. Any new callbacks scheduled as a result + of the last iteration will be discarded. + (Contributed by Guido van Rossum in :issue:`25593`.) + +* :meth:`Future.set_exception ` + will now raise :exc:`TypeError` when passed an instance of + :exc:`StopIteration` exception. + (Contributed by Chris Angelico in :issue:`26221`.) + +* New :meth:`Loop.connect_accepted_socket() ` + method to be used by servers that accept connections outside of asyncio, + but that use asyncio to handle them. + (Contributed by Jim Fulton in :issue:`27392`.) + + +base64 +------ + +The :func:`~base64.a85decode` function no longer requires the leading +``'<~'`` characters in input when the *adobe* argument is set. +(Contributed by Swati Jaiswal in :issue:`25913`.) + + +binascii +-------- + +The :func:`~binascii.b2a_base64` function now accepts an optional *newline* +keyword argument to control whether the newline character is appended to the +return value. +(Contributed by Victor Stinner in :issue:`25357`.) + + +cmath +----- + +The new :const:`cmath.tau` (τ) constant has been added. +(Contributed by Lisa Roach in :issue:`12345`, see :pep:`628` for details.) + +New constants: :const:`cmath.inf` and :const:`cmath.nan` to +match :const:`math.inf` and :const:`math.nan`, and also :const:`cmath.infj` +and :const:`cmath.nanj` to match the format used by complex repr. +(Contributed by Mark Dickinson in :issue:`23229`.) + + +collections +----------- + +The new :class:`~collections.Collection` abstract base class has been +added to represent sized iterable container classes. + +The :func:`~collections.namedtuple` function now accepts an optional +keyword argument *module*, which, when specified, is used for +the ``__module__`` attribute of the returned named tuple class. +(Contributed by Raymond Hettinger in :issue:`17941`.) + +The *verbose* and *rename* arguments for +:func:`~collections.namedtuple` are now keyword-only. +(Contributed by Raymond Hettinger in :issue:`25628`.) + +Recursive :class:`collections.deque` instances can now be pickled. +(Contributed by Serhiy Storchaka in :issue:`26482`.) + + +concurrent.futures +------------------ + +The :class:`ThreadPoolExecutor ` section for more +information. +(Contributed by Alexander Belopolsky in :issue:`24773`.) + The :meth:`datetime.strftime() ` and -:meth:`date.strftime() ` methods now support ISO 8601 date -directives ``%G``, ``%u`` and ``%V``. +:meth:`date.strftime() ` methods now support +ISO 8601 date directives ``%G``, ``%u`` and ``%V``. (Contributed by Ashley Anderson in :issue:`12006`.) +The :func:`datetime.isoformat() ` function +now accepts an optional *timespec* argument that specifies the number +of additional components of the time value to include. +(Contributed by Alessandro Cucci and Alexander Belopolsky in :issue:`19475`.) + +The :meth:`datetime.combine() ` now +accepts an optional *tzinfo* argument. +(Contributed by Alexander Belopolsky in :issue:`27661`.) + + +decimal +------- + +New :meth:`Decimal.as_integer_ratio() ` +method that returns a pair ``(n, d)`` of integers that represent the given +:class:`~decimal.Decimal` instance as a fraction, in lowest terms and +with a positive denominator:: + + >>> Decimal('-3.14').as_integer_ratio() + (-157, 50) -distutils.command.sdist ------------------------ +(Contributed by Stefan Krah amd Mark Dickinson in :issue:`25928`.) + + +dis +--- + +Disassembling a class now disassembles class and static +methods. (Contributed by Xiang Zhang in :issue:`26733`.) + +The disassembler now decodes ``FORMAT_VALUE`` argument. +(Contributed by Serhiy Storchaka in :issue:`28317`.) + + +distutils +--------- The ``default_format`` attribute has been removed from :class:`distutils.command.sdist.sdist` and the ``formats`` @@ -825,6 +1031,31 @@ encodings On Windows, added the ``'oem'`` encoding to use ``CP_OEMCP`` and the ``'ansi'`` alias for the existing ``'mbcs'`` encoding, which uses the ``CP_ACP`` code page. +(Contributed by Steve Dower in :issue:`27959`.) + + +enum +---- + +Two new enumeration base classes have been added to the :mod:`enum` module: +:class:`~enum.Flag` and :class:`~enum.IntFlags`. Both are used to define +constants that can be combined using the bitwise operators. +(Contributed by Ethan Furman in :issue:`23591`.) + +Many standard library modules have been updated to use the +:class:`~enum.IntFlags` class for their constants. + +The new :class:`enum.auto` value can be used to assign values to enum +members automatically:: + + >>> from enum import Enum, auto + >>> class Color(Enum): + ... red = auto() + ... blue = auto() + ... green = auto() + ... + >>> list(Color) + [, , ] faulthandler @@ -835,12 +1066,17 @@ exceptions: see :func:`faulthandler.enable`. (Contributed by Victor Stinner in :issue:`23848`.) +fileinput +--------- + +:func:`~fileinput.hook_encoded` now supports the *errors* argument. +(Contributed by Joseph Hackman in :issue:`25788`.) + + hashlib ------- -:mod:`hashlib` supports OpenSSL 1.1.0. The minimum recommend version is 1.0.2. -It has been tested with 0.9.8zc, 0.9.8zh and 1.0.1t as well as LibreSSL 2.3 -and 2.4. +:mod:`hashlib` supports OpenSSL 1.1.0. The minimum recommend version is 1.0.2. (Contributed by Christian Heimes in :issue:`26470`.) BLAKE2 hash functions were added to the module. :func:`~hashlib.blake2b` @@ -872,16 +1108,35 @@ chunked encoding request bodies. idlelib and IDLE ---------------- -The idlelib package is being modernized and refactored to make IDLE look and work better and to make the code easier to understand, test, and improve. Part of making IDLE look better, especially on Linux and Mac, is using ttk widgets, mostly in the dialogs. As a result, IDLE no longer runs with tcl/tk 8.4. It now requires tcl/tk 8.5 or 8.6. We recommend running the latest release of either. +The idlelib package is being modernized and refactored to make IDLE look and +work better and to make the code easier to understand, test, and improve. Part +of making IDLE look better, especially on Linux and Mac, is using ttk widgets, +mostly in the dialogs. As a result, IDLE no longer runs with tcl/tk 8.4. It +now requires tcl/tk 8.5 or 8.6. We recommend running the latest release of +either. -'Modernizing' includes renaming and consolidation of idlelib modules. The renaming of files with partial uppercase names is similar to the renaming of, for instance, Tkinter and TkFont to tkinter and tkinter.font in 3.0. As a result, imports of idlelib files that worked in 3.5 will usually not work in 3.6. At least a module name change will be needed (see idlelib/README.txt), sometimes more. (Name changes contributed by Al Swiegart and Terry Reedy in :issue:`24225`. Most idlelib patches since have been and will be part of the process.) +'Modernizing' includes renaming and consolidation of idlelib modules. The +renaming of files with partial uppercase names is similar to the renaming of, +for instance, Tkinter and TkFont to tkinter and tkinter.font in 3.0. As a +result, imports of idlelib files that worked in 3.5 will usually not work in +3.6. At least a module name change will be needed (see idlelib/README.txt), +sometimes more. (Name changes contributed by Al Swiegart and Terry Reedy in +:issue:`24225`. Most idlelib patches since have been and will be part of the +process.) -In compensation, the eventual result with be that some idlelib classes will be easier to use, with better APIs and docstrings explaining them. Additional useful information will be added to idlelib when available. +In compensation, the eventual result with be that some idlelib classes will be +easier to use, with better APIs and docstrings explaining them. Additional +useful information will be added to idlelib when available. importlib --------- +Import now raises the new exception :exc:`ModuleNotFoundError` +(subclass of :exc:`ImportError`) when it cannot find a module. Code +that current checks for ``ImportError`` (in try-except) will still work. +(Contributed by Eric Snow in :issue:`15767`.) + :class:`importlib.util.LazyLoader` now calls :meth:`~importlib.abc.Loader.create_module` on the wrapped loader, removing the restriction that :class:`importlib.machinery.BuiltinImporter` and @@ -894,6 +1149,15 @@ restriction that :class:`importlib.machinery.BuiltinImporter` and :term:`path-like object`. +inspect +------- + +The :func:`inspect.signature() ` function now reports the +implicit ``.0`` parameters generated by the compiler for comprehension and +generator expression scopes as if they were positional-only parameters called +``implicit0``. (Contributed by Jelle Zijlstra in :issue:`19611`.) + + json ---- @@ -902,9 +1166,38 @@ JSON should be represented using either UTF-8, UTF-16, or UTF-32. (Contributed by Serhiy Storchaka in :issue:`17909`.) +logging +------- + +The new :meth:`WatchedFileHandler.reopenIfNeeded() ` +method has been added to add the ability to check if the log file needs to +be reopened. +(Contributed by Marian Horban in :issue:`24884`.) + + +math +---- + +The tau (τ) constant has been added to the :mod:`math` and :mod:`cmath` +modules. +(Contributed by Lisa Roach in :issue:`12345`, see :pep:`628` for details.) + + +multiprocessing +--------------- + +:ref:`Proxy Objects ` returned by +:func:`multiprocessing.Manager` can now be nested. +(Contributed by Davin Potts in :issue:`6766`.) + + os -- +See the summary for :ref:`PEP 519 ` for details on how the +:mod:`os` and :mod:`os.path` modules now support +:term:`path-like objects `. + A new :meth:`~os.scandir.close` method allows explicitly closing a :func:`~os.scandir` iterator. The :func:`~os.scandir` iterator now supports the :term:`context manager` protocol. If a :func:`scandir` @@ -919,9 +1212,21 @@ The Linux ``getrandom()`` syscall (get random bytes) is now exposed as the new :func:`os.getrandom` function. (Contributed by Victor Stinner, part of the :pep:`524`) -See the summary for :ref:`PEP 519 ` for details on how the -:mod:`os` and :mod:`os.path` modules now support -:term:`path-like objects `. + +pathlib +------- + +:mod:`pathlib` now supports :term:`path-like objects `. +(Contributed by Brett Cannon in :issue:`27186`.) + +See the summary for :ref:`PEP 519 ` for details. + + +pdb +--- + +The :class:`~pdb.Pdb` class constructor has a new optional *readrc* argument +to control whether ``.pdbrc`` files should be read. pickle @@ -933,6 +1238,34 @@ Protocol version 4 already supports this case. (Contributed by Serhiy Storchaka in :issue:`24164`.) +pickletools +----------- + +:func:`pickletools.dis()` now outputs implicit memo index for the +``MEMOIZE`` opcode. +(Contributed by Serhiy Storchaka in :issue:`25382`.) + + +pydoc +----- + +The :mod:`pydoc` module has learned to respect the ``MANPAGER`` +environment variable. +(Contributed by Matthias Klose in :issue:`8637`.) + +:func:`help` and :mod:`pydoc` can now list named tuple fields in the +order they were defined rather than alphabetically. +(Contributed by Raymond Hettinger in :issue:`24879`.) + + +random +------- + +The new :func:`~random.choices` function returns a list of elements of +specified size from the given population with optional weights. +(Contributed by Raymond Hettinger in :issue:`18844`.) + + re -- @@ -945,6 +1278,11 @@ Match object groups can be accessed by ``__getitem__``, which is equivalent to ``group()``. So ``mo['name']`` is now equivalent to ``mo.group('name')``. (Contributed by Eric Smith in :issue:`24454`.) +:class:`~re.Match` objects in the now support +:meth:`index-like objects ` as group +indices. +(Contributed by Jeroen Demeyer and Xiang Zhang in :issue:`27177`.) + readline -------- @@ -966,6 +1304,16 @@ Previously, names of properties and slots which were not yet created on an instance were excluded. (Contributed by Martin Panter in :issue:`25590`.) +shlex +----- + +The :class:`~shlex.shlex` has much +:ref:`improved shell compatibility ` +through the new *punctuation_chars* argument to control which characters +are treated as punctuation. +(Contributed by Vinay Sajip in :issue:`1521950`.) + + site ---- @@ -984,20 +1332,25 @@ sqlite3 socket ------ -The :func:`~socket.socket.ioctl` function now supports the :data:`~socket.SIO_LOOPBACK_FAST_PATH` -control code. +The :func:`~socket.socket.ioctl` function now supports the +:data:`~socket.SIO_LOOPBACK_FAST_PATH` control code. (Contributed by Daniel Stokes in :issue:`26536`.) The :meth:`~socket.socket.getsockopt` constants ``SO_DOMAIN``, ``SO_PROTOCOL``, ``SO_PEERSEC``, and ``SO_PASSSEC`` are now supported. (Contributed by Christian Heimes in :issue:`26907`.) +The :meth:`~socket.socket.setsockopt` now supports the +``setsockopt(level, optname, None, optlen: int)`` form. +(Contributed by Christian Heimes in issue:`27744`.) + The socket module now supports the address family :data:`~socket.AF_ALG` to interface with Linux Kernel crypto API. ``ALG_*``, ``SOL_ALG`` and :meth:`~socket.socket.sendmsg_afalg` were added. (Contributed by Christian Heimes in :issue:`27744` with support from Victor Stinner.) + socketserver ------------ @@ -1013,16 +1366,15 @@ the :class:`io.BufferedIOBase` writable interface. In particular, calling :meth:`~io.BufferedIOBase.write` is now guaranteed to send the data in full. (Contributed by Martin Panter in :issue:`26721`.) + ssl --- -:mod:`ssl` supports OpenSSL 1.1.0. The minimum recommend version is 1.0.2. -It has been tested with 0.9.8zc, 0.9.8zh and 1.0.1t as well as LibreSSL 2.3 -and 2.4. +:mod:`ssl` supports OpenSSL 1.1.0. The minimum recommend version is 1.0.2. (Contributed by Christian Heimes in :issue:`26470`.) 3DES has been removed from the default cipher suites and ChaCha20 Poly1305 -cipher suites are now in the right position. +cipher suites have been added. (Contributed by Christian Heimes in :issue:`27850` and :issue:`27766`.) :class:`~ssl.SSLContext` has better default configuration for options @@ -1030,11 +1382,14 @@ and ciphers. (Contributed by Christian Heimes in :issue:`28043`.) SSL session can be copied from one client-side connection to another -with :class:`~ssl.SSLSession`. TLS session resumption can speed up -the initial handshake, reduce latency and improve performance +with the new :class:`~ssl.SSLSession` class. TLS session resumption can +speed up the initial handshake, reduce latency and improve performance (Contributed by Christian Heimes in :issue:`19500` based on a draft by Alex Warhawk.) +The new :meth:`~ssl.SSLContext.get_ciphers` method can be used to +get a list of enabled ciphers in order of cipher priority. + All constants and flags have been converted to :class:`~enum.IntEnum` and :class:`~enum.IntFlags`. (Contributed by Christian Heimes in :issue:`28025`.) @@ -1047,6 +1402,22 @@ General resource ids (``GEN_RID``) in subject alternative name extensions no longer case a SystemError. (Contributed by Christian Heimes in :issue:`27691`.) + +statistics +---------- + +A new :func:`~statistics.harmonic_mean` function has been added. +(Contributed by Steven D'Aprano in :issue:`27181`.) + + +struct +------ + +:mod:`struct` now supports IEEE 754 half-precision floats via the ``'e'`` +format specifier. +(Contributed by Eli Stevens, Mark Dickinson in :issue:`11734`.) + + subprocess ---------- @@ -1059,6 +1430,22 @@ read the exit status of the child process (Contributed by Victor Stinner in The :class:`subprocess.Popen` constructor and all functions that pass arguments through to it now accept *encoding* and *errors* arguments. Specifying either of these will enable text mode for the *stdin*, *stdout* and *stderr* streams. +(Contributed by Steve Dower in :issue:`6135`.) + + +sys +--- + +The new :func:`~sys.getfilesystemencodeerrors` function returns the name of +the error mode used to convert between Unicode filenames and bytes filenames. +(Contributed by Steve Dower in :issue:`27781`.) + +On Windows the return value of the :func:`~sys.getwindowsversion` function +now includes the *platform_version* field which contains the accurate major +version, minor version and build number of the current operating system, +rather than the version that is being emulated for the process +(Contributed by Steve Dower in :issue:`27932`.) + telnetlib --------- @@ -1067,6 +1454,26 @@ telnetlib Stéphane Wirtel in :issue:`25485`). +time +---- + +The :class:`~time.struct_time` attributes :attr:`tm_gmtoff` and +:attr:`tm_zone` are now available on all platforms. + + +timeit +------ + +The new :meth:`Timer.autorange() ` convenience +method has been added to call :meth:`Timer.timeit() ` +repeatedly so that the total run time is greater or equal to 200 milliseconds. +(Contributed by Steven D'Aprano in :issue:`6422`.) + +:mod:`timeit` now warns when there is substantial (4x) variance +between best and worst times. +(Contributed by Serhiy Storchaka in :issue:`23552`.) + + tkinter ------- @@ -1080,7 +1487,7 @@ not work in future versions of Tcl. (Contributed by Serhiy Storchaka in :issue:`22115`). -.. _py36-traceback: +.. _whatsnew36-traceback: traceback --------- @@ -1103,19 +1510,69 @@ following example:: (Contributed by Emanuel Barry in :issue:`26823`.) +tracemalloc +----------- + +The :mod:`tracemalloc` module now supports tracing memory allocations in +multiple different address spaces. + +The new :class:`~tracemalloc.DomainFilter` filter class has been added +to filter block traces by their address space (domain). + +(Contributed by Victor Stinner in :issue:`26588`.) + + +.. _whatsnew36-typing: + typing ------ +Starting with Python 3.6 the :mod:`typing` module is no longer provisional +and its API is considered stable. + +Since the :mod:`typing` module was :term:`provisional ` +in Python 3.5, all changes introduced in Python 3.6 have also been +backported to Python 3.5.x. + The :class:`typing.ContextManager` class has been added for representing :class:`contextlib.AbstractContextManager`. (Contributed by Brett Cannon in :issue:`25609`.) +The :class:`typing.Collection` class has been added for +representing :class:`collections.abc.Collection`. +(Contributed by Ivan Levkivskyi in :issue:`27598`.) + +The :const:`typing.ClassVar` type construct has been added to +mark class variables. As introduced in :pep:`526`, a variable annotation +wrapped in ClassVar indicates that a given attribute is intended to be used as +a class variable and should not be set on instances of that class. +(Contributed by Ivan Levkivskyi in `Github #280 +`_.) + +A new :const:`~typing.TYPE_CHECKING` constant that is assumed to be +``True`` by the static type chekers, but is ``False`` at runtime. +(Contributed by Guido van Rossum in `Github #230 +`_.) + +A new :func:`~typing.NewType` helper function has been added to create +lightweight distinct types for annotations:: + + from typing import NewType + + UserId = NewType('UserId', int) + some_id = UserId(524313) + +The static type checker will treat the new type as if it were a subclass +of the original type. (Contributed by Ivan Levkivskyi in `Github #189 +`_.) + unicodedata ----------- -The internal database has been upgraded to use Unicode 9.0.0. (Contributed by -Benjamin Peterson.) +The :mod:`unicodedata` module now uses data from `Unicode 9.0.0 +`_. +(Contributed by Benjamin Peterson.) unittest.mock @@ -1129,12 +1586,17 @@ The :class:`~unittest.mock.Mock` class has the following improvements: was called. (Contributed by Amit Saha in :issue:`26323`.) +* The :meth:`Mock.reset_mock() ` method + now has two optional keyword only arguments: *return_value* and + *side_effect*. + (Contributed by Kushal Das in :issue:`21271`.) + urllib.request -------------- If a HTTP request has a file or iterable body (other than a -bytes object) but no Content-Length header, rather than +bytes object) but no ``Content-Length`` header, rather than throwing an error, :class:`~urllib.request.AbstractHTTPHandler` now falls back to use chunked transfer encoding. (Contributed by Demian Brecht and Rolf Krahl in :issue:`12319`.) @@ -1148,6 +1610,14 @@ urllib.robotparser (Contributed by Nikolay Bogoychev in :issue:`16099`.) +venv +---- + +:mod:`venv` accepts a new parameter ``--prompt``. This parameter provides an +alternative prefix for the virtual environment. (Proposed by Łukasz Balcerzak +and ported to 3.6 by Stéphane Wirtel in :issue:`22829`.) + + warnings -------- @@ -1203,8 +1673,9 @@ Allowed keyword arguments to be passed to :func:`Beep `, xmlrpc.client ------------- -The module now supports unmarshalling additional data types used by -Apache XML-RPC implementation for numerics and ``None``. +The :mod:`xmlrpc.client` module now supports unmarshalling +additional data types used by Apache XML-RPC implementation +for numerics and ``None``. (Contributed by Serhiy Storchaka in :issue:`26885`.) @@ -1225,19 +1696,26 @@ write data into a ZIP file, as well as for extracting data. zlib ---- -The :func:`~zlib.compress` function now accepts keyword arguments. -(Contributed by Aviv Palivoda in :issue:`26243`.) +The :func:`~zlib.compress` and :func:`~zlib.decompress` functions now accept +keyword arguments. +(Contributed by Aviv Palivoda in :issue:`26243` and +Xiang Zhang in :issue:`16764` respectively.) -fileinput ---------- +Optimizations +============= -:func:`~fileinput.hook_encoded` now supports the *errors* argument. -(Contributed by Joseph Hackman in :issue:`25788`.) +* Python interpreter now uses 16-bit wordcode instead of bytecode which + made a number of opcode optimizations possible. + (Contributed by Demur Rumed with input and reviews from + Serhiy Storchaka and Victor Stinner in :issue:`26647` and :issue:`28050`.) +* The :class:`Future ` now has an optimized + C implementation. + (Contributed by Yury Selivanov and INADA Naoki in :issue:`26801`.) -Optimizations -============= +* The :class:`Task ` now has an optimized + C implementation. (Contributed by Yury Selivanov in :issue:`28544`.) * The ASCII decoder is now up to 60 times as fast for error handlers ``surrogateescape``, ``ignore`` and ``replace`` (Contributed @@ -1291,12 +1769,23 @@ Optimizations it is now about 1.5--4 times faster. (Contributed by Serhiy Storchaka in :issue:`26032`). +* :class:`xml.etree.ElementTree` parsing, iteration and deepcopy performance + has been significantly improved. + (Contributed by Serhiy Storchaka in :issue:`25638`, :issue:`25873`, + and :issue:`25869`.) + +* Creation of :class:`fractions.Fraction` instances from floats and + decimals is now 2 to 3 times faster. + (Contributed by Serhiy Storchaka in :issue:`25971`.) + Build and C API Changes ======================= -* Python now requires some C99 support in the toolchain to build. For more - information, see :pep:`7`. +* Python now requires some C99 support in the toolchain to build. + Most notably, Python now uses standard integer types and macros in + place of custom macros like ``PY_LONG_LONG``. + For more information, see :pep:`7` and :issue:`17884`. * Cross-compiling CPython with the Android NDK and the Android API level set to 21 (Android 5.0 Lollilop) or greater, runs successfully. While Android is not @@ -1307,8 +1796,13 @@ Build and C API Changes will activate expensive optimizations like PGO. (Original patch by Alecsandru Patrascu of Intel in :issue:`26539`.) +* The :term:`GIL ` must now be held when allocator + functions of :c:data:`PYMEM_DOMAIN_OBJ` (ex: :c:func:`PyObject_Malloc`) and + :c:data:`PYMEM_DOMAIN_MEM` (ex: :c:func:`PyMem_Malloc`) domains are called. + * New :c:func:`Py_FinalizeEx` API which indicates if flushing buffered data - failed (:issue:`5319`). + failed. + (Contributed by Martin Panter in :issue:`5319`.) * :c:func:`PyArg_ParseTupleAndKeywords` now supports :ref:`positional-only parameters `. Positional-only parameters are @@ -1319,112 +1813,178 @@ Build and C API Changes as ``"[Previous line repeated {count} more times]"``. (Contributed by Emanuel Barry in :issue:`26823`.) +* The new :c:func:`PyErr_SetImportErrorSubclass` function allows for + specifying a subclass of :exc:`ImportError` to raise. + (Contributed by Eric Snow in :issue:`15767`.) -Deprecated -========== +* The new :c:func:`PyErr_ResourceWarning` function can be used to generate + the :exc:`ResourceWarning` providing the source of the resource allocation. + (Contributed by Victor Stinner in :issue:`26567`.) + +* The new :c:func:`PyOS_FSPath` function returns the file system + representation of a :term:`path-like object`. + (Contributed by Brett Cannon in :issue:`27186`.) + +* The :c:func:`PyUnicode_FSConverter` and :c:func:`PyUnicode_FSDecoder` + functions will now accept :term:`path-like objects `. -Deprecated Build Options ------------------------- -The ``--with-system-ffi`` configure flag is now on by default on non-OSX UNIX -platforms. It may be disabled by using ``--without-system-ffi``, but using the -flag is deprecated and will not be accepted in Python 3.7. OSX is unaffected -by this change. Note that many OS distributors already use the -``--with-system-ffi`` flag when building their system Python. +Deprecated +========== New Keywords ------------ ``async`` and ``await`` are not recommended to be used as variable, class, function or module names. Introduced by :pep:`492` in Python 3.5, they will -become proper keywords in Python 3.7. +become proper keywords in Python 3.7. Starting in Python 3.6, the use of +``async`` or ``await`` as names will generate a :exc:`DeprecationWarning`. + + +Deprecated Python behavior +-------------------------- + +Raising the :exc:`StopIteration` exception inside a generator will now +generate a :exc:`DeprecationWarning`, and will trigger a :exc:`RuntimeError` +in Python 3.7. See :ref:`whatsnew-pep-479` for details. + +The :meth:`__aiter__` method is now expected to return an asynchronous +iterator directly instead of returning an awaitable as previously. +Doing the former will trigger a :exc:`DeprecationWarning`. Backward +compatibility will be removed in Python 3.7. +(Contributed by Yury Selivanov in :issue:`27243`.) + +A backslash-character pair that is not a valid escape sequence now generates +a :exc:`DeprecationWarning`. Although this will eventually become a +:exc:`SyntaxError`, that will not be for several Python releases. +(Contributed by Emanuel Barry in :issue:`27364`.) + +When performing a relative import, falling back on ``__name__`` and +``__path__`` from the calling module when ``__spec__`` or +``__package__`` are not defined now raises an :exc:`ImportWarning`. +(Contributed by Rose Ames in :issue:`25791`.) Deprecated Python modules, functions and methods ------------------------------------------------ -* :meth:`importlib.machinery.SourceFileLoader.load_module` and - :meth:`importlib.machinery.SourcelessFileLoader.load_module` are now - deprecated. They were the only remaining implementations of - :meth:`importlib.abc.Loader.load_module` in :mod:`importlib` that had not - been deprecated in previous versions of Python in favour of - :meth:`importlib.abc.Loader.exec_module`. +asynchat +~~~~~~~~ + +The :mod:`asynchat` has been deprecated in favor of :mod:`asyncio`. +(Contributed by Mariatta in :issue:`25002`.) + + +asyncore +~~~~~~~~ + +The :mod:`asyncore` has been deprecated in favor of :mod:`asyncio`. +(Contributed by Mariatta in :issue:`25002`.) + -* The :mod:`tkinter.tix` module is now deprecated. :mod:`tkinter` users should - use :mod:`tkinter.ttk` instead. +dbm +~~~ + +Unlike other :mod:`dbm` implementations, the :mod:`dbm.dumb` module +creates databases with the ``'rw'`` mode and allows modifying the database +opened with the ``'r'`` mode. This behavior is now deprecated and will +be removed in 3.8. +(Contributed by Serhiy Storchaka in :issue:`21708`.) + + +distutils +~~~~~~~~~ + +The undocumented ``extra_path`` argument to the +:class:`~distutils.Distribution` constructor is now considered deprecated +and will raise a warning if set. Support for this parameter will be +removed in a future Python release. See :issue:`27919` for details. + + +grp +~~~ + +The support of non-integer arguments in :func:`~grp.getgrgid` has been +deprecated. +(Contributed by Serhiy Storchaka in :issue:`26129`.) + + +importlib +~~~~~~~~~ + +The :meth:`importlib.machinery.SourceFileLoader.load_module` and +:meth:`importlib.machinery.SourcelessFileLoader.load_module` methods +are now deprecated. They were the only remaining implementations of +:meth:`importlib.abc.Loader.load_module` in :mod:`importlib` that had not +been deprecated in previous versions of Python in favour of +:meth:`importlib.abc.Loader.exec_module`. + +os +~~ + +Undocumented support of general :term:`bytes-like objects ` +as paths in :mod:`os` functions, :func:`compile` and similar functions is +now deprecated. +(Contributed by Serhiy Storchaka in :issue:`25791` and :issue:`26754`.) + +re +~~ + +Support for inline flags ``(?letters)`` in the middle of the regular +expression has been deprecated and will be removed in a future Python +version. Flags at the start of a regular expression are still allowed. +(Contributed by Serhiy Storchaka in :issue:`22493`.) + +ssl +~~~ + +OpenSSL 0.9.8, 1.0.0 and 1.0.1 are deprecated and no longer supported. +In the future the :mod:`ssl` module will require at least OpenSSL 1.0.2 or +1.1.0. + +SSL-related arguments like ``certfile``, ``keyfile`` and ``check_hostname`` +in :mod:`ftplib`, :mod:`http.client`, :mod:`imaplib`, :mod:`poplib`, +and :mod:`smtplib` have been deprecated in favor of ``context``. +(Contributed by Christian Heimes in :issue:`28022`.) + +A couple of protocols and functions of the :mod:`ssl` module are now +deprecated. Some features will no longer be available in future versions +of OpenSSL. Other features are deprecated in favor of a different API. +(Contributed by Christian Heimes in :issue:`28022` and :issue:`26470`.) + +tkinter +~~~~~~~ + +The :mod:`tkinter.tix` module is now deprecated. :mod:`tkinter` users +should use :mod:`tkinter.ttk` instead. + +venv +~~~~ + +The ``pyvenv`` script has been deprecated in favour of ``python3 -m venv``. +This prevents confusion as to what Python interpreter ``pyvenv`` is +connected to and thus what Python interpreter will be used by the virtual +environment. (Contributed by Brett Cannon in :issue:`25154`.) Deprecated functions and types of the C API ------------------------------------------- -* Undocumented functions :c:func:`PyUnicode_AsEncodedObject`, - :c:func:`PyUnicode_AsDecodedObject`, :c:func:`PyUnicode_AsEncodedUnicode` - and :c:func:`PyUnicode_AsDecodedUnicode` are deprecated now. - Use :ref:`generic codec based API ` instead. - - -Deprecated features -------------------- - -* The ``pyvenv`` script has been deprecated in favour of ``python3 -m venv``. - This prevents confusion as to what Python interpreter ``pyvenv`` is - connected to and thus what Python interpreter will be used by the virtual - environment. (Contributed by Brett Cannon in :issue:`25154`.) - -* When performing a relative import, falling back on ``__name__`` and - ``__path__`` from the calling module when ``__spec__`` or - ``__package__`` are not defined now raises an :exc:`ImportWarning`. - (Contributed by Rose Ames in :issue:`25791`.) - -* Unlike to other :mod:`dbm` implementations, the :mod:`dbm.dumb` module - creates database in ``'r'`` and ``'w'`` modes if it doesn't exist and - allows modifying database in ``'r'`` mode. This behavior is now deprecated - and will be removed in 3.8. - (Contributed by Serhiy Storchaka in :issue:`21708`.) - -* Undocumented support of general :term:`bytes-like objects ` - as paths in :mod:`os` functions, :func:`compile` and similar functions is - now deprecated. - (Contributed by Serhiy Storchaka in :issue:`25791` and :issue:`26754`.) - -* The undocumented ``extra_path`` argument to a distutils Distribution - is now considered - deprecated, will raise a warning during install if set. Support for this - parameter will be dropped in a future Python release and likely earlier - through third party tools. See :issue:`27919` for details. - -* A backslash-character pair that is not a valid escape sequence now generates - a DeprecationWarning. Although this will eventually become a SyntaxError, - that will not be for several Python releases. (Contributed by Emanuel Barry - in :issue:`27364`.) - -* Inline flags ``(?letters)`` now should be used only at the start of the - regular expression. Inline flags in the middle of the regular expression - affects global flags in Python :mod:`re` module. This is an exception to - other regular expression engines that either apply flags to only part of - the regular expression or treat them as an error. To avoid distinguishing - inline flags in the middle of the regular expression now emit a deprecation - warning. It will be an error in future Python releases. - (Contributed by Serhiy Storchaka in :issue:`22493`.) - -* SSL-related arguments like ``certfile``, ``keyfile`` and ``check_hostname`` - in :mod:`ftplib`, :mod:`http.client`, :mod:`imaplib`, :mod:`poplib`, - and :mod:`smtplib` have been deprecated in favor of ``context``. - (Contributed by Christian Heimes in :issue:`28022`.) - -* A couple of protocols and functions of the :mod:`ssl` module are now - deprecated. Some features will no longer be available in future versions - of OpenSSL. Other features are deprecated in favor of a different API. - (Contributed by Christian Heimes in :issue:`28022` and :issue:`26470`.) +Undocumented functions :c:func:`PyUnicode_AsEncodedObject`, +:c:func:`PyUnicode_AsDecodedObject`, :c:func:`PyUnicode_AsEncodedUnicode` +and :c:func:`PyUnicode_AsDecodedUnicode` are deprecated now. +Use :ref:`generic codec based API ` instead. -Deprecated Python behavior --------------------------- +Deprecated Build Options +------------------------ -* Raising the :exc:`StopIteration` exception inside a generator will now generate a - :exc:`DeprecationWarning`, and will trigger a :exc:`RuntimeError` in Python 3.7. - See :ref:`whatsnew-pep-479` for details. +The ``--with-system-ffi`` configure flag is now on by default on non-macOS +UNIX platforms. It may be disabled by using ``--without-system-ffi``, but +using the flag is deprecated and will not be accepted in Python 3.7. +macOS is unaffected by this change. Note that many OS distributors already +use the ``--with-system-ffi`` flag when building their system Python. Removed @@ -1433,9 +1993,14 @@ Removed API and Feature Removals ------------------------ +* Unknown escapes consisting of ``'\'`` and an ASCII letter in + regular expressions will now cause an error. The :const:`re.LOCALE` + flag can now only be used with binary patterns. + * ``inspect.getmoduleinfo()`` was removed (was deprecated since CPython 3.3). :func:`inspect.getmodulename` should be used for obtaining the module name for a given path. + (Contributed by Yury Selivanov in :issue:`13248`.) * ``traceback.Ignore`` class and ``traceback.usage``, ``traceback.modname``, ``traceback.fullmodname``, ``traceback.find_lines_from_code``, @@ -1460,6 +2025,8 @@ API and Feature Removals script that created these modules is still available in the source distribution at :source:`Tools/scripts/h2py.py`. +* The deprecated ``asynchat.fifo`` class has been removed. + Porting to Python 3.6 ===================== @@ -1480,6 +2047,10 @@ Changes in 'python' Command Behavior Changes in the Python API ------------------------- +* :func:`open() ` will no longer allow combining the ``'U'`` mode flag + with ``'+'``. + (Contributed by Jeff Balogh and John O'Connor in :issue:`2091`.) + * :mod:`sqlite3` no longer implicitly commit an open transaction before DDL statements. @@ -1523,7 +2094,8 @@ Changes in the Python API :mod:`mimetypes`, :mod:`optparse`, :mod:`plistlib`, :mod:`smtpd`, :mod:`subprocess`, :mod:`tarfile`, :mod:`threading` and :mod:`wave`. This means they will export new symbols when ``import *`` - is used. See :issue:`23883`. + is used. + (Contributed by Joel Taddei and Jacek Kołodziej in :issue:`23883`.) * When performing a relative import, if ``__package__`` does not compare equal to ``__spec__.parent`` then :exc:`ImportWarning` is raised. @@ -1546,8 +2118,8 @@ Changes in the Python API :exc:`KeyError` if the user doesn't have privileges. * The :meth:`socket.socket.close` method now raises an exception if - an error (e.g. EBADF) was reported by the underlying system call. - See :issue:`26685`. + an error (e.g. ``EBADF``) was reported by the underlying system call. + (Contributed by Martin Panter in :issue:`26685`.) * The *decode_data* argument for :class:`smtpd.SMTPChannel` and :class:`smtpd.SMTPServer` constructors is now ``False`` by default. @@ -1557,13 +2129,16 @@ Changes in the Python API Code that has already been updated in accordance with the deprecation warning generated by 3.5 will not be affected. -* All optional parameters of the :func:`~json.dump`, :func:`~json.dumps`, +* All optional arguments of the :func:`~json.dump`, :func:`~json.dumps`, :func:`~json.load` and :func:`~json.loads` functions and :class:`~json.JSONEncoder` and :class:`~json.JSONDecoder` class constructors in the :mod:`json` module are now :ref:`keyword-only `. (Contributed by Serhiy Storchaka in :issue:`18726`.) +* Subclasses of :class:`type` which don't override ``type.__new__`` may no + longer use the one-argument form to get the type of an object. + * As part of :pep:`487`, the handling of keyword arguments passed to :class:`type` (other than the metaclass hint, ``metaclass``) is now consistently delegated to :meth:`object.__init_subclass__`. This means that @@ -1592,7 +2167,63 @@ Changes in the Python API header field has been specified and the request body is a file object, it is now sent with HTTP 1.1 chunked encoding. If a file object has to be sent to a HTTP 1.0 server, the Content-Length value now has to be - specified by the caller. See :issue:`12319`. + specified by the caller. + (Contributed by Demian Brecht and Rolf Krahl with tweaks from + Martin Panter in :issue:`12319`.) + +* The :class:`~csv.DictReader` now returns rows of type + :class:`~collections.OrderedDict`. + (Contributed by Steve Holden in :issue:`27842`.) + +* The :const:`crypt.METHOD_CRYPT` will no longer be added to ``crypt.methods`` + if unsupported by the platform. + (Contributed by Victor Stinner in :issue:`25287`.) + +* The *verbose* and *rename* arguments for + :func:`~collections.namedtuple` are now keyword-only. + (Contributed by Raymond Hettinger in :issue:`25628`.) + +* The :meth:`~cgi.FieldStorage.read_multi` method now ignores the + ``Content-Length`` header in part headers. + (Contributed by Peter Landry in :issue:`24764`.) + +* On Linux, :func:`ctypes.util.find_library` now looks in + ``LD_LIBRARY_PATH`` for shared libraries. + (Contributed by Vinay Sajip in :issue:`9998`.) + +* The :meth:`datetime.fromtimestamp() ` and + :meth:`datetime.utcfromtimestamp() ` + methods now round microseconds to nearest with ties going to + nearest even integer (``ROUND_HALF_EVEN``), instead of + rounding towards negative infinity (``ROUND_FLOOR``). + (Contributed by Victor Stinner in :issue:`23517`.) + +* The :class:`imaplib.IMAP4` class now handles flags containing the + ``']'`` character in messages sent from the server to improve + real-world compatibility. + (Contributed by Lita Cho in :issue:`21815`.) + +* The :func:`mmap.write() ` function now returns the number + of bytes written like other write methods. + (Contributed by Jakub Stasiak in :issue:`26335`.) + +* The :func:`pkgutil.iter_modules` and :func:`pkgutil.walk_packages` + functions now return :class:`~pkgutil.ModuleInfo` named tuples. + (Contributed by Ramchandra Apte in :issue:`17211`.) + +* :func:`re.sub` now raises an error for invalid numerical group + reference in replacement template even if the pattern is not + found in the string. Error message for invalid group reference + now includes the group index and the position of the reference. + (Contributed by SilentGhost, Serhiy Storchaka in :issue:`25953`.) + +* :class:`zipfile.ZipFile` will now raise :exc:`NotImplementedError` for + unrecognized compression values. Previously a plain :exc:`RuntimeError` + was raised. Additionally, calling :class:`~zipfile.ZipFile` methods or + on a closed ZipFile or calling :meth:`~zipfile.ZipFile.write` methods + on a ZipFile created with mode ``'r'`` will raise a :exc:`ValueError`. + Previously, a :exc:`RuntimeError` was raised in those scenarios. + Changes in the C API -------------------- -- 2.10.1