# What\'s New In Python 3.6 Editors : Elvis Pranskevichus \, Yury Selivanov \ > \* Anyone can add text to this document. Do not spend very much time on the wording of your changes, because your text will probably get rewritten to some degree. > > \* The maintainer will go through Misc/NEWS periodically and add changes; it\'s therefore more important to add your changes to Misc/NEWS than to this file. > > \* This is not a complete list of every single change; completeness is the purpose of Misc/NEWS. Some changes I consider too small or esoteric to include. If such a change is added to the text, I\'ll just remove it. (This is another reason you shouldn\'t spend too much time on writing your addition.) > > \* If you want to draw your new text to the attention of the maintainer, add \'XXX\' to the beginning of the paragraph or section. > > \* It\'s OK to just add a fragmentary note about a change. For example: \"XXX Describe the transmogrify() function added to the socket module.\" The maintainer will research the change and write the necessary text. > > \* You can comment out your additions if you like, but it\'s not necessary (especially when a final release is some months away). > > \* Credit the author of a patch or bugfix. Just the name is sufficient; the e-mail address isn\'t necessary. > > - It\'s helpful to add the bug/patch number as a comment: > > XXX Describe the transmogrify() function added to the socket module. (Contributed by P.Y. Developer in `12345`{.interpreted-text role="issue"}.) > > This saves the maintainer the effort of going through the Mercurial log when researching a change. This article explains the new features in Python 3.6, compared to 3.5. Python 3.6 was released on December 23, 2016. See the [changelog](https://docs.python.org/3.6/whatsnew/changelog.html) for a full list of changes. ::: seealso `494`{.interpreted-text role="pep"} - Python 3.6 Release Schedule ::: ## Summary \-- Release highlights New syntax features: - `PEP 498 `{.interpreted-text role="ref"}, formatted string literals. - `PEP 515 `{.interpreted-text role="ref"}, underscores in numeric literals. - `PEP 526 `{.interpreted-text role="ref"}, syntax for variable annotations. - `PEP 525 `{.interpreted-text role="ref"}, asynchronous generators. - `PEP 530 `{.interpreted-text role="ref"}: asynchronous comprehensions. New library modules: - `secrets`{.interpreted-text role="mod"}: `PEP 506 -- Adding A Secrets Module To The Standard Library `{.interpreted-text role="ref"}. CPython implementation improvements: - The `dict `{.interpreted-text role="ref"} type has been reimplemented to use a `more compact representation `{.interpreted-text role="ref"} based on [a proposal by Raymond Hettinger](https://mail.python.org/pipermail/python-dev/2012-December/123028.html) and similar to the [PyPy dict implementation](https://morepypy.blogspot.com/2015/01/faster-more-memory-efficient-and-more.html). 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 `new protocol `{.interpreted-text role="ref"}. - The class attribute definition order is `now preserved `{.interpreted-text role="ref"}. - The order of elements in `**kwargs` now `corresponds to the order `{.interpreted-text role="ref"} in which keyword arguments were passed to the function. - DTrace and SystemTap `probing support `{.interpreted-text role="ref"} has been added. - The new `PYTHONMALLOC `{.interpreted-text role="ref"} environment variable can now be used to debug the interpreter memory allocation and access errors. Significant improvements in the standard library: - The `asyncio`{.interpreted-text role="mod"} 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 `file system path protocol `{.interpreted-text role="ref"} has been implemented to support `path-like objects `{.interpreted-text role="term"}. All standard library functions operating on paths have been updated to work with the new protocol. - The `datetime`{.interpreted-text role="mod"} module has gained support for `Local Time Disambiguation `{.interpreted-text role="ref"}. - The `typing`{.interpreted-text role="mod"} module received a number of `improvements `{.interpreted-text role="ref"}. - The `tracemalloc`{.interpreted-text role="mod"} module has been significantly reworked and is now used to provide better output for `ResourceWarning`{.interpreted-text role="exc"} as well as provide better diagnostics for memory allocation errors. See the `PYTHONMALLOC section `{.interpreted-text role="ref"} for more information. Security improvements: - The new `secrets`{.interpreted-text role="mod"} 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, `os.urandom`{.interpreted-text role="func"} now blocks until the system urandom entropy pool is initialized to increase the security. See the `524`{.interpreted-text role="pep"} for the rationale. - The `hashlib`{.interpreted-text role="mod"} and `ssl`{.interpreted-text role="mod"} modules now support OpenSSL 1.1.0. - The default settings and feature set of the `ssl`{.interpreted-text role="mod"} module have been improved. - The `hashlib`{.interpreted-text role="mod"} module received support for the BLAKE2, SHA-3 and SHAKE hash algorithms and the `~hashlib.scrypt`{.interpreted-text role="func"} key derivation function. Windows improvements: - `PEP 528 `{.interpreted-text role="ref"} and `PEP 529 `{.interpreted-text role="ref"}, Windows filesystem and console encoding changed to UTF-8. - The `py.exe` launcher, when used interactively, no longer prefers Python 2 over Python 3 when the user doesn\'t specify a version (via command line arguments or a config file). Handling of shebang lines remains unchanged - \"python\" refers to Python 2 in that case. - `python.exe` and `pythonw.exe` have been marked as long-path aware, which means that the 260 character path limit may no longer apply. See `removing the MAX_PATH limitation `{.interpreted-text role="ref"} for details. - A `._pth` file can be added to force isolated mode and fully specify all search paths to avoid registry and environment lookup. See `the documentation `{.interpreted-text role="ref"} for more information. - A `python36.zip` file now works as a landmark to infer `PYTHONHOME`{.interpreted-text role="envvar"}. See `the documentation `{.interpreted-text role="ref"} for more information. ## New Features ### PEP 498: Formatted string literals {#whatsnew36-pep498} `498`{.interpreted-text role="pep"} introduces a new kind of string literals: *f-strings*, or `formatted string literals `{.interpreted-text role="ref"}. Formatted string literals are prefixed with `'f'` and are similar to the format strings accepted by `str.format`{.interpreted-text role="meth"}. They contain replacement fields surrounded by curly braces. The replacement fields are expressions, which are evaluated at run time, and then formatted using the `format`{.interpreted-text role="func"} protocol: >>> 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 `498`{.interpreted-text role="pep"} \-- Literal String Interpolation. : PEP written and implemented by Eric V. Smith. `Feature documentation `{.interpreted-text role="ref"}. ::: ### PEP 526: Syntax for variable annotations {#whatsnew36-pep526} `484`{.interpreted-text role="pep"} introduced the standard for type annotations of function parameters, a.k.a. type hints. This PEP adds syntax to Python for annotating the types of variables including class variables and instance variables: primes: List[int] = [] captain: str # Note: no initial value! class Starship: stats: Dict[str, int] = {} Just as for function annotations, the Python interpreter does not attach any particular meaning to variable annotations and only stores them in the `__annotations__` attribute of a class or module. In contrast to variable declarations in statically typed languages, the goal of annotation syntax is to provide an easy way to specify structured type metadata for third party tools and libraries via the abstract syntax tree and the `__annotations__` attribute. ::: seealso `526`{.interpreted-text role="pep"} \-- Syntax for variable annotations. : PEP written by Ryan Gonzalez, Philip House, Ivan Levkivskyi, Lisa Roach, and Guido van Rossum. Implemented by Ivan Levkivskyi. Tools that use or will use the new syntax: [mypy](https://www.mypy-lang.org/), [pytype](https://github.com/google/pytype), PyCharm, etc. ::: ### PEP 515: Underscores in Numeric Literals {#whatsnew36-pep515} `515`{.interpreted-text role="pep"} adds the ability to use underscores in numeric literals for improved readability. For example: >>> 1_000_000_000_000_000 1000000000000000 >>> 0x_FF_FF_FF_FF 4294967295 Single underscores are allowed between digits and after any base specifier. Leading, trailing, or multiple underscores in a row are not allowed. The `string formatting `{.interpreted-text role="ref"} 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 `515`{.interpreted-text role="pep"} \-- Underscores in Numeric Literals : PEP written by Georg Brandl and Serhiy Storchaka. ::: ### PEP 525: Asynchronous Generators {#whatsnew36-pep525} `492`{.interpreted-text role="pep"} introduced support for native coroutines and `async` / `await` syntax to Python 3.5. A notable limitation of the Python 3.5 implementation is that it was not possible to use `await` and `yield` in the same function body. In Python 3.6 this restriction has been lifted, making it possible to define *asynchronous generators*: async def ticker(delay, to): """Yield numbers from 0 to *to* every *delay* seconds.""" for i in range(to): yield i await asyncio.sleep(delay) The new syntax allows for faster and more concise code. ::: seealso `525`{.interpreted-text role="pep"} \-- Asynchronous Generators : PEP written and implemented by Yury Selivanov. ::: ### PEP 530: Asynchronous Comprehensions {#whatsnew36-pep530} `530`{.interpreted-text role="pep"} adds support for using `async for` in list, set, dict comprehensions and generator expressions: result = [i async for i in aiter() if i % 2] Additionally, `await` expressions are supported in all kinds of comprehensions: result = [await fun() for fun in funcs if await condition()] ::: seealso `530`{.interpreted-text role="pep"} \-- Asynchronous Comprehensions : PEP written and implemented by Yury Selivanov. ::: ### PEP 487: Simpler customization of class creation {#whatsnew36-pep487} 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 PluginBase: subclasses = [] def __init_subclass__(cls, **kwargs): super().__init_subclass__(**kwargs) cls.subclasses.append(cls) class Plugin1(PluginBase): pass class Plugin2(PluginBase): pass In order to allow zero-argument `super`{.interpreted-text role="func"} calls to work correctly from `~object.__init_subclass__`{.interpreted-text role="meth"} implementations, custom metaclasses must ensure that the new `__classcell__` namespace entry is propagated to `type.__new__` (as described in `class-object-creation`{.interpreted-text role="ref"}). ::: seealso `487`{.interpreted-text role="pep"} \-- Simpler customization of class creation : PEP written and implemented by Martin Teichmann. `Feature documentation `{.interpreted-text role="ref"} ::: ### PEP 487: Descriptor Protocol Enhancements {#whatsnew36-pep487-descriptors} `487`{.interpreted-text role="pep"} extends the descriptor protocol to include the new optional `~object.__set_name__`{.interpreted-text role="meth"} 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. In other words, instances of descriptors can now know the attribute name of the descriptor in the owner class: class IntField: def __get__(self, instance, owner): return instance.__dict__[self.name] def __set__(self, instance, value): if not isinstance(value, int): raise ValueError(f'expecting integer in {self.name}') instance.__dict__[self.name] = value # this is the new initializer: def __set_name__(self, owner, name): self.name = name class Model: int_field = IntField() ::: seealso `487`{.interpreted-text role="pep"} \-- Simpler customization of class creation : PEP written and implemented by Martin Teichmann. `Feature documentation `{.interpreted-text role="ref"} ::: ### PEP 519: Adding a file system path protocol {#whatsnew36-pep519} File system paths have historically been represented as `str`{.interpreted-text role="class"} or `bytes`{.interpreted-text role="class"} objects. This has led to people who write code which operate on file system paths to assume that such objects are only one of those two types (an `int`{.interpreted-text role="class"} representing a file descriptor does not count as that is not a file path). Unfortunately that assumption prevents alternative object representations of file system paths like `pathlib`{.interpreted-text role="mod"} from working with pre-existing code, including Python\'s standard library. To fix this situation, a new interface represented by `os.PathLike`{.interpreted-text role="class"} has been defined. By implementing the `~os.PathLike.__fspath__`{.interpreted-text role="meth"} method, an object signals that it represents a path. An object can then provide a low-level representation of a file system path as a `str`{.interpreted-text role="class"} or `bytes`{.interpreted-text role="class"} object. This means an object is considered `path-like `{.interpreted-text role="term"} if it implements `os.PathLike`{.interpreted-text role="class"} or is a `str`{.interpreted-text role="class"} or `bytes`{.interpreted-text role="class"} object which represents a file system path. Code can use `os.fspath`{.interpreted-text role="func"}, `os.fsdecode`{.interpreted-text role="func"}, or `os.fsencode`{.interpreted-text role="func"} to explicitly get a `str`{.interpreted-text role="class"} and/or `bytes`{.interpreted-text role="class"} representation of a path-like object. The built-in `open`{.interpreted-text role="func"} function has been updated to accept `os.PathLike`{.interpreted-text role="class"} objects, as have all relevant functions in the `os`{.interpreted-text role="mod"} and `os.path`{.interpreted-text role="mod"} modules, and most other functions and classes in the standard library. The `os.DirEntry`{.interpreted-text role="class"} class and relevant classes in `pathlib`{.interpreted-text role="mod"} have also been updated to implement `os.PathLike`{.interpreted-text role="class"}. The hope is that updating the fundamental functions for operating on file system paths will lead to third-party code to implicitly support all `path-like objects `{.interpreted-text role="term"} without any code changes, or at least very minimal ones (e.g. calling `os.fspath`{.interpreted-text role="func"} at the beginning of code before operating on a path-like object). Here are some examples of how the new interface allows for `pathlib.Path`{.interpreted-text role="class"} to be used more easily and transparently with pre-existing code: >>> import pathlib >>> with open(pathlib.Path("README")) as f: ... contents = f.read() ... >>> import os.path >>> os.path.splitext(pathlib.Path("some_file.txt")) ('some_file', '.txt') >>> os.path.join("/a/b", pathlib.Path("c")) '/a/b/c' >>> import os >>> os.fspath(pathlib.Path("some_file.txt")) 'some_file.txt' (Implemented by Brett Cannon, Ethan Furman, Dusty Phillips, and Jelle Zijlstra.) ::: seealso `519`{.interpreted-text role="pep"} \-- Adding a file system path protocol : PEP written by Brett Cannon and Koos Zevenhoven. ::: ### PEP 495: Local Time Disambiguation {#whatsnew36-pep495} 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. `495`{.interpreted-text role="pep"} adds the new *fold* attribute to instances of `datetime.datetime`{.interpreted-text role="class"} and `datetime.time`{.interpreted-text role="class"} 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 `fold `{.interpreted-text role="attr"} attribute have the value `0` for all instances except those that represent the second (chronologically) moment in time in an ambiguous case. ::: seealso `495`{.interpreted-text role="pep"} \-- Local Time Disambiguation : PEP written by Alexander Belopolsky and Tim Peters, implementation by Alexander Belopolsky. ::: ### PEP 529: Change Windows filesystem encoding to UTF-8 {#whatsnew36-pep529} Representing filesystem paths is best performed with str (Unicode) rather than bytes. However, there are some situations where using bytes is sufficient and correct. Prior to Python 3.6, data loss could result when using bytes paths on Windows. With this change, using bytes to represent paths is now supported on Windows, provided those bytes are encoded with the encoding returned by `sys.getfilesystemencoding`{.interpreted-text role="func"}, which now defaults to `'utf-8'`. Applications that do not use str to represent paths should use `os.fsencode`{.interpreted-text role="func"} and `os.fsdecode`{.interpreted-text role="func"} to ensure their bytes are correctly encoded. To revert to the previous behaviour, set `PYTHONLEGACYWINDOWSFSENCODING`{.interpreted-text role="envvar"} or call `sys._enablelegacywindowsfsencoding`{.interpreted-text role="func"}. See `529`{.interpreted-text role="pep"} for more information and discussion of code modifications that may be required. ### PEP 528: Change Windows console encoding to UTF-8 {#whatsnew36-pep528} The default console on Windows will now accept all Unicode characters and provide correctly read str objects to Python code. `sys.stdin`, `sys.stdout` and `sys.stderr` now default to utf-8 encoding. This change only applies when using an interactive console, and not when redirecting files or pipes. To revert to the previous behaviour for interactive console use, set `PYTHONLEGACYWINDOWSSTDIO`{.interpreted-text role="envvar"}. ::: seealso `528`{.interpreted-text role="pep"} \-- Change Windows console encoding to UTF-8 : PEP written and implemented by Steve Dower. ::: ### PEP 520: Preserving Class Attribute Definition Order {#whatsnew36-pep520} 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 `~type.__dict__`{.interpreted-text role="attr"} attribute. Also, the effective default class *execution* namespace (returned from `type.__prepare__() `{.interpreted-text role="ref"}) is now an insertion-order-preserving mapping. ::: seealso `520`{.interpreted-text role="pep"} \-- Preserving Class Attribute Definition Order : PEP written and implemented by Eric Snow. ::: ### PEP 468: Preserving Keyword Argument Order {#whatsnew36-pep468} `**kwargs` in a function signature is now guaranteed to be an insertion-order-preserving mapping. ::: seealso `468`{.interpreted-text role="pep"} \-- Preserving Keyword Argument Order : PEP written and implemented by Eric Snow. ::: ### New `dict `{.interpreted-text role="ref"} implementation {#whatsnew36-compactdict} The `dict `{.interpreted-text role="ref"} type now uses a \"compact\" representation based on [a proposal by Raymond Hettinger](https://mail.python.org/pipermail/python-dev/2012-December/123028.html) which was [first implemented by PyPy](https://morepypy.blogspot.com/2015/01/faster-more-memory-efficient-and-more.html). The memory usage of the new `dict`{.interpreted-text role="func"} is between 20% and 25% smaller compared to Python 3.5. 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 `27350`{.interpreted-text role="issue"}. Idea [originally suggested by Raymond Hettinger](https://mail.python.org/pipermail/python-dev/2012-December/123028.html).) ### PEP 523: Adding a frame evaluation API to CPython {#whatsnew36-pep523} 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 Python there really wasn\'t any way without directly manipulating function pointers for defined functions. `523`{.interpreted-text role="pep"} changes this by providing an API to make frame evaluation pluggable at the C level. This will allow for tools such as debuggers and JITs to intercept frame evaluation before the execution of Python code begins. This enables the use of alternative evaluation implementations for Python code, tracking frame evaluation, etc. This API is not part of the limited C API and is marked as private to signal that usage of this API is expected to be limited and only applicable to very select, low-level use-cases. Semantics of the API will change with Python as necessary. ::: seealso `523`{.interpreted-text role="pep"} \-- Adding a frame evaluation API to CPython : PEP written by Brett Cannon and Dino Viehland. ::: ### PYTHONMALLOC environment variable {#whatsnew36-pythonmalloc} The new `PYTHONMALLOC`{.interpreted-text role="envvar"} environment variable allows setting the Python memory allocators and installing debug hooks. It is now possible to install debug hooks on Python memory allocators on Python compiled in release mode using `PYTHONMALLOC=debug`. Effects of debug hooks: - Newly allocated memory is filled with the byte `0xCB` - Freed memory is filled with the byte `0xDB` - Detect violations of the Python memory allocator API. For example, `PyObject_Free`{.interpreted-text role="c:func"} called on a memory block allocated by `PyMem_Malloc`{.interpreted-text role="c:func"}. - Detect writes before the start of a buffer (buffer underflows) - Detect writes after the end of a buffer (buffer overflows) - Check that the `GIL `{.interpreted-text role="term"} is held when allocator functions of `PYMEM_DOMAIN_OBJ`{.interpreted-text role="c:macro"} (ex: `PyObject_Malloc`{.interpreted-text role="c:func"}) and `PYMEM_DOMAIN_MEM`{.interpreted-text role="c:macro"} (ex: `PyMem_Malloc`{.interpreted-text role="c:func"}) domains are called. Checking if the GIL is held is also a new feature of Python 3.6. See the `PyMem_SetupDebugHooks`{.interpreted-text role="c:func"} function for debug hooks on Python memory allocators. It is now also possible to force the usage of the `malloc`{.interpreted-text role="c:func"} allocator of the C library for all Python memory allocations using `PYTHONMALLOC=malloc`. This is helpful when using external memory debuggers like Valgrind on a Python compiled in release mode. On error, the debug hooks on Python memory allocators now use the `tracemalloc`{.interpreted-text role="mod"} module to get the traceback where a memory block was allocated. Example of fatal error on buffer overflow using `python3.6 -X tracemalloc=5` (store 5 frames in traces): Debug memory block at address p=0x7fbcd41666f8: API 'o' 4 bytes originally requested The 7 pad bytes at p-7 are FORBIDDENBYTE, as expected. The 8 pad bytes at tail=0x7fbcd41666fc are not all FORBIDDENBYTE (0xfb): at tail+0: 0x02 *** OUCH at tail+1: 0xfb at tail+2: 0xfb at tail+3: 0xfb at tail+4: 0xfb at tail+5: 0xfb at tail+6: 0xfb at tail+7: 0xfb The block was made by call #1233329 to debug malloc/realloc. Data at p: 1a 2b 30 00 Memory block allocated at (most recent call first): File "test/test_bytes.py", line 323 File "unittest/case.py", line 600 File "unittest/case.py", line 648 File "unittest/suite.py", line 122 File "unittest/suite.py", line 84 Fatal Python error: bad trailing pad byte Current thread 0x00007fbcdbd32700 (most recent call first): File "test/test_bytes.py", line 323 in test_hex File "unittest/case.py", line 600 in run File "unittest/case.py", line 648 in __call__ File "unittest/suite.py", line 122 in run File "unittest/suite.py", line 84 in __call__ File "unittest/suite.py", line 122 in run File "unittest/suite.py", line 84 in __call__ ... (Contributed by Victor Stinner in `26516`{.interpreted-text role="issue"} and `26564`{.interpreted-text role="issue"}.) ### DTrace and SystemTap probing support {#whatsnew36-tracing} Python can now be built `--with-dtrace` which enables static markers for the following events in the interpreter: - function call/return - garbage collection started/finished - line of code executed. This can be used to instrument running interpreters in production, without the need to recompile specific `debug builds `{.interpreted-text role="ref"} or providing application-specific profiling/debugging code. More details in `instrumentation`{.interpreted-text role="ref"}. The current implementation is tested on Linux and macOS. Additional markers may be added in the future. (Contributed by Łukasz Langa in `21590`{.interpreted-text role="issue"}, based on patches by Jesús Cea Avión, David Malcolm, and Nikhil Benesch.) ## Other Language Changes Some smaller changes made to the core Python language are: - A `global` or `nonlocal` statement must now textually appear before the first use of the affected name in the same scope. Previously this was a `SyntaxWarning`{.interpreted-text role="exc"}. - It is now possible to set a `special method `{.interpreted-text role="ref"} to `None` to indicate that the corresponding operation is not available. For example, if a class sets `~object.__iter__`{.interpreted-text role="meth"} to `None`, the class is not iterable. (Contributed by Andrew Barnert and Ivan Levkivskyi in `25958`{.interpreted-text role="issue"}.) - Long sequences of repeated traceback lines are now abbreviated as `"[Previous line repeated {count} more times]"` (see `whatsnew36-traceback`{.interpreted-text role="ref"} for an example). (Contributed by Emanuel Barry in `26823`{.interpreted-text role="issue"}.) - Import now raises the new exception `ModuleNotFoundError`{.interpreted-text role="exc"} (subclass of `ImportError`{.interpreted-text role="exc"}) when it cannot find a module. Code that currently checks for ImportError (in try-except) will still work. (Contributed by Eric Snow in `15767`{.interpreted-text role="issue"}.) - Class methods relying on zero-argument `super()` will now work correctly when called from metaclass methods during class creation. (Contributed by Martin Teichmann in `23722`{.interpreted-text role="issue"}.) ## New Modules ### secrets {#whatsnew36-pep506} The main purpose of the new `secrets`{.interpreted-text role="mod"} 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 ::: title Warning ::: Note that the pseudo-random generators in the `random`{.interpreted-text role="mod"} module should *NOT* be used for security purposes. Use `secrets`{.interpreted-text role="mod"} on Python 3.6+ and `os.urandom`{.interpreted-text role="func"} on Python 3.5 and earlier. :::: ::: seealso `506`{.interpreted-text role="pep"} \-- Adding A Secrets Module To The Standard Library : PEP written and implemented by Steven D\'Aprano. ::: ## Improved Modules ### array Exhausted iterators of `array.array`{.interpreted-text role="class"} 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 `26492`{.interpreted-text role="issue"}. ### ast The new `ast.Constant`{.interpreted-text role="class"} AST node has been added. It can be used by external AST optimizers for the purposes of constant folding. Contributed by Victor Stinner in `26146`{.interpreted-text role="issue"}. ### asyncio Starting with Python 3.6 the `asyncio` module is no longer provisional and its API is considered stable. Notable changes in the `asyncio`{.interpreted-text role="mod"} module since Python 3.5.0 (all backported to 3.5.x due to the provisional status): - The `~asyncio.get_event_loop`{.interpreted-text role="func"} function has been changed to always return the currently running loop when called from coroutines and callbacks. (Contributed by Yury Selivanov in `28613`{.interpreted-text role="issue"}.) - The `~asyncio.ensure_future`{.interpreted-text role="func"} function and all functions that use it, such as `loop.run_until_complete() `{.interpreted-text role="meth"}, now accept all kinds of `awaitable objects `{.interpreted-text role="term"}. (Contributed by Yury Selivanov.) - New `~asyncio.run_coroutine_threadsafe`{.interpreted-text role="func"} function to submit coroutines to event loops from other threads. (Contributed by Vincent Michel.) - New `Transport.is_closing() `{.interpreted-text role="meth"} method to check if the transport is closing or closed. (Contributed by Yury Selivanov.) - The `loop.create_server() `{.interpreted-text role="meth"} method can now accept a list of hosts. (Contributed by Yann Sionneau.) - New `loop.create_future() `{.interpreted-text role="meth"} method to create Future objects. This allows alternative event loop implementations, such as [uvloop](https://github.com/MagicStack/uvloop), to provide a faster `asyncio.Future`{.interpreted-text role="class"} implementation. (Contributed by Yury Selivanov in `27041`{.interpreted-text role="issue"}.) - New `loop.get_exception_handler() `{.interpreted-text role="meth"} method to get the current exception handler. (Contributed by Yury Selivanov in `27040`{.interpreted-text role="issue"}.) - New `StreamReader.readuntil() `{.interpreted-text role="meth"} method to read data from the stream until a separator bytes sequence appears. (Contributed by Mark Korenberg.) - The performance of `StreamReader.readexactly() `{.interpreted-text role="meth"} has been improved. (Contributed by Mark Korenberg in `28370`{.interpreted-text role="issue"}.) - The `loop.getaddrinfo() `{.interpreted-text role="meth"} method is optimized to avoid calling the system `getaddrinfo` function if the address is already resolved. (Contributed by A. Jesse Jiryu Davis.) - The `loop.stop() `{.interpreted-text role="meth"} 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 `25593`{.interpreted-text role="issue"}.) - `Future.set_exception `{.interpreted-text role="meth"} will now raise `TypeError`{.interpreted-text role="exc"} when passed an instance of the `StopIteration`{.interpreted-text role="exc"} exception. (Contributed by Chris Angelico in `26221`{.interpreted-text role="issue"}.) - New `loop.connect_accepted_socket() `{.interpreted-text role="meth"} method to be used by servers that accept connections outside of asyncio, but that use asyncio to handle them. (Contributed by Jim Fulton in `27392`{.interpreted-text role="issue"}.) - `TCP_NODELAY` flag is now set for all TCP transports by default. (Contributed by Yury Selivanov in `27456`{.interpreted-text role="issue"}.) - New `loop.shutdown_asyncgens() `{.interpreted-text role="meth"} to properly close pending asynchronous generators before closing the loop. (Contributed by Yury Selivanov in `28003`{.interpreted-text role="issue"}.) - `Future `{.interpreted-text role="class"} and `Task `{.interpreted-text role="class"} classes now have an optimized C implementation which makes asyncio code up to 30% faster. (Contributed by Yury Selivanov and INADA Naoki in `26081`{.interpreted-text role="issue"} and `28544`{.interpreted-text role="issue"}.) ### binascii The `~binascii.b2a_base64`{.interpreted-text role="func"} 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 `25357`{.interpreted-text role="issue"}.) ### cmath The new `cmath.tau`{.interpreted-text role="const"} (*τ*) constant has been added. (Contributed by Lisa Roach in `12345`{.interpreted-text role="issue"}, see `628`{.interpreted-text role="pep"} for details.) New constants: `cmath.inf`{.interpreted-text role="const"} and `cmath.nan`{.interpreted-text role="const"} to match `math.inf`{.interpreted-text role="const"} and `math.nan`{.interpreted-text role="const"}, and also `cmath.infj`{.interpreted-text role="const"} and `cmath.nanj`{.interpreted-text role="const"} to match the format used by complex repr. (Contributed by Mark Dickinson in `23229`{.interpreted-text role="issue"}.) ### collections The new `~collections.abc.Collection`{.interpreted-text role="class"} abstract base class has been added to represent sized iterable container classes. (Contributed by Ivan Levkivskyi, docs by Neil Girdhar in `27598`{.interpreted-text role="issue"}.) The new `~collections.abc.Reversible`{.interpreted-text role="class"} abstract base class represents iterable classes that also provide the `~object.__reversed__`{.interpreted-text role="meth"} method. (Contributed by Ivan Levkivskyi in `25987`{.interpreted-text role="issue"}.) The new `~collections.abc.AsyncGenerator`{.interpreted-text role="class"} abstract base class represents asynchronous generators. (Contributed by Yury Selivanov in `28720`{.interpreted-text role="issue"}.) The `~collections.namedtuple`{.interpreted-text role="func"} function now accepts an optional keyword argument *module*, which, when specified, is used for the `~type.__module__`{.interpreted-text role="attr"} attribute of the returned named tuple class. (Contributed by Raymond Hettinger in `17941`{.interpreted-text role="issue"}.) The *verbose* and *rename* arguments for `~collections.namedtuple`{.interpreted-text role="func"} are now keyword-only. (Contributed by Raymond Hettinger in `25628`{.interpreted-text role="issue"}.) Recursive `collections.deque`{.interpreted-text role="class"} instances can now be pickled. (Contributed by Serhiy Storchaka in `26482`{.interpreted-text role="issue"}.) ### concurrent.futures The `ThreadPoolExecutor `{.interpreted-text role="class"} class constructor now accepts an optional *thread_name_prefix* argument to make it possible to customize the names of the threads created by the pool. (Contributed by Gregory P. Smith in `27664`{.interpreted-text role="issue"}.) ### contextlib The `contextlib.AbstractContextManager`{.interpreted-text role="class"} class has been added to provide an abstract base class for context managers. It provides a sensible default implementation for `__enter__()` which returns `self` and leaves `__exit__()` an abstract method. A matching class has been added to the `typing`{.interpreted-text role="mod"} module as `typing.ContextManager`{.interpreted-text role="class"}. (Contributed by Brett Cannon in `25609`{.interpreted-text role="issue"}.) ### datetime The `~datetime.datetime`{.interpreted-text role="class"} and `~datetime.time`{.interpreted-text role="class"} classes have the new `~datetime.time.fold`{.interpreted-text role="attr"} attribute used to disambiguate local time when necessary. Many functions in the `datetime`{.interpreted-text role="mod"} have been updated to support local time disambiguation. See `Local Time Disambiguation `{.interpreted-text role="ref"} section for more information. (Contributed by Alexander Belopolsky in `24773`{.interpreted-text role="issue"}.) The `datetime.strftime() `{.interpreted-text role="meth"} and `date.strftime() `{.interpreted-text role="meth"} methods now support ISO 8601 date directives `%G`, `%u` and `%V`. (Contributed by Ashley Anderson in `12006`{.interpreted-text role="issue"}.) The `datetime.isoformat() `{.interpreted-text role="func"} 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 `19475`{.interpreted-text role="issue"}.) The `datetime.combine() `{.interpreted-text role="meth"} now accepts an optional *tzinfo* argument. (Contributed by Alexander Belopolsky in `27661`{.interpreted-text role="issue"}.) ### decimal New `Decimal.as_integer_ratio() `{.interpreted-text role="meth"} method that returns a pair `(n, d)` of integers that represent the given `~decimal.Decimal`{.interpreted-text role="class"} instance as a fraction, in lowest terms and with a positive denominator: >>> Decimal('-3.14').as_integer_ratio() (-157, 50) (Contributed by Stefan Krah amd Mark Dickinson in `25928`{.interpreted-text role="issue"}.) ### distutils The `default_format` attribute has been removed from `distutils.command.sdist.sdist` and the `formats` attribute defaults to `['gztar']`. Although not anticipated, any code relying on the presence of `default_format` may need to be adapted. See `27819`{.interpreted-text role="issue"} for more details. ### email The new email API, enabled via the *policy* keyword to various constructors, is no longer provisional. The `email`{.interpreted-text role="mod"} documentation has been reorganized and rewritten to focus on the new API, while retaining the old documentation for the legacy API. (Contributed by R. David Murray in `24277`{.interpreted-text role="issue"}.) The `email.mime`{.interpreted-text role="mod"} classes now all accept an optional *policy* keyword. (Contributed by Berker Peksag in `27331`{.interpreted-text role="issue"}.) The `~email.generator.DecodedGenerator`{.interpreted-text role="class"} now supports the *policy* keyword. There is a new `~email.policy`{.interpreted-text role="mod"} attribute, `~email.policy.Policy.message_factory`{.interpreted-text role="attr"}, that controls what class is used by default when the parser creates new message objects. For the `email.policy.compat32`{.interpreted-text role="attr"} policy this is `~email.message.Message`{.interpreted-text role="class"}, for the new policies it is `~email.message.EmailMessage`{.interpreted-text role="class"}. (Contributed by R. David Murray in `20476`{.interpreted-text role="issue"}.) ### 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 `27959`{.interpreted-text role="issue"}.) ### enum Two new enumeration base classes have been added to the `enum`{.interpreted-text role="mod"} module: `~enum.Flag`{.interpreted-text role="class"} and `~enum.IntFlag`{.interpreted-text role="class"}. Both are used to define constants that can be combined using the bitwise operators. (Contributed by Ethan Furman in `23591`{.interpreted-text role="issue"}.) Many standard library modules have been updated to use the `~enum.IntFlag`{.interpreted-text role="class"} class for their constants. The new `enum.auto`{.interpreted-text role="class"} 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 On Windows, the `faulthandler`{.interpreted-text role="mod"} module now installs a handler for Windows exceptions: see `faulthandler.enable`{.interpreted-text role="func"}. (Contributed by Victor Stinner in `23848`{.interpreted-text role="issue"}.) ### fileinput `~fileinput.hook_encoded`{.interpreted-text role="func"} now supports the *errors* argument. (Contributed by Joseph Hackman in `25788`{.interpreted-text role="issue"}.) ### hashlib `hashlib`{.interpreted-text role="mod"} supports OpenSSL 1.1.0. The minimum recommend version is 1.0.2. (Contributed by Christian Heimes in `26470`{.interpreted-text role="issue"}.) BLAKE2 hash functions were added to the module. `~hashlib.blake2b`{.interpreted-text role="func"} and `~hashlib.blake2s`{.interpreted-text role="func"} are always available and support the full feature set of BLAKE2. (Contributed by Christian Heimes in `26798`{.interpreted-text role="issue"} based on code by Dmitry Chestnykh and Samuel Neves. Documentation written by Dmitry Chestnykh.) The SHA-3 hash functions `~hashlib.sha3_224`{.interpreted-text role="func"}, `~hashlib.sha3_256`{.interpreted-text role="func"}, `~hashlib.sha3_384`{.interpreted-text role="func"}, `~hashlib.sha3_512`{.interpreted-text role="func"}, and SHAKE hash functions `~hashlib.shake_128`{.interpreted-text role="func"} and `~hashlib.shake_256`{.interpreted-text role="func"} were added. (Contributed by Christian Heimes in `16113`{.interpreted-text role="issue"}. Keccak Code Package by Guido Bertoni, Joan Daemen, Michaël Peeters, Gilles Van Assche, and Ronny Van Keer.) The password-based key derivation function `~hashlib.scrypt`{.interpreted-text role="func"} is now available with OpenSSL 1.1.0 and newer. (Contributed by Christian Heimes in `27928`{.interpreted-text role="issue"}.) ### http.client `HTTPConnection.request() `{.interpreted-text role="meth"} and `~http.client.HTTPConnection.endheaders`{.interpreted-text role="meth"} both now support chunked encoding request bodies. (Contributed by Demian Brecht and Rolf Krahl in `12319`{.interpreted-text role="issue"}.) ### 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. \'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 `24225`{.interpreted-text role="issue"}. 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. New in 3.6.2: Multiple fixes for autocompletion. (Contributed by Louie Lu in `15786`{.interpreted-text role="issue"}.) New in 3.6.3: Module Browser (on the File menu, formerly called Class Browser), now displays nested functions and classes in addition to top-level functions and classes. (Contributed by Guilherme Polo, Cheryl Sabella, and Terry Jan Reedy in `1612262`{.interpreted-text role="issue"}.) The IDLE features formerly implemented as extensions have been reimplemented as normal features. Their settings have been moved from the Extensions tab to other dialog tabs. (Contributed by Charles Wohlganger and Terry Jan Reedy in `27099`{.interpreted-text role="issue"}.) The Settings dialog (Options, Configure IDLE) has been partly rewritten to improve both appearance and function. (Contributed by Cheryl Sabella and Terry Jan Reedy in multiple issues.) New in 3.6.4: The font sample now includes a selection of non-Latin characters so that users can better see the effect of selecting a particular font. (Contributed by Terry Jan Reedy in `13802`{.interpreted-text role="issue"}.) The sample can be edited to include other characters. (Contributed by Serhiy Storchaka in `31860`{.interpreted-text role="issue"}.) New in 3.6.6: Editor code context option revised. Box displays all context lines up to maxlines. Clicking on a context line jumps the editor to that line. Context colors for custom themes is added to Highlights tab of Settings dialog. (Contributed by Cheryl Sabella and Terry Jan Reedy in `33642`{.interpreted-text role="issue"}, `33768`{.interpreted-text role="issue"}, and `33679`{.interpreted-text role="issue"}.) On Windows, a new API call tells Windows that tk scales for DPI. On Windows 8.1+ or 10, with DPI compatibility properties of the Python binary unchanged, and a monitor resolution greater than 96 DPI, this should make text and lines sharper. It should otherwise have no effect. (Contributed by Terry Jan Reedy in `33656`{.interpreted-text role="issue"}.) New in 3.6.7: Output over N lines (50 by default) is squeezed down to a button. N can be changed in the PyShell section of the General page of the Settings dialog. Fewer, but possibly extra long, lines can be squeezed by right clicking on the output. Squeezed output can be expanded in place by double-clicking the button or into the clipboard or a separate window by right-clicking the button. (Contributed by Tal Einat in `1529353`{.interpreted-text role="issue"}.) ### importlib Import now raises the new exception `ModuleNotFoundError`{.interpreted-text role="exc"} (subclass of `ImportError`{.interpreted-text role="exc"}) when it cannot find a module. Code that current checks for `ImportError` (in try-except) will still work. (Contributed by Eric Snow in `15767`{.interpreted-text role="issue"}.) `importlib.util.LazyLoader`{.interpreted-text role="class"} now calls `~importlib.abc.Loader.create_module`{.interpreted-text role="meth"} on the wrapped loader, removing the restriction that `importlib.machinery.BuiltinImporter`{.interpreted-text role="class"} and `importlib.machinery.ExtensionFileLoader`{.interpreted-text role="class"} couldn\'t be used with `importlib.util.LazyLoader`{.interpreted-text role="class"}. `importlib.util.cache_from_source`{.interpreted-text role="func"}, `importlib.util.source_from_cache`{.interpreted-text role="func"}, and `importlib.util.spec_from_file_location`{.interpreted-text role="func"} now accept a `path-like object`{.interpreted-text role="term"}. ### inspect The `inspect.signature() `{.interpreted-text role="func"} 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 `19611`{.interpreted-text role="issue"}.) To reduce code churn when upgrading from Python 2.7 and the legacy `!inspect.getargspec`{.interpreted-text role="func"} API, the previously documented deprecation of `inspect.getfullargspec`{.interpreted-text role="func"} has been reversed. While this function is convenient for single/source Python 2/3 code bases, the richer `inspect.signature`{.interpreted-text role="func"} interface remains the recommended approach for new code. (Contributed by Nick Coghlan in `27172`{.interpreted-text role="issue"}) ### json `json.load`{.interpreted-text role="func"} and `json.loads`{.interpreted-text role="func"} now support binary input. Encoded JSON should be represented using either UTF-8, UTF-16, or UTF-32. (Contributed by Serhiy Storchaka in `17909`{.interpreted-text role="issue"}.) ### logging The new `WatchedFileHandler.reopenIfNeeded() `{.interpreted-text role="meth"} method has been added to add the ability to check if the log file needs to be reopened. (Contributed by Marian Horban in `24884`{.interpreted-text role="issue"}.) ### math The tau (*τ*) constant has been added to the `math`{.interpreted-text role="mod"} and `cmath`{.interpreted-text role="mod"} modules. (Contributed by Lisa Roach in `12345`{.interpreted-text role="issue"}, see `628`{.interpreted-text role="pep"} for details.) ### multiprocessing `Proxy Objects `{.interpreted-text role="ref"} returned by `multiprocessing.Manager`{.interpreted-text role="func"} can now be nested. (Contributed by Davin Potts in `6766`{.interpreted-text role="issue"}.) ### os See the summary of `PEP 519 `{.interpreted-text role="ref"} for details on how the `os`{.interpreted-text role="mod"} and `os.path`{.interpreted-text role="mod"} modules now support `path-like objects `{.interpreted-text role="term"}. `~os.scandir`{.interpreted-text role="func"} now supports `bytes`{.interpreted-text role="class"} paths on Windows. A new `~os.scandir.close`{.interpreted-text role="meth"} method allows explicitly closing a `~os.scandir`{.interpreted-text role="func"} iterator. The `~os.scandir`{.interpreted-text role="func"} iterator now supports the `context manager`{.interpreted-text role="term"} protocol. If a `!scandir`{.interpreted-text role="func"} iterator is neither exhausted nor explicitly closed a `ResourceWarning`{.interpreted-text role="exc"} will be emitted in its destructor. (Contributed by Serhiy Storchaka in `25994`{.interpreted-text role="issue"}.) On Linux, `os.urandom`{.interpreted-text role="func"} now blocks until the system urandom entropy pool is initialized to increase the security. See the `524`{.interpreted-text role="pep"} for the rationale. The Linux `getrandom()` syscall (get random bytes) is now exposed as the new `os.getrandom`{.interpreted-text role="func"} function. (Contributed by Victor Stinner, part of the `524`{.interpreted-text role="pep"}) ### pathlib `pathlib`{.interpreted-text role="mod"} now supports `path-like objects `{.interpreted-text role="term"}. (Contributed by Brett Cannon in `27186`{.interpreted-text role="issue"}.) See the summary of `PEP 519 `{.interpreted-text role="ref"} for details. ### pdb The `~pdb.Pdb`{.interpreted-text role="class"} class constructor has a new optional *readrc* argument to control whether `.pdbrc` files should be read. ### pickle Objects that need `__new__` called with keyword arguments can now be pickled using `pickle protocols `{.interpreted-text role="ref"} older than protocol version 4. Protocol version 4 already supports this case. (Contributed by Serhiy Storchaka in `24164`{.interpreted-text role="issue"}.) ### pickletools `pickletools.dis`{.interpreted-text role="func"} now outputs the implicit memo index for the `MEMOIZE` opcode. (Contributed by Serhiy Storchaka in `25382`{.interpreted-text role="issue"}.) ### pydoc The `pydoc`{.interpreted-text role="mod"} module has learned to respect the `MANPAGER` environment variable. (Contributed by Matthias Klose in `8637`{.interpreted-text role="issue"}.) `help`{.interpreted-text role="func"} and `pydoc`{.interpreted-text role="mod"} can now list named tuple fields in the order they were defined rather than alphabetically. (Contributed by Raymond Hettinger in `24879`{.interpreted-text role="issue"}.) ### random The new `~random.choices`{.interpreted-text role="func"} function returns a list of elements of specified size from the given population with optional weights. (Contributed by Raymond Hettinger in `18844`{.interpreted-text role="issue"}.) ### re Added support of modifier spans in regular expressions. Examples: `'(?i:p)ython'` matches `'python'` and `'Python'`, but not `'PYTHON'`; `'(?i)g(?-i:v)r'` matches `'GvR'` and `'gvr'`, but not `'GVR'`. (Contributed by Serhiy Storchaka in `433028`{.interpreted-text role="issue"}.) 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 `24454`{.interpreted-text role="issue"}.) `~re.Match`{.interpreted-text role="class"} objects now support `index-like objects `{.interpreted-text role="meth"} as group indices. (Contributed by Jeroen Demeyer and Xiang Zhang in `27177`{.interpreted-text role="issue"}.) ### readline Added `~readline.set_auto_history`{.interpreted-text role="func"} to enable or disable automatic addition of input to the history list. (Contributed by Tyler Crompton in `26870`{.interpreted-text role="issue"}.) ### rlcompleter Private and special attribute names now are omitted unless the prefix starts with underscores. A space or a colon is added after some completed keywords. (Contributed by Serhiy Storchaka in `25011`{.interpreted-text role="issue"} and `25209`{.interpreted-text role="issue"}.) ### shlex The `~shlex.shlex`{.interpreted-text role="class"} has much `improved shell compatibility `{.interpreted-text role="ref"} through the new *punctuation_chars* argument to control which characters are treated as punctuation. (Contributed by Vinay Sajip in `1521950`{.interpreted-text role="issue"}.) ### site When specifying paths to add to `sys.path`{.interpreted-text role="data"} in a `.pth` file, you may now specify file paths on top of directories (e.g. zip files). (Contributed by Wolfgang Langner in `26587`{.interpreted-text role="issue"}). ### sqlite3 `sqlite3.Cursor.lastrowid`{.interpreted-text role="attr"} now supports the `REPLACE` statement. (Contributed by Alex LordThorsen in `16864`{.interpreted-text role="issue"}.) ### socket The `~socket.socket.ioctl`{.interpreted-text role="func"} function now supports the `~socket.SIO_LOOPBACK_FAST_PATH`{.interpreted-text role="const"} control code. (Contributed by Daniel Stokes in `26536`{.interpreted-text role="issue"}.) The `~socket.socket.getsockopt`{.interpreted-text role="meth"} constants `SO_DOMAIN`, `SO_PROTOCOL`, `SO_PEERSEC`, and `SO_PASSSEC` are now supported. (Contributed by Christian Heimes in `26907`{.interpreted-text role="issue"}.) The `~socket.socket.setsockopt`{.interpreted-text role="meth"} now supports the `setsockopt(level, optname, None, optlen: int)` form. (Contributed by Christian Heimes in `27744`{.interpreted-text role="issue"}.) The socket module now supports the address family `~socket.AF_ALG`{.interpreted-text role="const"} to interface with Linux Kernel crypto API. `ALG_*`, `SOL_ALG` and `~socket.socket.sendmsg_afalg`{.interpreted-text role="meth"} were added. (Contributed by Christian Heimes in `27744`{.interpreted-text role="issue"} with support from Victor Stinner.) New Linux constants `TCP_USER_TIMEOUT` and `TCP_CONGESTION` were added. (Contributed by Omar Sandoval, `26273`{.interpreted-text role="issue"}). ### socketserver Servers based on the `socketserver`{.interpreted-text role="mod"} module, including those defined in `http.server`{.interpreted-text role="mod"}, `xmlrpc.server`{.interpreted-text role="mod"} and `wsgiref.simple_server`{.interpreted-text role="mod"}, now support the `context manager`{.interpreted-text role="term"} protocol. (Contributed by Aviv Palivoda in `26404`{.interpreted-text role="issue"}.) The `wfile `{.interpreted-text role="attr"} attribute of `~socketserver.StreamRequestHandler`{.interpreted-text role="class"} classes now implements the `io.BufferedIOBase`{.interpreted-text role="class"} writable interface. In particular, calling `~io.BufferedIOBase.write`{.interpreted-text role="meth"} is now guaranteed to send the data in full. (Contributed by Martin Panter in `26721`{.interpreted-text role="issue"}.) ### ssl `ssl`{.interpreted-text role="mod"} supports OpenSSL 1.1.0. The minimum recommend version is 1.0.2. (Contributed by Christian Heimes in `26470`{.interpreted-text role="issue"}.) 3DES has been removed from the default cipher suites and ChaCha20 Poly1305 cipher suites have been added. (Contributed by Christian Heimes in `27850`{.interpreted-text role="issue"} and `27766`{.interpreted-text role="issue"}.) `~ssl.SSLContext`{.interpreted-text role="class"} has better default configuration for options and ciphers. (Contributed by Christian Heimes in `28043`{.interpreted-text role="issue"}.) SSL session can be copied from one client-side connection to another with the new `~ssl.SSLSession`{.interpreted-text role="class"} class. TLS session resumption can speed up the initial handshake, reduce latency and improve performance (Contributed by Christian Heimes in `19500`{.interpreted-text role="issue"} based on a draft by Alex Warhawk.) The new `~ssl.SSLContext.get_ciphers`{.interpreted-text role="meth"} method can be used to get a list of enabled ciphers in order of cipher priority. All constants and flags have been converted to `~enum.IntEnum`{.interpreted-text role="class"} and `~enum.IntFlag`{.interpreted-text role="class"}. (Contributed by Christian Heimes in `28025`{.interpreted-text role="issue"}.) Server and client-side specific TLS protocols for `~ssl.SSLContext`{.interpreted-text role="class"} were added. (Contributed by Christian Heimes in `28085`{.interpreted-text role="issue"}.) Added `ssl.SSLContext.post_handshake_auth`{.interpreted-text role="attr"} to enable and `ssl.SSLSocket.verify_client_post_handshake`{.interpreted-text role="meth"} to initiate TLS 1.3 post-handshake authentication. (Contributed by Christian Heimes in `78851`{.interpreted-text role="gh"}.) ### statistics A new `~statistics.harmonic_mean`{.interpreted-text role="func"} function has been added. (Contributed by Steven D\'Aprano in `27181`{.interpreted-text role="issue"}.) ### struct `struct`{.interpreted-text role="mod"} now supports IEEE 754 half-precision floats via the `'e'` format specifier. (Contributed by Eli Stevens, Mark Dickinson in `11734`{.interpreted-text role="issue"}.) ### subprocess `subprocess.Popen`{.interpreted-text role="class"} destructor now emits a `ResourceWarning`{.interpreted-text role="exc"} warning if the child process is still running. Use the context manager protocol (`with proc: ...`) or explicitly call the `~subprocess.Popen.wait`{.interpreted-text role="meth"} method to read the exit status of the child process. (Contributed by Victor Stinner in `26741`{.interpreted-text role="issue"}.) The `subprocess.Popen`{.interpreted-text role="class"} 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 `6135`{.interpreted-text role="issue"}.) ### sys The new `~sys.getfilesystemencodeerrors`{.interpreted-text role="func"} function returns the name of the error mode used to convert between Unicode filenames and bytes filenames. (Contributed by Steve Dower in `27781`{.interpreted-text role="issue"}.) On Windows the return value of the `~sys.getwindowsversion`{.interpreted-text role="func"} 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 `27932`{.interpreted-text role="issue"}.) ### telnetlib `!telnetlib.Telnet`{.interpreted-text role="class"} is now a context manager (contributed by Stéphane Wirtel in `25485`{.interpreted-text role="issue"}). ### time The `~time.struct_time`{.interpreted-text role="class"} attributes `!tm_gmtoff`{.interpreted-text role="attr"} and `!tm_zone`{.interpreted-text role="attr"} are now available on all platforms. ### timeit The new `Timer.autorange() `{.interpreted-text role="meth"} convenience method has been added to call `Timer.timeit() `{.interpreted-text role="meth"} repeatedly so that the total run time is greater or equal to 200 milliseconds. (Contributed by Steven D\'Aprano in `6422`{.interpreted-text role="issue"}.) `timeit`{.interpreted-text role="mod"} now warns when there is substantial (4x) variance between best and worst times. (Contributed by Serhiy Storchaka in `23552`{.interpreted-text role="issue"}.) ### tkinter Added methods `!Variable.trace_add`{.interpreted-text role="meth"}, `!Variable.trace_remove`{.interpreted-text role="meth"} and `!trace_info`{.interpreted-text role="meth"} in the `!tkinter.Variable`{.interpreted-text role="class"} class. They replace old methods `!trace_variable`{.interpreted-text role="meth"}, `!trace`{.interpreted-text role="meth"}, `!trace_vdelete`{.interpreted-text role="meth"} and `!trace_vinfo`{.interpreted-text role="meth"} that use obsolete Tcl commands and might not work in future versions of Tcl. (Contributed by Serhiy Storchaka in `22115`{.interpreted-text role="issue"}). ### traceback {#whatsnew36-traceback} Both the traceback module and the interpreter\'s builtin exception display now abbreviate long sequences of repeated lines in tracebacks as shown in the following example: >>> def f(): f() ... >>> f() Traceback (most recent call last): File "", line 1, in File "", line 1, in f File "", line 1, in f File "", line 1, in f [Previous line repeated 995 more times] RecursionError: maximum recursion depth exceeded (Contributed by Emanuel Barry in `26823`{.interpreted-text role="issue"}.) ### tracemalloc The `tracemalloc`{.interpreted-text role="mod"} module now supports tracing memory allocations in multiple different address spaces. The new `~tracemalloc.DomainFilter`{.interpreted-text role="class"} filter class has been added to filter block traces by their address space (domain). (Contributed by Victor Stinner in `26588`{.interpreted-text role="issue"}.) ### typing {#whatsnew36-typing} Since the `typing`{.interpreted-text role="mod"} module is `provisional `{.interpreted-text role="term"}, all changes introduced in Python 3.6 have also been backported to Python 3.5.x. The `typing`{.interpreted-text role="mod"} module has a much improved support for generic type aliases. For example `Dict[str, Tuple[S, T]]` is now a valid type annotation. (Contributed by Guido van Rossum in [Github #195](https://github.com/python/typing/pull/195).) The `typing.ContextManager`{.interpreted-text role="class"} class has been added for representing `contextlib.AbstractContextManager`{.interpreted-text role="class"}. (Contributed by Brett Cannon in `25609`{.interpreted-text role="issue"}.) The `typing.Collection`{.interpreted-text role="class"} class has been added for representing `collections.abc.Collection`{.interpreted-text role="class"}. (Contributed by Ivan Levkivskyi in `27598`{.interpreted-text role="issue"}.) The `typing.ClassVar`{.interpreted-text role="const"} type construct has been added to mark class variables. As introduced in `526`{.interpreted-text role="pep"}, 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](https://github.com/python/typing/pull/280).) A new `~typing.TYPE_CHECKING`{.interpreted-text role="const"} constant that is assumed to be `True` by the static type checkers, but is `False` at runtime. (Contributed by Guido van Rossum in [Github #230](https://github.com/python/typing/issues/230).) A new `~typing.NewType`{.interpreted-text role="func"} 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](https://github.com/python/typing/issues/189).) ### unicodedata The `unicodedata`{.interpreted-text role="mod"} module now uses data from [Unicode 9.0.0](https://unicode.org/versions/Unicode9.0.0/). (Contributed by Benjamin Peterson.) ### unittest.mock The `~unittest.mock.Mock`{.interpreted-text role="class"} class has the following improvements: - Two new methods, `Mock.assert_called() `{.interpreted-text role="meth"} and `Mock.assert_called_once() `{.interpreted-text role="meth"} to check if the mock object was called. (Contributed by Amit Saha in `26323`{.interpreted-text role="issue"}.) - The `Mock.reset_mock() `{.interpreted-text role="meth"} method now has two optional keyword only arguments: *return_value* and *side_effect*. (Contributed by Kushal Das in `21271`{.interpreted-text role="issue"}.) ### urllib.request If a HTTP request has a file or iterable body (other than a bytes object) but no `Content-Length` header, rather than throwing an error, `AbstractHTTPHandler `{.interpreted-text role="class"} now falls back to use chunked transfer encoding. (Contributed by Demian Brecht and Rolf Krahl in `12319`{.interpreted-text role="issue"}.) ### urllib.robotparser `~urllib.robotparser.RobotFileParser`{.interpreted-text role="class"} now supports the `Crawl-delay` and `Request-rate` extensions. (Contributed by Nikolay Bogoychev in `16099`{.interpreted-text role="issue"}.) ### venv `venv`{.interpreted-text role="mod"} 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 `22829`{.interpreted-text role="issue"}.) ### warnings A new optional *source* parameter has been added to the `warnings.warn_explicit`{.interpreted-text role="func"} function: the destroyed object which emitted a `ResourceWarning`{.interpreted-text role="exc"}. A *source* attribute has also been added to `!warnings.WarningMessage`{.interpreted-text role="class"} (contributed by Victor Stinner in `26568`{.interpreted-text role="issue"} and `26567`{.interpreted-text role="issue"}). When a `ResourceWarning`{.interpreted-text role="exc"} warning is logged, the `tracemalloc`{.interpreted-text role="mod"} module is now used to try to retrieve the traceback where the destroyed object was allocated. Example with the script `example.py`: import warnings def func(): return open(__file__) f = func() f = None Output of the command `python3.6 -Wd -X tracemalloc=5 example.py`: example.py:7: ResourceWarning: unclosed file <_io.TextIOWrapper name='example.py' mode='r' encoding='UTF-8'> f = None Object allocated at (most recent call first): File "example.py", lineno 4 return open(__file__) File "example.py", lineno 6 f = func() The \"Object allocated at\" traceback is new and is only displayed if `tracemalloc`{.interpreted-text role="mod"} is tracing Python memory allocations and if the `warnings`{.interpreted-text role="mod"} module was already imported. ### winreg Added the 64-bit integer type `REG_QWORD `{.interpreted-text role="data"}. (Contributed by Clement Rouault in `23026`{.interpreted-text role="issue"}.) ### winsound Allowed keyword arguments to be passed to `Beep `{.interpreted-text role="func"}, `MessageBeep `{.interpreted-text role="func"}, and `PlaySound `{.interpreted-text role="func"} (`27982`{.interpreted-text role="issue"}). ### xmlrpc.client The `xmlrpc.client`{.interpreted-text role="mod"} module now supports unmarshalling additional data types used by the Apache XML-RPC implementation for numerics and `None`. (Contributed by Serhiy Storchaka in `26885`{.interpreted-text role="issue"}.) ### zipfile A new `ZipInfo.from_file() `{.interpreted-text role="meth"} class method allows making a `~zipfile.ZipInfo`{.interpreted-text role="class"} instance from a filesystem file. A new `ZipInfo.is_dir() `{.interpreted-text role="meth"} method can be used to check if the `~zipfile.ZipInfo`{.interpreted-text role="class"} instance represents a directory. (Contributed by Thomas Kluyver in `26039`{.interpreted-text role="issue"}.) The `ZipFile.open() `{.interpreted-text role="meth"} method can now be used to write data into a ZIP file, as well as for extracting data. (Contributed by Thomas Kluyver in `26039`{.interpreted-text role="issue"}.) ### zlib The `~zlib.compress`{.interpreted-text role="func"} and `~zlib.decompress`{.interpreted-text role="func"} functions now accept keyword arguments. (Contributed by Aviv Palivoda in `26243`{.interpreted-text role="issue"} and Xiang Zhang in `16764`{.interpreted-text role="issue"} respectively.) ## Optimizations - The Python interpreter now uses a 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 `26647`{.interpreted-text role="issue"} and `28050`{.interpreted-text role="issue"}.) - The `asyncio.Future`{.interpreted-text role="class"} class now has an optimized C implementation. (Contributed by Yury Selivanov and INADA Naoki in `26081`{.interpreted-text role="issue"}.) - The `asyncio.Task`{.interpreted-text role="class"} class now has an optimized C implementation. (Contributed by Yury Selivanov in `28544`{.interpreted-text role="issue"}.) - Various implementation improvements in the `typing`{.interpreted-text role="mod"} module (such as caching of generic types) allow up to 30 times performance improvements and reduced memory footprint. - The ASCII decoder is now up to 60 times as fast for error handlers `surrogateescape`, `ignore` and `replace` (Contributed by Victor Stinner in `24870`{.interpreted-text role="issue"}). - The ASCII and the Latin1 encoders are now up to 3 times as fast for the error handler `surrogateescape` (Contributed by Victor Stinner in `25227`{.interpreted-text role="issue"}). - The UTF-8 encoder is now up to 75 times as fast for error handlers `ignore`, `replace`, `surrogateescape`, `surrogatepass` (Contributed by Victor Stinner in `25267`{.interpreted-text role="issue"}). - The UTF-8 decoder is now up to 15 times as fast for error handlers `ignore`, `replace` and `surrogateescape` (Contributed by Victor Stinner in `25301`{.interpreted-text role="issue"}). - `bytes % args` is now up to 2 times faster. (Contributed by Victor Stinner in `25349`{.interpreted-text role="issue"}). - `bytearray % args` is now between 2.5 and 5 times faster. (Contributed by Victor Stinner in `25399`{.interpreted-text role="issue"}). - Optimize `bytes.fromhex`{.interpreted-text role="meth"} and `bytearray.fromhex`{.interpreted-text role="meth"}: they are now between 2x and 3.5x faster. (Contributed by Victor Stinner in `25401`{.interpreted-text role="issue"}). - Optimize `bytes.replace(b'', b'.')` and `bytearray.replace(b'', b'.')`: up to 80% faster. (Contributed by Josh Snider in `26574`{.interpreted-text role="issue"}). - Allocator functions of the `PyMem_Malloc`{.interpreted-text role="c:func"} domain (`PYMEM_DOMAIN_MEM`{.interpreted-text role="c:macro"}) now use the `pymalloc memory allocator `{.interpreted-text role="ref"} instead of `malloc`{.interpreted-text role="c:func"} function of the C library. The pymalloc allocator is optimized for objects smaller or equal to 512 bytes with a short lifetime, and use `malloc`{.interpreted-text role="c:func"} for larger memory blocks. (Contributed by Victor Stinner in `26249`{.interpreted-text role="issue"}). - `pickle.load`{.interpreted-text role="func"} and `pickle.loads`{.interpreted-text role="func"} are now up to 10% faster when deserializing many small objects (Contributed by Victor Stinner in `27056`{.interpreted-text role="issue"}). - Passing `keyword arguments `{.interpreted-text role="term"} to a function has an overhead in comparison with passing `positional arguments `{.interpreted-text role="term"}. Now in extension functions implemented with using Argument Clinic this overhead is significantly decreased. (Contributed by Serhiy Storchaka in `27574`{.interpreted-text role="issue"}). - Optimized `~glob.glob`{.interpreted-text role="func"} and `~glob.iglob`{.interpreted-text role="func"} functions in the `glob`{.interpreted-text role="mod"} module; they are now about 3\--6 times faster. (Contributed by Serhiy Storchaka in `25596`{.interpreted-text role="issue"}). - Optimized globbing in `pathlib`{.interpreted-text role="mod"} by using `os.scandir`{.interpreted-text role="func"}; it is now about 1.5\--4 times faster. (Contributed by Serhiy Storchaka in `26032`{.interpreted-text role="issue"}). - `xml.etree.ElementTree`{.interpreted-text role="class"} parsing, iteration and deepcopy performance has been significantly improved. (Contributed by Serhiy Storchaka in `25638`{.interpreted-text role="issue"}, `25873`{.interpreted-text role="issue"}, and `25869`{.interpreted-text role="issue"}.) - Creation of `fractions.Fraction`{.interpreted-text role="class"} instances from floats and decimals is now 2 to 3 times faster. (Contributed by Serhiy Storchaka in `25971`{.interpreted-text role="issue"}.) ## Build and C API Changes - 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 `7`{.interpreted-text role="pep"} and `17884`{.interpreted-text role="issue"}. - Cross-compiling CPython with the Android NDK and the Android API level set to 21 (Android 5.0 Lollipop) or greater runs successfully. While Android is not yet a supported platform, the Python test suite runs on the Android emulator with only about 16 tests failures. See the Android meta-issue `26865`{.interpreted-text role="issue"}. - The `--enable-optimizations` configure flag has been added. Turning it on will activate expensive optimizations like PGO. (Original patch by Alecsandru Patrascu of Intel in `26359`{.interpreted-text role="issue"}.) - The `GIL `{.interpreted-text role="term"} must now be held when allocator functions of `PYMEM_DOMAIN_OBJ`{.interpreted-text role="c:macro"} (ex: `PyObject_Malloc`{.interpreted-text role="c:func"}) and `PYMEM_DOMAIN_MEM`{.interpreted-text role="c:macro"} (ex: `PyMem_Malloc`{.interpreted-text role="c:func"}) domains are called. - New `Py_FinalizeEx`{.interpreted-text role="c:func"} API which indicates if flushing buffered data failed. (Contributed by Martin Panter in `5319`{.interpreted-text role="issue"}.) - `PyArg_ParseTupleAndKeywords`{.interpreted-text role="c:func"} now supports `positional-only parameters `{.interpreted-text role="ref"}. Positional-only parameters are defined by empty names. (Contributed by Serhiy Storchaka in `26282`{.interpreted-text role="issue"}). - `PyTraceback_Print` method now abbreviates long sequences of repeated lines as `"[Previous line repeated {count} more times]"`. (Contributed by Emanuel Barry in `26823`{.interpreted-text role="issue"}.) - The new `PyErr_SetImportErrorSubclass`{.interpreted-text role="c:func"} function allows for specifying a subclass of `ImportError`{.interpreted-text role="exc"} to raise. (Contributed by Eric Snow in `15767`{.interpreted-text role="issue"}.) - The new `PyErr_ResourceWarning`{.interpreted-text role="c:func"} function can be used to generate a `ResourceWarning`{.interpreted-text role="exc"} providing the source of the resource allocation. (Contributed by Victor Stinner in `26567`{.interpreted-text role="issue"}.) - The new `PyOS_FSPath`{.interpreted-text role="c:func"} function returns the file system representation of a `path-like object`{.interpreted-text role="term"}. (Contributed by Brett Cannon in `27186`{.interpreted-text role="issue"}.) - The `PyUnicode_FSConverter`{.interpreted-text role="c:func"} and `PyUnicode_FSDecoder`{.interpreted-text role="c:func"} functions will now accept `path-like objects `{.interpreted-text role="term"}. ## Other Improvements - When `--version`{.interpreted-text role="option"} (short form: `-V`{.interpreted-text role="option"}) is supplied twice, Python prints `sys.version`{.interpreted-text role="data"} for detailed information. ``` shell-session $ ./python -VV Python 3.6.0b4+ (3.6:223967b49e49+, Nov 21 2016, 20:55:04) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] ``` ## Deprecated ### New Keywords `async` and `await` are not recommended to be used as variable, class, function or module names. Introduced by `492`{.interpreted-text role="pep"} in Python 3.5, they will become proper keywords in Python 3.7. Starting in Python 3.6, the use of `async` or `await` as names will generate a `DeprecationWarning`{.interpreted-text role="exc"}. ### Deprecated Python behavior Raising the `StopIteration`{.interpreted-text role="exc"} exception inside a generator will now generate a `DeprecationWarning`{.interpreted-text role="exc"}, and will trigger a `RuntimeError`{.interpreted-text role="exc"} in Python 3.7. See `whatsnew-pep-479`{.interpreted-text role="ref"} for details. The `~object.__aiter__`{.interpreted-text role="meth"} method is now expected to return an asynchronous iterator directly instead of returning an awaitable as previously. Doing the former will trigger a `DeprecationWarning`{.interpreted-text role="exc"}. Backward compatibility will be removed in Python 3.7. (Contributed by Yury Selivanov in `27243`{.interpreted-text role="issue"}.) A backslash-character pair that is not a valid escape sequence now generates a `DeprecationWarning`{.interpreted-text role="exc"}. Although this will eventually become a `SyntaxError`{.interpreted-text role="exc"}, that will not be for several Python releases. (Contributed by Emanuel Barry in `27364`{.interpreted-text role="issue"}.) 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 `ImportWarning`{.interpreted-text role="exc"}. (Contributed by Rose Ames in `25791`{.interpreted-text role="issue"}.) ### Deprecated Python modules, functions and methods #### asynchat The `!asynchat`{.interpreted-text role="mod"} has been deprecated in favor of `asyncio`{.interpreted-text role="mod"}. (Contributed by Mariatta in `25002`{.interpreted-text role="issue"}.) #### asyncore The `!asyncore`{.interpreted-text role="mod"} has been deprecated in favor of `asyncio`{.interpreted-text role="mod"}. (Contributed by Mariatta in `25002`{.interpreted-text role="issue"}.) #### dbm Unlike other `dbm`{.interpreted-text role="mod"} implementations, the `dbm.dumb`{.interpreted-text role="mod"} 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 `21708`{.interpreted-text role="issue"}.) #### distutils The undocumented `extra_path` argument to the `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 `27919`{.interpreted-text role="issue"} for details. #### grp The support of non-integer arguments in `~grp.getgrgid`{.interpreted-text role="func"} has been deprecated. (Contributed by Serhiy Storchaka in `26129`{.interpreted-text role="issue"}.) #### importlib The `importlib.machinery.SourceFileLoader.load_module` and `importlib.machinery.SourcelessFileLoader.load_module` methods are now deprecated. They were the only remaining implementations of `importlib.abc.Loader.load_module` in `importlib`{.interpreted-text role="mod"} that had not been deprecated in previous versions of Python in favour of `importlib.abc.Loader.exec_module`{.interpreted-text role="meth"}. The `importlib.machinery.WindowsRegistryFinder`{.interpreted-text role="class"} class is now deprecated. As of 3.6.0, it is still added to `sys.meta_path`{.interpreted-text role="data"} by default (on Windows), but this may change in future releases. #### os Undocumented support of general `bytes-like objects `{.interpreted-text role="term"} as paths in `os`{.interpreted-text role="mod"} functions, `compile`{.interpreted-text role="func"} and similar functions is now deprecated. (Contributed by Serhiy Storchaka in `25791`{.interpreted-text role="issue"} and `26754`{.interpreted-text role="issue"}.) #### 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 `22493`{.interpreted-text role="issue"}.) #### ssl OpenSSL 0.9.8, 1.0.0 and 1.0.1 are deprecated and no longer supported. In the future the `ssl`{.interpreted-text role="mod"} module will require at least OpenSSL 1.0.2 or 1.1.0. SSL-related arguments like `certfile`, `keyfile` and `check_hostname` in `ftplib`{.interpreted-text role="mod"}, `http.client`{.interpreted-text role="mod"}, `imaplib`{.interpreted-text role="mod"}, `poplib`{.interpreted-text role="mod"}, and `smtplib`{.interpreted-text role="mod"} have been deprecated in favor of `context`. (Contributed by Christian Heimes in `28022`{.interpreted-text role="issue"}.) A couple of protocols and functions of the `ssl`{.interpreted-text role="mod"} 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 `28022`{.interpreted-text role="issue"} and `26470`{.interpreted-text role="issue"}.) #### tkinter The `!tkinter.tix`{.interpreted-text role="mod"} module is now deprecated. `tkinter`{.interpreted-text role="mod"} users should use `tkinter.ttk`{.interpreted-text role="mod"} instead. #### venv {#whatsnew36-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 `25154`{.interpreted-text role="issue"}.) ### xml - As mitigation against DTD and external entity retrieval, the `xml.dom.minidom`{.interpreted-text role="mod"} and `xml.sax`{.interpreted-text role="mod"} modules no longer process external entities by default. (Contributed by Christian Heimes in `61441`{.interpreted-text role="gh"}.) ### Deprecated functions and types of the C API Undocumented functions `!PyUnicode_AsEncodedObject`{.interpreted-text role="c:func"}, `!PyUnicode_AsDecodedObject`{.interpreted-text role="c:func"}, `!PyUnicode_AsEncodedUnicode`{.interpreted-text role="c:func"} and `!PyUnicode_AsDecodedUnicode`{.interpreted-text role="c:func"} are deprecated now. Use the `generic codec based API `{.interpreted-text role="ref"} instead. ### Deprecated Build Options 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 ### API and Feature Removals - Unknown escapes consisting of `'\'` and an ASCII letter in regular expressions will now cause an error. In replacement templates for `re.sub`{.interpreted-text role="func"} they are still allowed, but deprecated. The `re.LOCALE`{.interpreted-text role="const"} flag can now only be used with binary patterns. - `inspect.getmoduleinfo()` was removed (was deprecated since CPython 3.3). `inspect.getmodulename`{.interpreted-text role="func"} should be used for obtaining the module name for a given path. (Contributed by Yury Selivanov in `13248`{.interpreted-text role="issue"}.) - `traceback.Ignore` class and `traceback.usage`, `traceback.modname`, `traceback.fullmodname`, `traceback.find_lines_from_code`, `traceback.find_lines`, `traceback.find_strings`, `traceback.find_executable_lines` methods were removed from the `traceback`{.interpreted-text role="mod"} module. They were undocumented methods deprecated since Python 3.2 and equivalent functionality is available from private methods. - The `tk_menuBar()` and `tk_bindForTraversal()` dummy methods in `tkinter`{.interpreted-text role="mod"} widget classes were removed (corresponding Tk commands were obsolete since Tk 4.0). - The `~zipfile.ZipFile.open`{.interpreted-text role="meth"} method of the `zipfile.ZipFile`{.interpreted-text role="class"} class no longer supports the `'U'` mode (was deprecated since Python 3.4). Use `io.TextIOWrapper`{.interpreted-text role="class"} for reading compressed text files in `universal newlines`{.interpreted-text role="term"} mode. - The undocumented `IN`, `CDROM`, `DLFCN`, `TYPES`, `CDIO`, and `STROPTS` modules have been removed. They had been available in the platform specific `Lib/plat-*/` directories, but were chronically out of date, inconsistently available across platforms, and unmaintained. The script that created these modules is still available in the source distribution at [Tools/scripts/h2py.py](https://github.com/python/cpython/blob/v3.6.15/Tools/scripts/h2py.py). - The deprecated `asynchat.fifo` class has been removed. ## Porting to Python 3.6 This section lists previously described changes and other bugfixes that may require changes to your code. ### Changes in \'python\' Command Behavior - The output of a special Python build with defined `COUNT_ALLOCS`, `SHOW_ALLOC_COUNT` or `SHOW_TRACK_COUNT` macros is now off by default. It can be re-enabled using the `-X showalloccount` option. It now outputs to `stderr` instead of `stdout`. (Contributed by Serhiy Storchaka in `23034`{.interpreted-text role="issue"}.) ### Changes in the Python API - `open() `{.interpreted-text role="func"} will no longer allow combining the `'U'` mode flag with `'+'`. (Contributed by Jeff Balogh and John O\'Connor in `2091`{.interpreted-text role="issue"}.) - `sqlite3`{.interpreted-text role="mod"} no longer implicitly commits an open transaction before DDL statements. - On Linux, `os.urandom`{.interpreted-text role="func"} now blocks until the system urandom entropy pool is initialized to increase the security. - When `importlib.abc.Loader.exec_module`{.interpreted-text role="meth"} is defined, `importlib.abc.Loader.create_module`{.interpreted-text role="meth"} must also be defined. - `PyErr_SetImportError`{.interpreted-text role="c:func"} now sets `TypeError`{.interpreted-text role="exc"} when its **msg** argument is not set. Previously only `NULL` was returned. - The format of the `~codeobject.co_lnotab`{.interpreted-text role="attr"} attribute of code objects changed to support a negative line number delta. By default, Python does not emit bytecode with a negative line number delta. Functions using `frame.f_lineno`{.interpreted-text role="attr"}, `PyFrame_GetLineNumber()` or `PyCode_Addr2Line()` are not affected. Functions directly decoding `!co_lnotab`{.interpreted-text role="attr"} should be updated to use a signed 8-bit integer type for the line number delta, but this is only required to support applications using a negative line number delta. See `Objects/lnotab_notes.txt` for the `!co_lnotab`{.interpreted-text role="attr"} format and how to decode it, and see the `511`{.interpreted-text role="pep"} for the rationale. - The functions in the `compileall`{.interpreted-text role="mod"} module now return booleans instead of `1` or `0` to represent success or failure, respectively. Thanks to booleans being a subclass of integers, this should only be an issue if you were doing identity checks for `1` or `0`. See `25768`{.interpreted-text role="issue"}. - Reading the `!port`{.interpreted-text role="attr"} attribute of `urllib.parse.urlsplit`{.interpreted-text role="func"} and `~urllib.parse.urlparse`{.interpreted-text role="func"} results now raises `ValueError`{.interpreted-text role="exc"} for out-of-range values, rather than returning `None`{.interpreted-text role="const"}. See `20059`{.interpreted-text role="issue"}. - The `!imp`{.interpreted-text role="mod"} module now raises a `DeprecationWarning`{.interpreted-text role="exc"} instead of `PendingDeprecationWarning`{.interpreted-text role="exc"}. - The following modules have had missing APIs added to their `~module.__all__`{.interpreted-text role="attr"} attributes to match the documented APIs: `calendar`{.interpreted-text role="mod"}, `!cgi`{.interpreted-text role="mod"}, `csv`{.interpreted-text role="mod"}, `~xml.etree.ElementTree`{.interpreted-text role="mod"}, `enum`{.interpreted-text role="mod"}, `fileinput`{.interpreted-text role="mod"}, `ftplib`{.interpreted-text role="mod"}, `logging`{.interpreted-text role="mod"}, `mailbox`{.interpreted-text role="mod"}, `mimetypes`{.interpreted-text role="mod"}, `optparse`{.interpreted-text role="mod"}, `plistlib`{.interpreted-text role="mod"}, `!smtpd`{.interpreted-text role="mod"}, `subprocess`{.interpreted-text role="mod"}, `tarfile`{.interpreted-text role="mod"}, `threading`{.interpreted-text role="mod"} and `wave`{.interpreted-text role="mod"}. This means they will export new symbols when `import *` is used. (Contributed by Joel Taddei and Jacek Kołodziej in `23883`{.interpreted-text role="issue"}.) - When performing a relative import, if `__package__` does not compare equal to `__spec__.parent` then `ImportWarning`{.interpreted-text role="exc"} is raised. (Contributed by Brett Cannon in `25791`{.interpreted-text role="issue"}.) - When a relative import is performed and no parent package is known, then `ImportError`{.interpreted-text role="exc"} will be raised. Previously, `SystemError`{.interpreted-text role="exc"} could be raised. (Contributed by Brett Cannon in `18018`{.interpreted-text role="issue"}.) - Servers based on the `socketserver`{.interpreted-text role="mod"} module, including those defined in `http.server`{.interpreted-text role="mod"}, `xmlrpc.server`{.interpreted-text role="mod"} and `wsgiref.simple_server`{.interpreted-text role="mod"}, now only catch exceptions derived from `Exception`{.interpreted-text role="exc"}. Therefore if a request handler raises an exception like `SystemExit`{.interpreted-text role="exc"} or `KeyboardInterrupt`{.interpreted-text role="exc"}, `~socketserver.BaseServer.handle_error`{.interpreted-text role="meth"} is no longer called, and the exception will stop a single-threaded server. (Contributed by Martin Panter in `23430`{.interpreted-text role="issue"}.) - `!spwd.getspnam`{.interpreted-text role="func"} now raises a `PermissionError`{.interpreted-text role="exc"} instead of `KeyError`{.interpreted-text role="exc"} if the user doesn\'t have privileges. - The `socket.socket.close`{.interpreted-text role="meth"} method now raises an exception if an error (e.g. `EBADF`) was reported by the underlying system call. (Contributed by Martin Panter in `26685`{.interpreted-text role="issue"}.) - The *decode_data* argument for the `!smtpd.SMTPChannel`{.interpreted-text role="class"} and `!smtpd.SMTPServer`{.interpreted-text role="class"} constructors is now `False` by default. This means that the argument passed to `!process_message`{.interpreted-text role="meth"} is now a bytes object by default, and `!process_message`{.interpreted-text role="meth"} will be passed keyword arguments. Code that has already been updated in accordance with the deprecation warning generated by 3.5 will not be affected. - All optional arguments of the `~json.dump`{.interpreted-text role="func"}, `~json.dumps`{.interpreted-text role="func"}, `~json.load`{.interpreted-text role="func"} and `~json.loads`{.interpreted-text role="func"} functions and `~json.JSONEncoder`{.interpreted-text role="class"} and `~json.JSONDecoder`{.interpreted-text role="class"} class constructors in the `json`{.interpreted-text role="mod"} module are now `keyword-only `{.interpreted-text role="ref"}. (Contributed by Serhiy Storchaka in `18726`{.interpreted-text role="issue"}.) - Subclasses of `type`{.interpreted-text role="class"} which don\'t override `type.__new__` may no longer use the one-argument form to get the type of an object. - As part of `487`{.interpreted-text role="pep"}, the handling of keyword arguments passed to `type`{.interpreted-text role="class"} (other than the metaclass hint, `metaclass`) is now consistently delegated to `object.__init_subclass__`{.interpreted-text role="meth"}. This means that `type.__new__ `{.interpreted-text role="meth"} and `type.__init__ `{.interpreted-text role="meth"} both now accept arbitrary keyword arguments, but `object.__init_subclass__`{.interpreted-text role="meth"} (which is called from `type.__new__ `{.interpreted-text role="meth"}) will reject them by default. Custom metaclasses accepting additional keyword arguments will need to adjust their calls to `type.__new__ `{.interpreted-text role="meth"} (whether direct or via `super`{.interpreted-text role="class"}) accordingly. - In `distutils.command.sdist.sdist`, the `default_format` attribute has been removed and is no longer honored. Instead, the gzipped tarfile format is the default on all platforms and no platform-specific selection is made. In environments where distributions are built on Windows and zip distributions are required, configure the project with a `setup.cfg` file containing the following: ``` ini [sdist] formats=zip ``` This behavior has also been backported to earlier Python versions by Setuptools 26.0.0. - In the `urllib.request`{.interpreted-text role="mod"} module and the `http.client.HTTPConnection.request`{.interpreted-text role="meth"} method, if no Content-Length 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. (Contributed by Demian Brecht and Rolf Krahl with tweaks from Martin Panter in `12319`{.interpreted-text role="issue"}.) - The `~csv.DictReader`{.interpreted-text role="class"} now returns rows of type `~collections.OrderedDict`{.interpreted-text role="class"}. (Contributed by Steve Holden in `27842`{.interpreted-text role="issue"}.) - The `!crypt.METHOD_CRYPT`{.interpreted-text role="const"} will no longer be added to `crypt.methods` if unsupported by the platform. (Contributed by Victor Stinner in `25287`{.interpreted-text role="issue"}.) - The *verbose* and *rename* arguments for `~collections.namedtuple`{.interpreted-text role="func"} are now keyword-only. (Contributed by Raymond Hettinger in `25628`{.interpreted-text role="issue"}.) - On Linux, `ctypes.util.find_library`{.interpreted-text role="func"} now looks in `LD_LIBRARY_PATH` for shared libraries. (Contributed by Vinay Sajip in `9998`{.interpreted-text role="issue"}.) - The `imaplib.IMAP4`{.interpreted-text role="class"} class now handles flags containing the `']'` character in messages sent from the server to improve real-world compatibility. (Contributed by Lita Cho in `21815`{.interpreted-text role="issue"}.) - The `mmap.mmap.write`{.interpreted-text role="func"} function now returns the number of bytes written like other write methods. (Contributed by Jakub Stasiak in `26335`{.interpreted-text role="issue"}.) - The `pkgutil.iter_modules`{.interpreted-text role="func"} and `pkgutil.walk_packages`{.interpreted-text role="func"} functions now return `~pkgutil.ModuleInfo`{.interpreted-text role="class"} named tuples. (Contributed by Ramchandra Apte in `17211`{.interpreted-text role="issue"}.) - `re.sub`{.interpreted-text role="func"} now raises an error for invalid numerical group references in replacement templates even if the pattern is not found in the string. The error message for invalid group references now includes the group index and the position of the reference. (Contributed by SilentGhost, Serhiy Storchaka in `25953`{.interpreted-text role="issue"}.) - `zipfile.ZipFile`{.interpreted-text role="class"} will now raise `NotImplementedError`{.interpreted-text role="exc"} for unrecognized compression values. Previously a plain `RuntimeError`{.interpreted-text role="exc"} was raised. Additionally, calling `~zipfile.ZipFile`{.interpreted-text role="class"} methods on a closed ZipFile or calling the `~zipfile.ZipFile.write`{.interpreted-text role="meth"} method on a ZipFile created with mode `'r'` will raise a `ValueError`{.interpreted-text role="exc"}. Previously, a `RuntimeError`{.interpreted-text role="exc"} was raised in those scenarios. - when custom metaclasses are combined with zero-argument `super`{.interpreted-text role="func"} or direct references from methods to the implicit `__class__` closure variable, the implicit `__classcell__` namespace entry must now be passed up to `type.__new__` for initialisation. Failing to do so will result in a `DeprecationWarning`{.interpreted-text role="exc"} in Python 3.6 and a `RuntimeError`{.interpreted-text role="exc"} in Python 3.8. - With the introduction of `ModuleNotFoundError`{.interpreted-text role="exc"}, import system consumers may start expecting import system replacements to raise that more specific exception when appropriate, rather than the less-specific `ImportError`{.interpreted-text role="exc"}. To provide future compatibility with such consumers, implementers of alternative import systems that completely replace `__import__`{.interpreted-text role="func"} will need to update their implementations to raise the new subclass when a module can\'t be found at all. Implementers of compliant plugins to the default import system shouldn\'t need to make any changes, as the default import system will raise the new subclass when appropriate. ### Changes in the C API - The `PyMem_Malloc`{.interpreted-text role="c:func"} allocator family now uses the `pymalloc allocator `{.interpreted-text role="ref"} rather than the system `malloc`{.interpreted-text role="c:func"}. Applications calling `PyMem_Malloc`{.interpreted-text role="c:func"} without holding the GIL can now crash. Set the `PYTHONMALLOC`{.interpreted-text role="envvar"} environment variable to `debug` to validate the usage of memory allocators in your application. See `26249`{.interpreted-text role="issue"}. - `Py_Exit`{.interpreted-text role="c:func"} (and the main interpreter) now override the exit status with 120 if flushing buffered data failed. See `5319`{.interpreted-text role="issue"}. ### CPython bytecode changes There have been several major changes to the `bytecode`{.interpreted-text role="term"} in Python 3.6. - The Python interpreter now uses a 16-bit wordcode instead of bytecode. (Contributed by Demur Rumed with input and reviews from Serhiy Storchaka and Victor Stinner in `26647`{.interpreted-text role="issue"} and `28050`{.interpreted-text role="issue"}.) - The new `!FORMAT_VALUE`{.interpreted-text role="opcode"} and `BUILD_STRING`{.interpreted-text role="opcode"} opcodes as part of the `formatted string literal `{.interpreted-text role="ref"} implementation. (Contributed by Eric Smith in `25483`{.interpreted-text role="issue"} and Serhiy Storchaka in `27078`{.interpreted-text role="issue"}.) - The new `!BUILD_CONST_KEY_MAP`{.interpreted-text role="opcode"} opcode to optimize the creation of dictionaries with constant keys. (Contributed by Serhiy Storchaka in `27140`{.interpreted-text role="issue"}.) - The function call opcodes have been heavily reworked for better performance and simpler implementation. The `MAKE_FUNCTION`{.interpreted-text role="opcode"}, `!CALL_FUNCTION`{.interpreted-text role="opcode"}, `!CALL_FUNCTION_KW`{.interpreted-text role="opcode"} and `!BUILD_MAP_UNPACK_WITH_CALL`{.interpreted-text role="opcode"} opcodes have been modified, the new `CALL_FUNCTION_EX`{.interpreted-text role="opcode"} and `!BUILD_TUPLE_UNPACK_WITH_CALL`{.interpreted-text role="opcode"} have been added, and `CALL_FUNCTION_VAR`, `CALL_FUNCTION_VAR_KW` and `MAKE_CLOSURE` opcodes have been removed. (Contributed by Demur Rumed in `27095`{.interpreted-text role="issue"}, and Serhiy Storchaka in `27213`{.interpreted-text role="issue"}, `28257`{.interpreted-text role="issue"}.) - The new `SETUP_ANNOTATIONS`{.interpreted-text role="opcode"} and `!STORE_ANNOTATION`{.interpreted-text role="opcode"} opcodes have been added to support the new `variable annotation`{.interpreted-text role="term"} syntax. (Contributed by Ivan Levkivskyi in `27985`{.interpreted-text role="issue"}.) ## Notable changes in Python 3.6.2 ### New `make regen-all` build target To simplify cross-compilation, and to ensure that CPython can reliably be compiled without requiring an existing version of Python to already be available, the autotools-based build system no longer attempts to implicitly recompile generated files based on file modification times. Instead, a new `make regen-all` command has been added to force regeneration of these files when desired (e.g. after an initial version of Python has already been built based on the pregenerated versions). More selective regeneration targets are also defined - see `Makefile.pre.in`{.interpreted-text role="source"} for details. (Contributed by Victor Stinner in `23404`{.interpreted-text role="issue"}.) ::: versionadded 3.6.2 ::: ### Removal of `make touch` build target The `make touch` build target previously used to request implicit regeneration of generated files by updating their modification times has been removed. It has been replaced by the new `make regen-all` target. (Contributed by Victor Stinner in `23404`{.interpreted-text role="issue"}.) ::: versionchanged 3.6.2 ::: ## Notable changes in Python 3.6.4 The `PyExc_RecursionErrorInst` singleton that was part of the public API has been removed as its members being never cleared may cause a segfault during finalization of the interpreter. (Contributed by Xavier de Gaye in `22898`{.interpreted-text role="issue"} and `30697`{.interpreted-text role="issue"}.) ## Notable changes in Python 3.6.5 The `locale.localeconv`{.interpreted-text role="func"} function now sets temporarily the `LC_CTYPE` locale to the `LC_NUMERIC` locale in some cases. (Contributed by Victor Stinner in `31900`{.interpreted-text role="issue"}.) ## Notable changes in Python 3.6.7 `xml.dom.minidom`{.interpreted-text role="mod"} and `xml.sax`{.interpreted-text role="mod"} modules no longer process external entities by default. See also `61441`{.interpreted-text role="gh"}. In 3.6.7 the `tokenize`{.interpreted-text role="mod"} module now implicitly emits a `NEWLINE` token when provided with input that does not have a trailing new line. This behavior now matches what the C tokenizer does internally. (Contributed by Ammar Askar in `33899`{.interpreted-text role="issue"}.) ## Notable changes in Python 3.6.10 Due to significant security concerns, the *reuse_address* parameter of `asyncio.loop.create_datagram_endpoint`{.interpreted-text role="meth"} is no longer supported. This is because of the behavior of the socket option `SO_REUSEADDR` in UDP. For more details, see the documentation for `loop.create_datagram_endpoint()`. (Contributed by Kyle Stanley, Antoine Pitrou, and Yury Selivanov in `37228`{.interpreted-text role="issue"}.) ## Notable changes in Python 3.6.13 Earlier Python versions allowed using both `;` and `&` as query parameter separators in `urllib.parse.parse_qs`{.interpreted-text role="func"} and `urllib.parse.parse_qsl`{.interpreted-text role="func"}. Due to security concerns, and to conform with newer W3C recommendations, this has been changed to allow only a single separator key, with `&` as the default. This change also affects `!cgi.parse`{.interpreted-text role="func"} and `!cgi.parse_multipart`{.interpreted-text role="func"} as they use the affected functions internally. For more details, please see their respective documentation. (Contributed by Adam Goldschmidt, Senthil Kumaran and Ken Jin in `42967`{.interpreted-text role="issue"}.) ## Notable changes in Python 3.6.14 A security fix alters the `ftplib.FTP`{.interpreted-text role="class"} behavior to not trust the IPv4 address sent from the remote server when setting up a passive data channel. We reuse the ftp server IP address instead. For unusual code requiring the old behavior, set a `trust_server_pasv_ipv4_address` attribute on your FTP instance to `True`. (See `87451`{.interpreted-text role="gh"}) The presence of newline or tab characters in parts of a URL allows for some forms of attacks. Following the WHATWG specification that updates RFC 3986, ASCII newline `\n`, `\r` and tab `\t` characters are stripped from the URL by the parser `urllib.parse`{.interpreted-text role="func"} preventing such attacks. The removal characters are controlled by a new module level variable `urllib.parse._UNSAFE_URL_BYTES_TO_REMOVE`. (See `88048`{.interpreted-text role="gh"})