shutil.make_archive
In previous versions of shutil.make_archive
, we needed to temporarily switch the current working directory to archive file/directory (e.g. zip
, tar
, bztar
, xztar
, etc.) to its relative paths - similar to the following shell pattern:
|
|
Now we can just pass the new root_dir
argument.
tempfile.NamedTemporaryFile
’s delete_on_close
This is one of my favorite new features. In UNIX, the tempfile.NamedTemporaryFile
generates a random file under the /tmp
directory to facilitate ephemeral writes and reads (like caching). However, in the old days, we needed to keep track of the filenames if we ever wanted to manually delete them. With the new delete_on_close
boolean parameter, we can now offload this responsibility with .close()
.
os.PIDFD_NONBLOCK
In this version, a new flag to os.pidfd_open(pid: int, flags: int)
has been added to expose PIDFD_NONBLOCK
to Python (a.k.a. opening a file descriptor to a running process in a non-blocking mode).
|
|
Not sure what I’ll be using this for yet, but will be keeping it in mind.
math.sumprod
Instead of doing this:
|
|
We can just do this:
|
|
typing.Hashable
and typing.Sized
I use these type hint notations in my codebase - but with 3.12
, the naming convention has been changed to collections.abc.Hashable
and collections.abc.Sized
.
get_event_loop()
The asyncio.get_event_loop()
, which returns the event loop of the current async context, will now DeprecationWarning
if there is no context event loop.
typing.runtime_checkable
The runtime_checkable
decorator will now freeze the members of typing.Protocol
.
wstr
and wstr_length
From Unicode objects, the wstr
and wstr_length
have been removed. This reduces the object size by 8 or 16 Bytes on 64-bit platforms.
re.sub
Great news for regular expression lovers like myself! Regex-based substitutions will be faster by 2~3x for expressions containing group references (like \1
).
perf
The perf
profilers will now report function names in the trace logs.