As a fall-back source of data for platforms that don’t ship the IANA database, the
tzdata
module was released as a first-party package – distributed via PyPI and maintained by the CPython core team.
改进模块
¶
ast
¶
添加
indent
选项到
dump()
which allows it to produce a multiline indented output. (Contributed by Serhiy Storchaka in
bpo-37995
)。
添加
ast.unparse()
as a function in the
ast
module that can be used to unparse an
ast.AST
object and produce a string with code that would produce an equivalent
ast.AST
object when parsed. (Contributed by Pablo Galindo and Batuhan Taskaya in
bpo-38870
)。
Added docstrings to AST nodes that contains the ASDL signature used to construct that node. (Contributed by Batuhan Taskaya in
bpo-39638
)。
asyncio
¶
Due to significant security concerns, the
reuse_address
参数对于
asyncio.loop.create_datagram_endpoint()
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
bpo-37228
)。
添加新
协程
shutdown_default_executor()
that schedules a shutdown for the default executor that waits on the
ThreadPoolExecutor
to finish closing. Also,
asyncio.run()
has been updated to use the new
协程
. (Contributed by Kyle Stanley in
bpo-34037
)。
添加
asyncio.PidfdChildWatcher
, a Linux-specific child watcher implementation that polls process file descriptors. (
bpo-38692
)
添加新
协程
asyncio.to_thread()
. It is mainly used for running IO-bound functions in a separate thread to avoid blocking the event loop, and essentially works as a high-level version of
run_in_executor()
that can directly take keyword arguments. (Contributed by Kyle Stanley and Yury Selivanov in
bpo-32309
)。
When cancelling the task due to a timeout,
asyncio.wait_for()
will now wait until the cancellation is complete also in the case when
timeout
is <= 0, like it does with positive timeouts. (Contributed by Elvis Pranskevichus in
bpo-32751
)。
asyncio
现在引发
TypeError
when calling incompatible methods with an
ssl.SSLSocket
socket. (Contributed by Ido Michael in
bpo-37404
)。
compileall
¶
Added new possibility to use hardlinks for duplicated
.pyc
文件:
hardlink_dupes
parameter and –hardlink-dupes command line option. (Contributed by Lumír ‘Frenzy’ Balhar in
bpo-40495
)。
Added new options for path manipulation in resulting
.pyc
文件:
stripdir
,
prependdir
,
limit_sl_dest
parameters and -s, -p, -e command line options. Added the possibility to specify the option for an optimization level multiple times. (Contributed by Lumír ‘Frenzy’ Balhar in
bpo-38112
)。
concurrent.futures
¶
添加新
cancel_futures
参数用于
concurrent.futures.Executor.shutdown()
that cancels all pending futures which have not started running, instead of waiting for them to complete before shutting down the executor. (Contributed by Kyle Stanley in
bpo-39349
)。
Removed daemon threads from
ThreadPoolExecutor
and
ProcessPoolExecutor
. This improves compatibility with subinterpreters and predictability in their shutdown processes. (Contributed by Kyle Stanley in
bpo-39812
)。
Workers in
ProcessPoolExecutor
are now spawned on demand, only when there are no available idle workers to reuse. This optimizes startup overhead and reduces the amount of lost CPU time to idle workers. (Contributed by Kyle Stanley in
bpo-39207
)。
distutils
¶
The
upload
command now creates SHA2-256 and Blake2b-256 hash digests. It skips MD5 on platforms that block MD5 digest. (Contributed by Christian Heimes in
bpo-40698
)。
fcntl
¶
添加常量
F_OFD_GETLK
,
F_OFD_SETLK
and
F_OFD_SETLKW
. (Contributed by Donghee Na in
bpo-38602
)。
ftplib
¶
FTP
and
FTP_TLS
现在引发
ValueError
if the given timeout for their constructor is zero to prevent the creation of a non-blocking socket. (Contributed by Donghee Na in
bpo-39259
)。
gc
¶
When the garbage collector makes a collection in which some objects resurrect (they are reachable from outside the isolated cycles after the finalizers have been executed), do not block the collection of all objects that are still unreachable. (Contributed by Pablo Galindo and Tim Peters in
bpo-38379
)。
添加新函数
gc.is_finalized()
to check if an object has been finalized by the garbage collector. (Contributed by Pablo Galindo in
bpo-39322
)。
hashlib
¶
The
hashlib
module can now use SHA3 hashes and SHAKE XOF from OpenSSL when available. (Contributed by Christian Heimes in
bpo-37630
)。
Builtin hash modules can now be disabled with
./configure --without-builtin-hashlib-hashes
or selectively enabled with e.g.
./configure --with-builtin-hashlib-hashes=sha3,blake2
to force use of OpenSSL based implementation. (Contributed by Christian Heimes in
bpo-40479
)
IDLE and idlelib
¶
Added option to toggle cursor blink off. (Contributed by Zackery Spytz in
bpo-4603
)。
Escape key now closes IDLE completion windows. (Contributed by Johnny Najera in
bpo-38944
)。
Added keywords to module name completion list. (Contributed by Terry J. Reedy in
bpo-37765
)。
New in 3.9 maintenance releases
Make IDLE invoke
sys.excepthook()
(when started without ‘-n’). User hooks were previously ignored. (Contributed by Ken Hilton in
bpo-43008
)。
The changes above have been backported to 3.8 maintenance releases.
Rearrange the settings dialog. Split the General tab into Windows and Shell/Ed tabs. Move help sources, which extend the Help menu, to the Extensions tab. Make space for new options and shorten the dialog. The latter makes the dialog better fit small screens. (Contributed by Terry Jan Reedy in
bpo-40468
.) Move the indent space setting from the Font tab to the new Windows tab. (Contributed by Mark Roseman and Terry Jan Reedy in
bpo-33962
)。
Apply syntax highlighting to
.pyi
files. (Contributed by Alex Waygood and Terry Jan Reedy in
bpo-45447
)。
imaplib
¶
IMAP4
and
IMAP4_SSL
now have an optional
timeout
parameter for their constructors. Also, the
open()
method now has an optional
timeout
parameter with this change. The overridden methods of
IMAP4_SSL
and
IMAP4_stream
were applied to this change. (Contributed by Donghee Na in
bpo-38615
)。
imaplib.IMAP4.unselect()
is added.
imaplib.IMAP4.unselect()
frees server’s resources associated with the selected mailbox and returns the server to the authenticated state. This command performs the same actions as
imaplib.IMAP4.close()
, except that no messages are permanently removed from the currently selected mailbox. (Contributed by Donghee Na in
bpo-40375
)。
importlib
¶
To improve consistency with import statements,
importlib.util.resolve_name()
现在引发
ImportError
而不是
ValueError
for invalid relative import attempts. (Contributed by Ngalim Siregar in
bpo-37444
)。
Import loaders which publish immutable module objects can now publish immutable packages in addition to individual modules. (Contributed by Dino Viehland in
bpo-39336
)。
添加
importlib.resources.files()
function with support for subdirectories in package data, matching backport in
importlib_resources
version 1.5. (Contributed by Jason R. Coombs in
bpo-39791
)。
Refreshed
importlib.metadata
from
importlib_metadata
version 1.6.1.
ipaddress
¶
ipaddress
now supports IPv6 Scoped Addresses (IPv6 address with suffix
%<scope_id>
).
Scoped IPv6 addresses can be parsed using
ipaddress.IPv6Address
. If present, scope zone ID is available through the
scope_id
attribute. (Contributed by Oleksandr Pavliuk in
bpo-34788
)。
Starting with Python 3.9.5 the
ipaddress
module no longer accepts any leading zeros in IPv4 address strings. (Contributed by Christian Heimes in
bpo-36384
).
math
¶
Expanded the
math.gcd()
function to handle multiple arguments. Formerly, it only supported two arguments. (Contributed by Serhiy Storchaka in
bpo-39648
)。
添加
math.lcm()
: return the least common multiple of specified arguments. (Contributed by Mark Dickinson, Ananthakrishnan and Serhiy Storchaka in
bpo-39479
and
bpo-39648
)。
添加
math.nextafter()
: return the next floating-point value after
x
towards
y
. (Contributed by Victor Stinner in
bpo-39288
)。
添加
math.ulp()
: return the value of the least significant bit of a float. (Contributed by Victor Stinner in
bpo-39310
)。
nntplib
¶
NNTP
and
NNTP_SSL
现在引发
ValueError
if the given timeout for their constructor is zero to prevent the creation of a non-blocking socket. (Contributed by Donghee Na in
bpo-39259
)。
pdb
¶
On Windows now
Pdb
supports
~/.pdbrc
. (Contributed by Tim Hopper and Dan Lidral-Porter in
bpo-20523
)。
poplib
¶
POP3
and
POP3_SSL
现在引发
ValueError
if the given timeout for their constructor is zero to prevent the creation of a non-blocking socket. (Contributed by Donghee Na in
bpo-39259
)。
pydoc
¶
The documentation string is now shown not only for class, function, method etc, but for any object that has its own
__doc__
attribute. (Contributed by Serhiy Storchaka in
bpo-40257
)。
random
¶
添加新
random.Random.randbytes
method: generate random bytes. (Contributed by Victor Stinner in
bpo-40286
)。
smtplib
¶
SMTP
and
SMTP_SSL
现在引发
ValueError
if the given timeout for their constructor is zero to prevent the creation of a non-blocking socket. (Contributed by Donghee Na in
bpo-39259
)。
LMTP
constructor now has an optional
timeout
parameter. (Contributed by Donghee Na in
bpo-39329
)。
time
¶
On AIX,
thread_time()
is now implemented with
thread_cputime()
which has nanosecond resolution, rather than
clock_gettime(CLOCK_THREAD_CPUTIME_ID)
which has a resolution of 10 milliseconds. (Contributed by Batuhan Taskaya in
bpo-40192
)
sys
¶
添加新
sys.platlibdir
attribute: name of the platform-specific library directory. It is used to build the path of standard library and the paths of installed extension modules. It is equal to
"lib"
on most platforms. On Fedora and SuSE, it is equal to
"lib64"
on 64-bit platforms. (Contributed by Jan Matějek, Matěj Cepl, Charalampos Stratakis and Victor Stinner in
bpo-1294959
)。
先前,
sys.stderr
was block-buffered when non-interactive. Now
stderr
defaults to always being line-buffered. (Contributed by Jendrik Seipp in
bpo-13601
)。
tracemalloc
¶
添加
tracemalloc.reset_peak()
to set the peak size of traced memory blocks to the current size, to measure the peak of specific pieces of code. (Contributed by Huon Wilson in
bpo-40630
)。
typing
¶
PEP 593
introduced an
typing.Annotated
type to decorate existing types with context-specific metadata and new
include_extras
参数用于
typing.get_type_hints()
to access the metadata at runtime. (Contributed by Till Varoquaux and Konstantin Kashin.)
unicodedata
¶
The Unicode database has been updated to version 13.0.0. (
bpo-39926
).
venv
¶
The activation scripts provided by
venv
now all specify their prompt customization consistently by always using the value specified by
__VENV_PROMPT__
. Previously some scripts unconditionally used
__VENV_PROMPT__
, others only if it happened to be set (which was the default case), and one used
__VENV_NAME__
instead. (Contributed by Brett Cannon in
bpo-37663
)。
xml
¶
White space characters within attributes are now preserved when serializing
xml.etree.ElementTree
to XML file. EOLNs are no longer normalized to “n”. This is the result of discussion about how to interpret section 2.11 of XML spec. (Contributed by Mefistotelis in
bpo-39011
)。