In previous versions, this was how to schedule a collection of
async tasks and
await on them.
Now we can simply enter into a TaskGroup context.
In previous versions, we needed to use an external library to load and manipulate
toml formats. Now we can utilize tomllib straight out of the box.
In previous versions, we had to keep a historic record to switch into a directory and back.
Now we can simply contextualize it.
In previous versions, we couldn’t directly reference the class as return type.
For example, we would get
NameError when running the following code.
Now we are able to reference using
Self without having to resort to a workaround of declaring a new
T to represent the class.
In previous versions, function overloading was not possible - in the conventional sense. We would “imitate” the overloading behavior by implementing enumerated function parameters and conditionally outputing the result. The downside is that this increases complexity of supposed “overloaded” function and keeping track of the logical bifurication.
Now we are able to utilize
functools.singledispatch and type signatures to behave similarly.
In previous versions of
shutil.make_archive, we needed to temporarily switch the current working directory to archive file/directory (e.g.
xztar, etc.) to its relative paths - similar to the following shell pattern:
Now we can just pass the new
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
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.
Instead of doing this:
We can just do this:
I use these type hint notations in my codebase - but with
3.12, the naming convention has been changed to
asyncio.get_event_loop(), which returns the event loop of the current async context, will now
DeprecationWarning if there is no context event loop.
runtime_checkable decorator will now freeze the members of
From Unicode objects, the
wstr_length have been removed. This reduces the object size by 8 or 16 Bytes on 64-bit platforms.
Great news for regular expression lovers like myself! Regex-based substitutions will be faster by 2~3x for expressions containing group references (like
perf profilers will now report function names in the trace logs.