- Podcasts
- Python Bytes
- #307 Your Python just got faster (3.11 is out!)
#307 Your Python just got faster (3.11 is out!)
Python Bytes
- October 26, 2022
- 45 min
- Episode 307
About this episodeTopics covered in this episode: Python 3.11 is released Installing Python 3.11 on Mac or Windows Bossie 2022 Awards Textual 0.2.0 Extras…
- Python 3.11 is released
- Installing Python 3.11 on Mac or Windows
- Bossie 2022 Awards
- Textual 0.2.0
- Extras
- Joke
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
#307 Your Python just got faster (3.11 is out!)
Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds. This is episode 307, recorded October 26th, and I am Brian Okken. Hey, I'm Michael Kennedy. Yay. Well, it's pretty exciting here in Python world this week. Oh, it's a big deal this week, absolutely.
It's a big deal. So tell us why it's a big deal. We've talked about Python being faster and new features coming along. But primarily, I would say there's like two ends of the spectrum that people have been really looking forward to. One is, wouldn't it be great if you did nothing and your code ran 50% faster?
Brian, you and I are of similar age, and I remember it was just like, well, wait till next year till I get a new computer. And that program that's a little sluggish is going to be zooming along, right? And just like computers would just double in speed all the time. And we don't get so much of that anymore.
But with Python, we kind of do this time around. Yeah, I remember like also like adding more memory and trying to detect whether I could tell a difference for the $100 I spent. Yes, exactly. Exactly. Or optimizing your low MIM versus high MIM. I mean, that's going back always. But the big news is Python 3.11 is out.
I remember when I got my Pentium 90, it had a turbo button. And I'm like, yes. What it really meant is if it was off, it would run in like some weird retro slow modes. I would like play MechWarrior. And stuff would like zoom around insanely fast. But if you took off turbo, you could play some of the older games because they weren't based on time.
They were based on frame rate. Anyway, crazy, crazy memories. So we're kind of getting that cool like doubling of speed thing here. So there's a ton of stuff to talk about in terms of what's available here. Before I get into the details, I want to point out on YouTube, which I'm linking to, Python Discord, Lemon over there, hosted a live stream of the release.
And like, right, like the actual pushing of the deployment. And there's a bunch of interesting things that happen there. And along the way, they talk about some of the features. I'm going to have a subset of the people that were there in apparently 46 hours on Friday on Talk Python to make an episode out of it there as well.
That's pretty cool. It's neat that they do that. Yeah. So people can just watch the process. Yeah, it is cool that they do that. And I certainly, I saw a pop up and like, these guys are going live. I'm like, oh, that's playing on the background while I'm working today. You know, I'm going to be apparently at 80% capacity of like getting stuff done, but I'm going to enjoy it a lot.
Also, we have a logo, which is not the official Python logo, but a Python 311 logo. And it has like little, it's like two snakes, but they're not the Python, you know, cartoon, dramatic, like sort of stylized snakes. They just look like snakes. And it says faster Python exception groups and accept star typing improvements.
And like literally the logo basically is the release notes. But, and it has a lightning bolt in the middle. I guess that means fast. I think so. I think so. All right. So let's see. Major new changes. We've got fine grained error locations and tracebacks. Let me see if I can get it to show us some interesting example here.
Yeah, this is super cool. So check, there's a line. If you just follow the PEP there, there's an example of, you know, suppose you're calling like a complicated JSON API and you get this data back and you start in a variable X. And you've got to go to some field in the JSON document, then further down, then further down, and further down, and like either get or set a value.
Which one was it? Right. It could have been B wasn't subscriptable, or it could have been C, or it could have been like, you don't know where. And so what a hassle, right? And you do print statements, and that's when you do debugging statements. That's when you maybe make that four different lines so you see which line crashes.
Well, in 3.11 now it just says tilde, tilde, tilde, carat, carat, carat. Look, it's, you had X of A of B of C. It's C that was the none thing. That's where the problem was. Actually, I suspect that, yeah, I guess it's probably C. We tried to get D out of none, and C was none is probably where the error was.
Yeah. But it points like right where these problems are throughout there. Yeah. Really neat. Plus a whole bunch of others. Yeah, there's a bunch of other ways that they're highlighting where the problem is. Yeah, if you go through, there's a bunch of cool examples here. But basically, you end up with within complex expressions.
You know, multiple things happening on one line and so on. You get nice details there. Pretty cool. So that's just one of them. But I would say if you don't care about performance, that's probably what you might consider the highlight. If you're an asyncio, async and await type person, async exception groups, PEP 564 and accept star are pretty interesting.
Indeed. Some of the higher level async frameworks like Trio and AnyIO have this concept of starting and managing a series of tasks together as a group. So if I'm going to save and entry to the database, I'm going to call an API and I'm going to create a file. And those are all the, all a result of like, I want to create a new user.
I want to do whatever. Right. You might want to be able to say, I want to start all those and wait for them to finish. Or if I start a couple of them to decide I want to bail out, cancel all of them or if one fails and so on. So we've got this concept of a task group in AsyncIO and changes to the task cancellation semantics.
And it's interesting. We've got, you know, PEP 657 was the traceback enhancements. 654 was the exception groups. But the task groups is GH 90908. Interesting. You know what GH stands for? GitHub. Okay. Weird. So it's news to me that this, these features git added through just a GitHub issue rather than a proper, you know, PEP.
But anyway, yeah. Pretty neat. Maybe you're pronouncing GH as P. Yeah. Like it. Exactly. Let's see. Henry has some cool comments following up out there. Henry Schreiner. Thanks. Catters is already using exception groups via backport exception group. It is fantastic and really does change Python exceptions.
Cool. Cool. Cool. Extra information there. All right. Let's keep going. You've already talked about TomlLib being built in. Like now that we have pyproject.toml. Should we really have external libraries in order to understand them? Yay. Now we, now we get to do the if block. If, if, if import TomlLib or, you know, the try except around it.
That is Mark Shannon, Gita Van Rossum, and a bunch of other folks, Grant and others, all working on this. And it says already yielding some exciting results. Python 3.11 is up 10 to 60% faster than just 3.10. That is just from last year. Right? Right? Hence the turbo button. On average, we measured a 1.22 or otherwise known as 22% feed up on the benchmarks for Python tests.
Yeah. Pretty exciting. A bunch of stuff around typing. Those are a lot of the other highlights there. Two things that are worth calling out here, I would say. One is self. It's good to be self-aware, right, Brian? Yeah. It is. And so, Python classes can now understand that they too have a self, even though they say self all over the place.
Like, no, their language, right? Like, this in C++ and C# is a thing you can, but not must use, or you've got to say self. So, ironically, the typing system now also understands self. And you can say, well, the problem was before, if I'm in a class and I have a method of that class that returns an instance of that class, the class is not yet defined as far as Python's concerned until you're to the end.
So, I can't say the return type is the name of the class, because until you're done, the class is not defined, right? It's like this weird error. So, what you can say is it returns self. And whatever self is, that's what it returns. And one of the changes and difficulties was to make this work with inheritance.
Yeah. I mean, like in C or in C++, you have to pre-declare the type ahead of time. But then, yeah, anyway. We don't have declarations in Python, so. We don't. I wonder why we don't have a two-pass compiler that like scans for types and then expands out the details. Do you know what variadic generics are?
Putting you on the spot. Sorry. You are putting me on the spot. Let's see. I just want to use that word more often. I know. I know. It sounds like. Yes, I do have a PhD in computer science. It enables the creation of generics parametrized with a single type. So this is something I don't do much of in Python types.
And then I can say I have an array, which is of type, you know, of generic, of axis one, axis one, right? Like, I don't know. I kind of left that kind of stuff behind in C++, like the multiple template. Oh, good. Somebody's helping us out. Dean is saying, when I learned about generic, I thought maybe we've gone too far with typing.
Thanks, dude. You know, one thing that's nice about Python is often you don't have to know or care or consume certain parts. You know what? That doesn't apply to me yet. Maybe someday. Not right now. There's other stuff, of course. The last one I think is noteworthy has to do with limiting the spread of little Bobby tables, let's say.
And these are arbitrary literal string types. So the idea is if you've got, say, like a SQL query, it would be great to somehow define, here's a string that I want to put into code, but I don't want to, it's kind of like a static string in a sense. Like it can't be modified or added against non-literal strings.
Right? Like these are bad. So what you can do with these now is you can come up with literal strings and they, in order to make the query work, you have to use database parameters. You just put like a placeholder in the string that never changes. And that way, basically your string in a sense is safe from injection.
Okay. Yeah. But you can still, you still can pass parameters in, but you just have to do it a different way. Right. And so in this example, they have select, select user.name, user.age from data where user ID is question mark. That's the indicator of a SQL parameter. And then you say connection execute given that string.
And then you pass the parameter, which has the value of the user ID. And then the database engine knows like that can't like truncate a statement. Right. It can't sort of modify the command you send. What's notable though, is you can also add on things and you can change it and combine it with other literal strings, but not with non-literal strings.
The Python bytes. Python bytes website is based on Beanie, the MongoDB, Pydantic combo of glory. Because it's all async. It's based on motor. The async driver for Python and MongoDB from the MongoDB folks. They built that thing in the super early days before async and await was a thing based on tornado.
So, they don't use async def for their async functions. They put at async.io.coroutine as a decorator onto all their async functions. Well, that was awesome until 3.11 where that was removed from the runtime. So, that doesn't work anymore. And it doesn't run so well either. So, the motor people had to rush out 3.11 yesterday after much conversation of like, you guys realize you should have tested on 3.11 beta or RC1 or RC2 or any other release at some point because clearly this code was never going to run and you should have known straight away.
I said, oh, cool. Then I'll install Python 3.11. Okay. Yeah, that's how I know. So, I want to stick with this install thing a little bit. Yeah. Because I would think that you're probably a power user. I mean, kind of. You know Python pretty much and you're doing, trying to be cutting edge and everything.
I think that a lot of Python bloggers and social media people that are famous in Python are probably the power user kind of people. And they tell people weird things, I think. Like brew install Python 3.11. Just brew install. And I don't think it's a good idea. Yeah. I'm going to get on the soapbox a little bit and say, I wrote an article on how to install Python.
But that's okay. It's kind of what I want. I've got 310. You can have multiple. I've got 310, 3.7, 3.11 all on my machine just with those links. And the 3.11 just is the default. I think it's the newest one and the oldest. Anyway, it modifies the Z profile, your .Z profile. And it shows up as the latest one.
Now, if I had 310 before, what if I go back and install the update my 310? Will it make 310 the default? No, it doesn't. It leaves it alone because it was already in there. It leaves it be. But you should check anyway if you're going to go back and install old versions. And Tox works just great with it.
But PyEnv is about managing different versions and having multiple live at the same time and different projects use different ones. It's not just an easy installer. And since it does all that other stuff, I don't think people should recommend it for newbies. It's not the right tool for somebody new to Python.
I think it's just going to confuse the heck out of people. So that said, I walked through the whole thing in this article. But I also admit that it's Mac focused. But on the Windows, I did a little blurb on Windows too. The thing I want to tell people that I sometimes forget on the Windows install is go slow when you're clicking through everything so that you can select the advanced features.
And you probably want add Python to environmental variables. That makes it so that just shows up in your path. Because you can add that to your path manually or you can let the installer do it. And I like to have the installer do it. So that's my rant. I think that for most people, just use the default installer.
I just decided to take 3.9 out because I didn't really need that. I've got it from homebrew as well already. But they do coexist. It's fine. And here's what the brew statement is. It's new formulae. And it's Python at 3.11 is what you can expect. Okay. Nice. Yeah. And as for Linux people, I think it's sort of funny that people try to tell how to install Python articles, talk about Linux stuff.
Linux people already know how to install their stuff, don't they? I mean. Yes. But although it's more complicated because Python's broken into a bunch of pieces. You want Python? Or do you want the Python dev bit? Or do you need the build essentials? Or like there's a lot of like, do you need Python 3-V and V?
Microsoft for Startups Founders Hub. Has, they have been recently big supporters of the show. We really appreciate it. And if you're out there either starting a business or want to start a business, got to know that it's, it's not easy, right? Within the first year, 90% of startups go out of business.
That's not amazing. So the folks over at Microsoft for Startups set out to understand what are the problems that people are running into and how could they help? So they came up with Microsoft for Startups Founders Hub. And the idea is that you get at any stage of your startup free resources to grow and thrive.
Like those, those kinds of things are incredibly powerful. And they've given people in locations like that huge advantages. So the other thing you get with this is access to a mentorship network, the ability to book one-on-ones with meetings, one-on-one meetings with mentors, many of whom are founders themselves.
You can talk about things like marketing or fundraising or whatever you need. So if you want to get started, make your dream, your company a reality today with the critical support you get from Microsoft for Startups Founders Hub. You don't have to be third-party validated. You don't have to be venture-backed or part of some kind of accelerator.
Yes. Let's talk about the Bossies. So the Bossies, this is InfoWorld's 2022 Bossie Awards. Celebrate the most important and innovative solution for application developments, DevOps, analytics, and what year. So let's go. These are open source. Best open source software. I was like, where does Boss come from?
Okay. Exactly. There's a bunch that are interesting, but we'll go through. You can't go through very fast. There's like a delay. Yeah, I guess. So you pay attention and you actually take it in. So maybe really quick, just because it's the first one, is there's Alma Linux, which is a free Linux OS for the community, by the community, that is like an enterprise Linux distribution focused on stability.
That'll be fun. Like Jhipster. I mean, greetings, Java hipster. That's a pretty awesome project. Java hipster. That seems sort of anachronistic. You know, you got to, this is part of that self-talk thing where you like try to talk yourself up a little. All right. Maybe number one that I want to give a shout out to, number one, as in number 10 in the list, is WASM time.
A fast and secure runtime for WebAssembly outside of the browser. So if you think about what Node.js did for JavaScript, like JavaScript used to be this thing you did on web front ends. And then somebody said, if we rip that engine out, it could be a server-side technology or a client-side technology that is not in a browser at all.
But just, it becomes a programming language, as long as we have a runtime that everyone likes and works with. Well, this is like that, but for WebAssembly, right? And so what's interesting is if you want to go and run a Python code and you don't want to worry about making sure Python is set up and all those things, you could just get, say, something like PyScript and ship it to run on top of WASM time.
So if I wanted to do C, .NET, Python, and Rust, have those all talk together because, I don't know, I couldn't decide or I don't know, whatever reason, right? You could have them all converted to WASM and then integrate there as well. So there's some pretty interesting runtime and deployment things here.
I was just using this to track down some errors that I introduced with trying to run Python 3.11 and Beanie before it was time. But it told me exactly what was going on and I figured, okay, that's a motor problem. I was able to track that down, which is pretty excellent. Let's see a few more here that are fun.
In BDEV, if you're doing notebook stuff and you want to be able to test your notebooks or clean them up before you check them in, or you want to turn notebooks into a Python package where certain actions in a cell become functions in your Python package and deploy it to PyBI. All those crazy things in BDEV.
It's wasm time. Yeah. We talk about Will McGugan a lot and textural and stuff. And Will's in the audience. Hey, Will. So one of the things that if you follow Will on Twitter, he shows a whole bunch of cool examples of stuff he's working on, but you haven't been able to play with it because he's been sneaky about it.
And it's been on a, well, it's not sneaky, but it's been on a CSS branch, different branch of their code base on textualize or textual. So now we can play with it because as of what, October 22nd, textual 0.2.0. Wow. Big jump in numbers there, guys. But it released and it has all of the CSS branch stuff merged in.
So all the really cool, fun things that you can do that looked like web development and, but they're in a CLI. Now I can start playing with them because they merged in. One of the things that I'm glad that they waited a little while for because they were looking for API stability, but also they wanted to finalize the documentation at the same time before they released it to everybody officially.
So they've got a tutorial written, which is really kind of nice. It's a little stopwatch application that kind of walks through and it walks through all the different pieces of, of how you, how you use textualize and with their CSS. And it's got going through writing through the CSS, the dynamicness of it, reactive attributes.
But anyway, really great stuff in this, in this, this manual. Good job guys. Yeah, that looks awesome. So I can't wait to play with it. Yeah. Who knew that we could treat, treat terminals as high refresh rate, general rendering engines. It's, I feel like the stuff that Will and crew are highlighting here is a little bit like what you could do with JavaScript canvases, right?
And I also just heard Will talking about this on ChangeLog just recently. One of the more recent ChangeLogs was talking about this release, which is pretty cool. Although, Will, I got to say I'm a little disappointed. Because they asked how you became rich and textual have gained so much popularity so quickly.
And you didn't even mention us. Just come on. Anyway. Cool. Anyway, that's it for our items. And since I've been kind of under the weather, I don't have any extras. Do you have any extras for us? You know that I do. I've got a bunch of things. I'll go quick through them. So I recently did a fun video.
I know that guy. Yeah. I did a video where I added, I did the live coding on Talk Python Training, actually adding the feature for the search over here. So I rewrote the search. You pointed out that pytest is a fun thing to type in there, right? pytest is good. You might search for Postman, Ingrok, and you get your search results there.
Got this cool hierarchy thing. But when I first wrote that, it was super slow. And the techniques that I used to debug that, figure out what's going on, make it faster. The video says 17, but in an extreme case, it was actually 80 times faster. There's just some really cool techniques of walking through like, oh, how could you like use logging in the database to figure out what's happening?
How could you use the profiling? How do we use dictionaries so that we can convert like 100 database calls into one, even though there's like a, not a natural join story going on. So if people want to follow, go check out that video. That's lots of fun in the show notes. From, let me get the name right here.
Is there some other weird event that's changing the start to close time? Right. So just a cool little library to bring that into your Pandas code. And I believe Pandas came out of New York and the whole trading industry over there. So that's good. Shout out for Roman Wright, who is out in the audience.
I just want to call this function. And I'm in the middle of a script that has no business being async, but you gave me an async only function. So now I got to figure out how to like spin up a loop and run this thing and wait for it when I just want to call the function. So in addition to the standard async model, Roman added a Beanie.sync submodule where you can get async document and you get a, you can initialize a synchronous database, connection.
DuckDuckGo has released a web browser. Just when you thought Chrome has taken over everything, DuckDuckGo says no, or they quacked no, or whatever DuckDuck does when they communicate. And right now it's Mac only, but it's coming out for Windows pretty soon as well. And it's a privacy focused database.
Web browser. Yeah. Yes. Sorry. I said database. Yeah. Web browser. But let me, let me show you. I can even show you real quick. Here it is. But did you install it? Oh, of course I did. Why wouldn't I do that? Here it is. So we go over here. We can go to pythonbytes.fm. And if you pull this up, why not?
Didn't add to stream. There we go. But come over here to Python Bytes. And you can click on this. It'll show you where all the tracking is. Like notice, no Google Analytics, no other tracking. But where shall we go? We have somewhere super egregious. We could go to CNN.com. And remember, this is using already NextDNS and other blocking.
So that's pretty cool. But I don't know. I'm not switching over to it yet. Hopefully they can do better. You can't do things like set your DNS servers for, say, DNS over HTTPS. So you can have more control over that. There's a lot of things that are not there. It has a really cool way to play YouTube videos in a private window.
It doesn't have any of those types of things. Right. And so it's like super, super early. But in that regard, I'm not really liked or recommending it. But it's awesome that they're trying. I like DuckDuckGo. I'd like to see them make progress here. And they have the fire button, which you can just clear all the stuff up and get a cool animation.
So I want to give credit here. This one comes from Will Shanks. Remember when we talked about int, like I-N-T parentheses, some string, like quote, one, two, three, close quote. Okay. That had a security patch in Python 3.10.7 because if you send it right, malicious, huge number string, it can get into like some denial of service where it like works for an insane amount of time trying to figure out what that number is by parsing it.
Not just a big number, but like a specifically bad big number, I think was the problem. So in 3.10.7, they said, you know what? We're going to limit the size of int to, I don't know, like 94 with 100 zeros or something after it, right? At the time, you and I spoke about, remember when we did C and C++ and C# and we had to think about shorts and, you know, 32-bit integers and 64-bit integers?
Should we say this is like too much of a problem? I mean, I don't really know how they're going to avoid eventually adopting it. Because like every version of Python going forward is going to have this in it, right? They don't want to eventually like permanently be held back. But on the other side, the, what's it, Ubuntu?
Let me look. Yeah, Ubuntu has decided to patch out that int limit. So basically unravel that security fix and preserve the behavior, previous behavior, thinking that the risk is low of getting an integer like that. And it's not worth breaking compatibility for. Okay. So apparently, int, open parenthesis, string, close parenthesis is still controversial.
Good idea. I didn't see that coming. Yeah, we should have coordinated with the Python folks. We could have just released like five really short episodes. Like, still waiting. No, skip to the next one. All right. Well, that's all I got. That's all I got for extras. Well, one of the things I want to extra from the audience.
And how about- Lovely city to visit if you get a chance to. Okay. Cool. How about something funny? Yes. All right. Besides my voice. Here we go. See if I can open the image. It's own glorious. So, Brian, I was thinking about getting a new monitor. I have a fine monitor. It's like a 32-inch 4K monitor.
But I want something kind of widescreen. There was this cool, like, horizontal resolution equivalent in 4K. But it was 40. It was either 40 or 49 inches wide. It was epic. But I didn't get it. So I didn't get it because I thought the curved monitor might be like parabolic echoes for all the work that we do here.
Small font. And it's edge to edge code. There's no PEP 8 ideas on this, right? Look at that. Is that nuts? That is nuts. Yeah. Yeah. Yeah. And the subtitles be like, I heard you like getters. Which apparently, you know, no properties and all that. Yeah. But anyway, I just thought you all might enjoy just checking out this picture of an insane bit of code.
I don't know. But it's got a bit of a curve. Nice. I have to. I have to. I, it's painful to watch that. And I'm not going to throw rocks at this glass house because I'm a C++ developer. And we've got a few pieces of gnarly code that have big long lines. Yeah. For the multiple inheritance, multiple template.
Oh, yeah. And also just bad naming sometimes. And that happens in Java too. You've got big long names. Well, the problem is you've got to get a name something. And then you've got to have a factory something. And you've got to have an iFactory interface of that something. And you've got to mock it out.
