Tin mới
Improved ‘Did you mean …’ suggestions
Python 3.12 is a stable release of the Python programming language, with a mix of changes to the language and the standard library. The library changes focus on cleaning up deprecated APIs, usability, and correctness. Of
sys.deactivate_stack_trampoline()
The parser now raises SyntaxError when parsing source code containing null bytes. (Contributed by Pablo Galindo in gh-96670.)
asyncio.create_eager_task_factory()
The array.array class now supports subscripting, making it a generic type. (Contributed by Jelle Zijlstra in gh-98658.)
Remove wstr and wstr_length members from Unicode objects. It reduces object size by 8 or 16 bytes on 64bit platform. (PEP 623) (Contributed by Inada Naoki in gh-92536.)
Remove the LOAD_METHOD instruction. It has been merged into LOAD_ATTR. LOAD_ATTR will now behave like the old LOAD_METHOD instruction if the low bit of its oparg is set. (Contributed by Ken Jin in gh-93429.)
this discussion on fork being incompatible with threads
argparse: The type, choices, and metavar parameters of argparse.BooleanOptionalAction are deprecated and will be removed in 3.14. (Contributed by Nikita Sobolev in gh-92248.)
importlib.machinery.EXTENSION_SUFFIXES
These two modules have been removed according to the schedule in PEP 594, having been deprecated in Python 3.6. Use asyncio instead. (Contributed by Nikita Sobolev in gh-96580.)
filesystem encoding and error handler
This section lists previously described changes and other bugfixes that may require changes to your code.
PyConfig_Get("legacy_windows_fs_encoding")
PEP 697: Introduce the Unstable C API tier, intended for low-level tools like debuggers and JIT compilers. This API may change in each minor release of CPython without deprecation warnings. Its contents are marked by the
PEP 695: Type Parameter Syntax¶
Generic classes and functions under PEP 484 were declared using a verbose syntax that left the scope of type parameters unclear and required explicit declarations of variance.
PEP 684: A Per-Interpreter GIL¶
PEP 684 introduces a per-interpreter GIL, so that sub-interpreters may now be created with a unique GIL per interpreter. This allows Python programs to take full advantage of multiple CPU cores. This is currently only av
asyncio.create_eager_task_factory()
The performance of writing to sockets in asyncio has been significantly improved. asyncio now avoids unnecessary copying when writing to sockets and uses sendmsg() if the platform supports it. (Contributed by Kumar Adity
Objects of type fractions.Fraction now support float-style formatting. (Contributed by Mark Dickinson in gh-100161.)
inspect.markcoroutinefunction()
Add inspect.markcoroutinefunction() to mark sync functions that return a coroutine for use with inspect.iscoroutinefunction(). (Contributed by Carlton Gibson in gh-99247.)
Add itertools.batched() for collecting into even-sized tuples where the last batch may be shorter than the rest. (Contributed by Raymond Hettinger in gh-98363.)
Add os.PIDFD_NONBLOCK to open a file descriptor for a process with os.pidfd_open() in non-blocking mode. (Contributed by Kumar Aditya in gh-93312.)
Add os.path.isjunction() to check if a given path is a junction. (Contributed by Charles Machalow in gh-99547.)
pathlib.PurePath.with_segments()
Add support for subclassing pathlib.PurePath and pathlib.Path, plus their Posix- and Windows-specific variants. Subclasses may override the pathlib.PurePath.with_segments() method to pass information between path instanc
Add random.binomialvariate(). (Contributed by Raymond Hettinger in gh-81620.)
shutil.make_archive() now passes the root_dir argument to custom archivers which support it. In this case it no longer temporarily changes the current working directory of the process to root_dir to perform archiving. (C
sqlite3.Connection.load_extension()
Add a command-line interface. (Contributed by Erlend E. Aasland in gh-77617.)
Extend statistics.correlation() to include as a ranked method for computing the Spearman correlation of ranked data. (Contributed by Raymond Hettinger in gh-95861.)
sys.deactivate_stack_trampoline()
Add the sys.monitoring namespace to expose the new PEP 669 monitoring API. (Contributed by Mark Shannon in gh-103082.)
The tempfile.NamedTemporaryFile function has a new optional parameter delete_on_close (Contributed by Evgeny Zorin in gh-58451.)
threading.setprofile_all_threads()
Add threading.settrace_all_threads() and threading.setprofile_all_threads() that allow to set tracing and profiling functions in all running threads in addition to the calling one. (Contributed by Pablo Galindo in gh-935
Add types.get_original_bases() to allow for further introspection of User-defined generic types when subclassed. (Contributed by James Hilton-Balfe and Alex Waygood in gh-101827.)
Add a command-line interface. (Contributed by Adam Chhina in gh-88597.)
Pending removal in Python 3.15¶
asyncio.WindowsSelectorEventLoopPolicy
Pending removal in Python 3.17¶
Pending removal in future versions¶
The following APIs will be removed in the future, although there is currently no date scheduled for their removal.
Several names deprecated in the configparser way back in 3.2 have been removed per gh-89336:
Remove the bundled setuptools wheel from ensurepip, and stop installing setuptools in environments created by venv.
Remove enum’s EnumMeta.__getattr__, which is no longer needed for enum attribute access. (Contributed by Ethan Furman in gh-95083.)
Remove ftplib’s FTP_TLS.ssl_version class attribute: use the context parameter instead. (Contributed by Victor Stinner in gh-94172.)
Remove the pure Python implementation of hashlib’s hashlib.pbkdf2_hmac(), deprecated in Python 3.10. Python 3.10 and newer requires OpenSSL 1.1.1 (PEP 644): this OpenSSL version provides a C implementation of pbkdf2_hmac
Remove io’s io.OpenWrapper and _pyio.OpenWrapper, deprecated in Python 3.10: just use open() instead. The open() (io.open()) function is a built-in function. Since Python 3.10, _pyio.open() is also a static method. (Cont
Remove locale’s locale.format() function, deprecated in Python 3.7: use locale.format_string() instead. (Contributed by Victor Stinner in gh-94226.)
The smtpd module has been removed according to the schedule in PEP 594, having been deprecated in Python 3.4.7 and 3.5.4. Use the aiosmtpd PyPI module or any other asyncio-based server instead. (Contributed by Oleg Iaryg
Remove ssl’s ssl.RAND_pseudo_bytes() function, deprecated in Python 3.6: use os.urandom() or ssl.RAND_bytes() instead. (Contributed by Victor Stinner in gh-94199.)
https://github.com/isidentical/teyit
Remove many long-deprecated unittest features:
Remove support for obsolete browsers from webbrowser. The removed browsers include: Grail, Mosaic, Netscape, Galeon, Skipstone, Iceape, Firebird, and Firefox versions 35 and below (gh-102871).
Remove zipimport’s find_loader() and find_module() methods, deprecated in Python 3.10: use the find_spec() method instead. See PEP 451 for the rationale. (Contributed by Victor Stinner in gh-94379.)
Remove the suspicious rule from the documentation Makefile and Doc/tools/rstlint.py, both in favor of sphinx-lint. (Contributed by Julien Palard in gh-98179.)
Py_TPFLAGS_DISALLOW_INSTANTIATION
Legacy Unicode APIs based on Py_UNICODE* representation has been removed. Please migrate to APIs based on UTF-8 or wchar_t*.