Other Goodness to Explore
00:00
In the previous lesson, I covered the additions to the pathlib
module. This lesson covers some of the other things in 3.13 that I don’t have time to go into in detail.
00:10
The locals()
built-in function returns a dictionary containing all the variables within local scope. This probably contains more than you might think due to system values like __file__
that contains the name of the file being run. Several releases back, some internal changes were made to how locals()
were handled within the context of a function to speed things up.
00:31 But the changes were only within the context of a function, not within other contexts, like classes. Inconsistency can cause problems, and this particular inconsistency was the source of some tricky little bugs within the threading library and other places.
00:46 As such, PEP 667 aims to put things back to a consistent form, and as you might guess by the fact that I’m talking about it, PEP 667, neighbor of the beast, got implemented in Python 3.13.
00:59
This little slice of code creates a local value named frame
_locals
, and inside of the list comprehension sets the value to be the contents of f_locals
.
01:09
This is the internal mechanism used by the locals()
function to determine what is in local scope. The result here is empty because list comprehensions are self-contained and don’t actually update the local context.
01:22
But in Python 3.12, this wasn’t true because of those aforementioned optimizations there was stuff in here instead, including the comprehension’s value of number
.
01:33
And even if you did expect the values from the comprehension to be there, you definitely wouldn’t expect it to be there outside of the comprehension. Except in Python 3.12, the value number
leaked out.
01:46 This has been changed in 3.13. None of this is likely to affect you unless you’re doing some very deep dark stuff. For 99.99% of us, this change should go unnoticed, but consistency typically means fewer bugs, which is better for all of us.
02:03 The last few releases of Python have made an effort to improve performance in the CPython interpreter. This release also touches on a couple of things. A bunch of the modules in the standard library have been given an overhaul to improve loading times.
02:17 Most of these were done by changing some of the imports in the module into conditional imports for their specific cases.
02:24
Keeping with the theme of deprecation I mentioned before, the argparse
module now also supports a parameter to indicate that an argument has been deprecated.
02:34
When I showed off the changes to the REPL and errors, you saw how some output has been colorized. I missed one. The doctest
output has also been brought out of the black and white age.
02:46
There’s a lesser-known function in the importlib
module called resources()
that allows you to dynamically import non-code files as assets.
02:54 For example, this can be used to grab images or sounds stored in your package. Until Python 3.13, this was for single files. Now you can load a directory as well.
03:06
If you’ve ever used the breakpoint()
or set_trace()
functions to programmatically stick a breakpoint in your code, you may have noticed that the entry point in your debugger is actually the line after the breakpoint.
03:18
This can be confusing, especially if it’s the last line of code in a function or program. To make it easier to understand, the entry point is now on the line that says breakpoint()
or set_trace()
instead. Python works on all sorts of platforms and there has been work ongoing for a while to support the mobile space.
03:37 Python 3.13 has officially added iOS as a supported platform, and work is happening for Android and it should get added soon as well.
03:47 If you’ve been keeping up with the last few releases, a whole bunch of old modules that are seldom used have been deprecated and removed. Python 3.13 is the last big chunk of this effort, and a whole bunch of the dead batteries are now gone.
04:03 In the last lesson, I’ll summarize the course and point you at a few places in case you want more information.
Become a Member to join the conversation.