What’s New In Python 3.3 — Python 3.9.25 documentation

docs.python.org

Tin mới

Summary – Release highlights¶

PEP 405: Virtual Environments¶

Other Language Changes¶

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

faulthandler.enable()

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

PyUnicode_FromKindAndData()

Changes to Python’s build process and to the C API include:

importlib.invalidate_caches()

This section lists previously described changes and other bugfixes that may require changes to your code.

types.SimpleNamespace

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.

sys.path_importer_cache

For potential required changes to code, see the Porting Python code section.

Permalink to this headline

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).

Permalink to this headline

The newly-added lzma module provides data compression and decompression using the LZMA algorithm, including support for the .xz and .lzma file formats.

abc.abstractstaticmethod

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

Permalink to this headline

The array module supports the long long type using q and Q type codes.

Permalink to this headline

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.)

Permalink to this headline

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.

Permalink to this headline

Permalink to this headline

Addition of salt and modular crypt format (hashing method) and the mksalt() function to the crypt module.

curses.window.encoding

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¶

functools.lru_cache()

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

Permalink to this headline

It is now possible to register callbacks invoked by the garbage collector before and after collection using the new callbacks list.

html.parser.HTMLParser

Permalink to this headline

The IMAP4_SSL constructor now accepts an SSLContext parameter to control parameters of the secure channel.

getgeneratorlocals()

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

Permalink to this headline

The math module has a new function, log2(), which returns the base-2 logarithm of x.

Permalink to this headline

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.

Permalink to this headline

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.

Permalink to this headline

str regular expressions now support \u and \U escapes.

Permalink to this headline

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

signal.siginterrupt()

Permalink to this headline

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.

Permalink to this headline

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:

set_trace_callback()

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:

Permalink to this headline

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.)

Permalink to this headline

Command strings can now be bytes objects on posix platforms. (Contributed by Victor Stinner in bpo-8513.)

Permalink to this headline

tarfile now supports lzma encoding via the lzma module. (Contributed by Lars Gustäbel in bpo-5689.)

tempfile.SpooledTemporaryFile

tempfile.SpooledTemporaryFile’s truncate() method now accepts a size parameter. (Contributed by Ryan Kelly in bpo-9957.)

Permalink to this headline

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.BoundedSemaphore

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

unittest.TestCase.run()

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.)

Permalink to this headline

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

xml.etree.ElementTree¶

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

zlib.ZLIB_RUNTIME_VERSION

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.)