Tin mới
PEP 405: Virtual Environments¶
Some smaller changes made to the core Python language are:
PyImport_ImportModuleNoBlock()
Previous versions of CPython have always relied on a global import lock. This led to unexpected annoyances, such as deadlocks when importing a module would trigger code execution in a different thread as a side-effect. C
https://en.wikipedia.org/wiki/Reliable_Datagram_Sockets
Improved support for abstract base classes containing descriptors composed with abstract methods. The recommended approach to declaring abstract descriptors is now to provide __isabstractmethod__ as a dynamically updated
Changes to Python’s build process and to the C API include:
This section lists previously described changes and other bugfixes that may require changes to your code.
The implementation of sys.implementation also introduces a new type to Python: types.SimpleNamespace. In contrast to a mapping-based namespace, like dict, SimpleNamespace is attribute-based, like object. However, unlike
importlib.machinery.SourcelessFileLoader
One of the large benefits of this work is the exposure of what goes into making the import statement work. That means the various importers that were once implicit are now fully exposed as part of the importlib package.
For potential required changes to code, see the Porting Python code section.
The new ipaddress module provides tools for creating and manipulating objects representing IPv4 and IPv6 addresses, networks and interfaces (i.e. an IP address associated with a specific IP subnet).
The newly-added lzma module provides data compression and decompression using the LZMA algorithm, including support for the .xz and .lzma file formats.
Improved support for abstract base classes containing descriptors composed with abstract methods. The recommended approach to declaring abstract descriptors is now to provide __isabstractmethod__ as a dynamically updated
The array module supports the long long type using q and Q type codes.
ASCII-only Unicode strings are now accepted by the decoding functions of the base64 modern interface. For example, base64.b64decode('YWJj') returns b'abc'. (Contributed by Catalin Iacob in bpo-13641.)
The mbcs codec has been rewritten to handle correctly replace and ignore error handlers on all Windows versions. The mbcs codec now supports all error handlers, instead of only replace to encode and ignore to decode.
Addition of salt and modular crypt format (hashing method) and the mksalt() function to the crypt module.
If the curses module is linked to the ncursesw library, use Unicode functions when Unicode strings or characters are passed (e.g. waddwstr()), and bytes functions otherwise (e.g. waddstr()).
datetime.datetime.astimezone()
Equality comparisons between naive and aware datetime instances now return False instead of raising TypeError (bpo-15006).
Provisional Policy with New Header API¶
The functools.lru_cache() decorator now accepts a typed keyword argument (that defaults to False to ensure that it caches values of different types that compare equal in separate cache slots. (Contributed by Raymond Hett
It is now possible to register callbacks invoked by the garbage collector before and after collection using the new callbacks list.
The IMAP4_SSL constructor now accepts an SSLContext parameter to control parameters of the secure channel.
A new getclosurevars() function has been added. This function reports the current binding of all names referenced from the function body and where those names were resolved, making it easier to verify correct internal st
The math module has a new function, log2(), which returns the base-2 logarithm of x.
The read() method is now more compatible with other file-like objects: if the argument is omitted or specified as None, it returns the bytes from the current file position to the end of the mapping. (Contributed by Petri
multiprocessing.pool.Pool.starmap()
The new multiprocessing.connection.wait() function allows polling multiple objects (such as connections, sockets and pipes) with a timeout. (Contributed by Richard Oudkerk in bpo-12328.)
paths relative to directory descriptors
The os module has a new pipe2() function that makes it possible to create a pipe with O_CLOEXEC or O_NONBLOCK flags set atomically. This is especially useful to avoid race conditions in multi-threaded programs.
The Tk GUI and the serve() function have been removed from the pydoc module: pydoc -g and serve() have been deprecated in Python 3.2.
str regular expressions now support \u and \U escapes.
The previously undocumented helper function quote from the pipes modules has been moved to the shlex module and documented. quote() properly escapes all characters in a string that might be otherwise given special meanin
The smtpd module now supports RFC 5321 (extended SMTP) and RFC 1870 (size extension). Per the standard, these extensions are enabled if and only if the client initiates the session with an EHLO command.
The SMTP, SMTP_SSL, and LMTP classes now accept a source_address keyword argument to specify the (host, port) to use as the source address in the bind call when creating the outgoing socket. (Contributed by Paulo Scardin
https://en.wikipedia.org/wiki/Reliable_Datagram_Sockets
The socket class now exposes additional methods to process ancillary data when supported by the underlying platform:
New sqlite3.Connection method set_trace_callback() can be used to capture a trace of all sql commands processed by sqlite. (Contributed by Torsten Landschoff in bpo-11688.)
ssl.SSLContext.set_npn_protocols()
The ssl module has two new random generation functions:
The struct module now supports ssize_t and size_t via the new codes n and N, respectively. (Contributed by Antoine Pitrou in bpo-3163.)
Command strings can now be bytes objects on posix platforms. (Contributed by Victor Stinner in bpo-8513.)
tarfile now supports lzma encoding via the lzma module. (Contributed by Lars Gustäbel in bpo-5689.)
tempfile.SpooledTemporaryFile’s truncate() method now accepts a size parameter. (Contributed by Ryan Kelly in bpo-9957.)
The textwrap module has a new indent() that makes it straightforward to add a common prefix to selected lines in a block of text (bpo-13857).
threading.Condition, threading.Semaphore, threading.BoundedSemaphore, threading.Event, and threading.Timer, all of which used to be factory functions returning a class instance, are now classes and may be subclassed. (Co
assertRaises(), assertRaisesRegex(), assertWarns(), and assertWarnsRegex() now accept a keyword argument msg when used as context managers. (Contributed by Ezio Melotti and Winston Ewert in bpo-10775.)
The webbrowser module supports more “browsers”: Google Chrome (named chrome, chromium, chrome-browser or chromium-browser depending on the version and operating system), and the generic launchers xdg-open, from the FreeD
The xml.etree.ElementTree module now imports its C accelerator by default; there is no longer a need to explicitly import xml.etree.cElementTree (this module stays for backwards compatibility, but is now deprecated). In
New attribute zlib.Decompress.eof makes it possible to distinguish between a properly-formed compressed stream and an incomplete or truncated one. (Contributed by Nadeem Vawda in bpo-12646.)