Transcript #190: You will now be notified if the Python zipper is broken
Return to episode page view on github00:00 Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to
00:04 your earbuds. This is episode 190, recorded July 8, 2020. At least it's the 8th year.
00:11 I'm not sure what it is in Australia. Is it tomorrow already?
00:14 It's the 9th.
00:14 Oh my God, you're from the future. Anthony Shaw is here and he is from the future.
00:19 That's awesome.
00:20 I'm Michael, as everyone knows. And Anthony, thank you for joining the two of us here on
00:25 the show. Happy to have you.
00:26 Yeah, I'm glad to be here.
00:27 I want to kick this off with, I think, an interesting article. It's by Tom Christie,
00:31 titled Python Async Frameworks Beyond Developer Tribalism. And I think it's a, and Tom Christie,
00:39 if you don't know who he is, he's done some things like the Django REST framework and HTTPX. Of course,
00:45 other people are on those projects as well, but bright guy. And I think it's in part to a reaction.
00:50 We didn't cover this article, but we noticed it prior. An article called Async Python is Not
00:56 Faster. But all of us had some issues with the article itself. And so this isn't a direct rebuttal,
01:03 but it's an interesting read. One of the things Tom Christie's pointing out is just that I think
01:10 that we need to move the Python community beyond polarizing discussions. And I think that Async
01:16 Python is Not Faster was not a helpful discussion, but it's part of it anyway. A little bit of a quote,
01:23 we could probably benefit from a bit more recognition of where there is shared ground
01:27 and in the areas where there's less clarity, have constructive conversations around those.
01:32 And so some of the shared ground Tom points out is kind of one of the things is you really shouldn't
01:39 really care about performance too much when you start a project. The success of a project is more
01:44 related to developer experience and the strengths surrounding the ecosystem of the framework you're
01:50 using, not just whether or not it's faster. And you should care. But we as the Python community do need
01:56 to care about web performance, partly because new projects starting off might decide to go with
02:03 non-Python solution because they fear Python might be too slow.
02:07 And Anthony, how often have either of you heard, oh, we decided to rewrite that and go.
02:11 So we have proper async or we decided to use JavaScript here because it supports async through
02:18 node or something like that. Like I've heard that a lot.
02:20 Yeah, definitely. Lots of projects.
02:22 Yeah. And I'm not sure. I don't know anything about those other languages though. So
02:26 at least I haven't used them, but for me, it would be a mistake because I know Python. I don't know
02:33 those other ones. Okay. So that's one of the points is that maybe we should care a little bit,
02:37 but also we should be careful about the word performance because if you measure performance
02:42 of just a single async function calls with, or a single function call, an async call is going to be
02:51 slightly slower because there's a little bit of async overhead, but we don't use async because we
02:57 want single threaded applications to be faster. We use it because especially IO bound concurrent
03:03 tasks are, they scale better with async. The other aspect we wanted to talk about was there's just
03:11 really, you have to be careful with looking at benchmark data because benchmarks are often geared
03:17 selected to tell the story that the person writing the article wants to convey.
03:24 Or the situation that they're trying to solve, right? They're like, oh, I thought this would help.
03:27 I tried to solve with this. Turns out it doesn't. It must be bad.
03:30 Yeah. Right.
03:31 Okay. So there's some things that they're just reasonable statements and there are some valid
03:36 differences. Like for instance, should web frameworks, the web frameworks we have now,
03:41 should they start converting to async or should we just leave them as they are and develop new frameworks
03:48 that are async native? Those are some differences. There's also different approaches,
03:52 which is part of the confusion and part of the discussion is there's asyncio. There's also trio
03:58 and twisted and curio and you know how to decide which one there is some confusion there. And I think that's
04:04 valid. So the discourse and the discussion is important, but I think it's important Tom points
04:09 out to say, basically we need to keep it. The benefits of adopting genuine collaborative mindset
04:16 are good rather than a competitive mindset. So let's not fight with each other. There may be
04:22 different or everybody's working on different little corners of the landscape, but we're still trying to
04:28 appreciate move the move async and move web forward for Python. So stay positive, be happy.
04:35 Be happy, man. Well, I didn't want to just call this other article out and criticize it because I don't think
04:41 that adds a lot of value. I don't think we want to cover items just to criticize them, except for their rare moments
04:47 where it's getting a ton of attention. And if you think there's an inaccuracy, you probably should call it.
04:52 I'm glad Tom wrote this article. I think Tom wrote it, right? I mean, it's not attributed, but it's from
04:57 basically his organization. So I'm pretty sure.
05:00 Yeah, I had to go look at the GitHub repo to see who did the push, the commits for this article. So, yep, it was Tom.
05:07 What an interesting way to attribute it. Very cool. I honestly believe that other article, which you're linking to,
05:13 is inaccurate. I think it's trying to apply async to a situation where it's not very warranted. It's like,
05:20 this hammer is really bad at unscrewing this nail or this unscrewing the screw. Hammers are bad, right?
05:26 Well, hammers aren't for that. Async stuff is for scaling when there is a waiting period,
05:31 when there's a latency when you're waiting on something. And the setup there was the DB was
05:36 100% maxed out. So there was no way to push that waiting and get more out of the database.
05:41 And there was almost no waiting, like a few milliseconds anyway. And so the overhead didn't
05:46 make any sense. Somebody wrote me and said, Michael, please, I've got to know your thoughts on this.
05:50 So I went ahead and did a little quick test. I've got in my async course, I've got some stuff where
05:55 we go and talk to things on the internet, where there's like ping time latency and stuff. And it
06:00 goes and gets 10 items off a web server. Ping time is like 100 milliseconds or something.
06:05 It was 750% faster to use the async version than not the async version. I changed that number to get
06:12 100 of them. And it went from 50 seconds, almost one minute down to two and a half seconds.
06:18 1,750% faster. Async is about scaling the waiting part. If there's no waiting,
06:25 there's no benefit. There's just overhead.
06:27 The one thing I have to, I guess I'm going to be on the other side a little bit.
06:30 The async is not faster article. One of the things he did point out was a lot of the async
06:35 framework benchmarks are in the benchmark numbers are not really that fair because there's other ways
06:43 you can speed up the other platforms by, for instance, adding processors or CPUs, adding more
06:49 cores to different applications. And that maybe the original application was just misconfigured.
06:56 I think that's valid, but it doesn't mean that async is bad.
07:00 Yeah, it definitely adds some complexity. Go ahead, Nat.
07:02 If you're comparing it with multi-threading, I think that's the comparison. I think if you're
07:07 just looking at, I've got single sequential code, does adding async make it faster? If it's something
07:12 that's IO bound, yes is the answer. But if you're comparing it to multi-threading, so using the
07:17 threading module to spawn threads, then I think that's where you see the performance improvement.
07:22 So I've got some micro benchmarks doing TCP port scanning across all the different ways you can do
07:29 concurrency and parallelism in Python. And async was the fastest of all those options. And it cuts down a
07:36 lot of the overhead from threading because the way that the threads work in Python, they've kind of got
07:42 this bootstrap module that kind of has to load some of the stuff that it needs for context. Whereas async doesn't need that. So it kind of cuts down a lot of that.
07:52 overhead. I think one of the challenges I've had with async in the earlier versions where it got released was the amount of
07:58 boilerplate code and kind of like infrastructure you needed to put in just to do something really simple, which is like, I want to run this function asynchronously. Like I don't care about what how the event loops and all that kind of stuff. Like I've used other languages.
08:13 I want to kick it off and forget it. It's like, why can't I just call this function and let it go? What is all this stuff I'm doing?
08:18 Yeah, exactly. So I've used other languages where the async is a bit more fluent. I've been using the Kotlin async last week, and I've used .NET, C#, the task API, which is really, really nice to use.
08:33 The other challenge is which bit of code owns the event loop? And that's like an anti-pattern where you end up with a god class that's kind of doing everything. And you've kind of then got to think about how you factor the application so that, okay, which bit owns the event loop? How do I construct that? Where does it end?
08:51 We were helping on the RealPython community group. Somebody was asking some questions. They'd async, or is it multi-threading into their code? And we were just trying to get them to refactor it to take all the logic out of the function that was being multi-threaded and put it into the master and just put the minimal amount of code in the threaded function.
09:10 I think there's still a whole bunch of stuff like that, which people need some good learning on and they need to get used to. It's like a different way of writing code. It's not just something that you can sprinkle on top and it suddenly makes your code faster. I think that's part of the misunderstanding.
09:26 Yeah, especially in Python, where it takes that extra step of you've got to manage the loop and then you've got to run it. And it's not like kind of I've kicked off a bunch of stuff and now it's all just happening.
09:36 Yeah, they made that simpler in 3.7 and 3.8. They've kind of got some shortcut modules that, so I think it's now like one or two lines of extra code you need as boilerplate just to get asyncio up and running. So it's a lot better than it was in the earlier versions.
09:52 But even if it's not a lot of extra code, and Tom Christie points this out, multi-threading and async are more complicated than not. So that's just a reality. Whether or not the code's too much more complicated, the entire design is different. And it's a reality. That isn't to say don't do async or don't do multi-threading. It's just you don't get it for free.
10:16 I think almost the opposite in a sense. I think the code is not complicated enough. On the other hand, like it looks close enough that people don't realize they have to change their mindset and like approach it in an entirely different way. And they feel like, oh, I just call it this way now. But then they run into these issues. They're like, oh, this is broken. Like, why is this not working? Or, you know, like you think you can just do it one way. But you really, if you don't have a little deeper understanding, you can just go down the wrong path also.
10:42 Yeah.
10:43 All right. Well, that was interesting. Thanks for bringing that up. And thanks, Tom, for writing that.
10:47 Anthony, I'm glad you're here to have another opinion as well. I agree that the C-sharp, async and white stuff is, it's like the gold standard. It's really, really well done.
10:55 So let's talk about something way simpler. You want to be a good citizen of your GitHub projects, right?
11:02 Sure.
11:02 Obviously, you want to have good commit messages. There's a major change. You want to bump the version, all those kinds of things, right?
11:08 So you should use commitizen. Commitizen is a command line interface, basically, that wraps around Git. But it has like a menu option for different things. And it guides you through doing them a little bit better.
11:25 So like, you can say CZ, and it'll drop down a list, you can pick commit or whatever. And then it'll ask you questions like, okay, well, what are you trying to do? Are you trying to add a feature? Are you trying to do a bug fix? Or is it a PR? And it'll ask you a couple of questions. And it'll generate interesting things like, hey, is this a breaking change? Would you like me to increment the major version as part of this? And so on.
11:50 So it does all sorts of interesting things around kind of structuring your interaction with Git. So rules for projects, auto bumping versions, auto change log generation, all that kind of stuff. And it's really meant for teams. So they all like interact with Git in a consistent way.
12:05 This is cool.
12:06 Yeah, neat, right?
12:07 Yeah. And if you go to it, it has a beautiful animated GIF showing how it works right on the GitHub repo. Gotta love that.
12:13 So do you, I'm just curious, do you normally commit through command line or through something else?
12:19 No, no, I commit either through PyCharm or SourceTree, depending on what I'm doing.
12:23 Yeah, I do both.
12:24 Yeah.
12:24 If I'm in PyCharm and a project, then I'll do it through there. If I'm doing something else, so like sometimes it's like little hacks or scripts and stuff like that, then I'll do it on the command line.
12:35 Like a presentation that's in, say, PowerPoint or something.
12:38 Yeah, yeah, I'm committing my PowerPoint presentation in.
12:43 Then I'd use the command line, but I've got a whole bunch of aliases to do because you should always sign your commits and stuff like that.
12:49 So put some aliases.
12:50 And something else would be really helpful that a lot of people don't know is that, you know how if you do Git commit on the command line, it uses Vim as the message editor by default.
12:59 You can actually change that. So if you wanted to use another editor like Emacs or Notepad++ or maybe even Microsoft Word, then you can change the configuration in the command line and you never have to use Vim ever again.
13:13 I like that.
13:13 I think a great prank that people should all do.
13:19 Maybe not all.
13:21 Sneak into your co-worker's computer if they run away for lunch and don't lock it and set Word as the editor.
13:27 So next time they go to do something and there's a merge error, like it pops up Word.
13:31 You're like, what in the world is going on here?
13:33 But your commit messages are going to be like 10,000 lines of XML.
13:36 Exactly.
13:38 Exactly.
13:39 Now, that's cool.
13:41 This thing, this commit is in, also comes with a Git pre-commit hook.
13:44 So you can set it up there as well.
13:47 And you can ask it for things like, you just say, run the bump or generate the changelog or validate the schema of a message or whatever.
13:56 So pretty cool.
13:57 It generates a changelog.
13:59 Like I've been looking for something to do that for ages.
14:01 Like I've got projects in Git and when I make a release, I had to like remember what got merged, which PRs got merged, who did them so you could attribute them.
14:11 I don't know what the output is, but it says, you know, CZ space changelog or CH for the shortness is what it will do.
14:20 And it says generates changelog by overriding an existing file if it's already there.
14:25 I don't know how it knows how far back to go.
14:28 Maybe from like a major version bump or something like that.
14:32 But anyway, give it a try and give us a report.
14:35 We'll find out if it's actually useful for you.
14:37 All right.
14:37 Well, that's it for commit is in.
14:39 It seems like a cool little shortcut.
14:41 I don't know if I'll use it or not because I don't work in large teams that really need this very much.
14:46 So it's just like one more thing.
14:47 But if I did, it would be cool.
14:49 Next up, I've got around PyCon.
14:52 Weren't we supposed to meet at PyCon in Pittsburgh and share a beer, the three of us?
14:55 And like, no?
14:57 Didn't happen?
14:57 It didn't happen.
14:58 It was touch and go as well.
15:00 Like I remember even a few weeks before whether or not it was going to happen.
15:05 I mean, I think cancelling, it was definitely the right decision.
15:07 Oh, and it wasn't really cancelled.
15:09 I mean, it was moved online and that's what I wanted to talk about was, you know, with all the PyCons happening all around the world, like I've been looking at which ones have made the move to go online.
15:20 I mean, there's, I guess there's like pros and cons to this.
15:23 I know some people miss out on meeting people and chatting to people and the hallway track and like, you're never going to replace that with an online conference.
15:31 And I think set your expectations low when it comes to interaction with other people.
15:38 But the one big upside is that I think it makes the talks more accessible.
15:45 So if I go to a big PyCon, I'd probably say I watch maybe like 10 talks over the PyCon and there's probably like 100 that I could have watched if I just sat in the talk rooms.
15:56 But like, that's not half the reason I'm there is not to watch the talks.
15:59 Like I watch a lot of them afterwards.
16:00 So I think what's been happening is quite a few PyCons have just cancelled altogether.
16:06 PyCon Israel, Odessa and Ukraine, EuroCyPi, Brazil, PyCon UK, PyCon Thailand, PyCon Spain, DragonPy, which is Slovenia, PyLatam, PyCon DE, which is Germany, and PyCon CZ, which I assume is the Czech Republic.
16:22 They've all been cancelled altogether.
16:26 And then a number of PyCon conferences have said we're going to go online.
16:29 And the cool thing about these is that anywhere in the world, you can go and watch the talks.
16:34 And I think something that's kind of happened as part of this is that some of the big PyCons like US and like Europe, they had like video crews to film the talks and like, you know, write all the subtitles and figure out how all the AV to get the sound nice and stuff like that.
16:54 But other than the really big conferences, the smaller ones couldn't really figure that out.
16:58 So some of them had the talks online, but like the quality was really not watchable.
17:03 But a big change with moving all the talks online is that people are recording at home in lockdown and the quality tends to be a lot better.
17:12 Like you can hear what they're saying and the audio is better.
17:15 And so there's more focus on getting the online experience better.
17:21 And as an added bonus, just as a Python enthusiast even or a PyCon enthusiast, you can just sit and watch PyCon talks from all over the world in your slippers or in your boots if you're in Australia.
17:36 And it's great.
17:37 Like I, you know, beam it onto the TV using Google Chromecast and you can just sit in your living room and watch like PyCon talks from us watching some from Japan, some from like the some of the US conferences, some of the European conferences.
17:51 And there's some really good talks that would have made great talks, you know, the bigger conferences that are in the smaller regional ones that are in there.
18:00 So some of the ones that I found which are online, like on US, obviously, the Python web conference.
18:06 FlaskCon SciPy and PyHEP, which is high energy physics, I think, will be online.
18:14 Europython will be online.
18:16 PyCon Japan, they released a whole bunch of talks this week.
18:20 PyCon AU will be online.
18:22 And I've submitted a talk for that.
18:24 Fingers crossed.
18:25 PyCon Bolivia will be online.
18:27 PyCon ZE, which is South Africa, will be online.
18:30 PyCon APAC in Malaysia will be online.
18:33 Hong Kong PyBay, which is in the US and California and PyCon Africa will all be online.
18:39 So there's at least, from what I could find, at least 15 PyCons around the world.
18:45 So let's say each one has like 50 talks.
18:48 That's like a lot of talks.
18:49 That is a ton of talks.
18:51 And you can just drop into some of these places that you might have a really hard time visiting.
18:56 Like, you know, maybe Malaysia is far away or Africa is far away, but you would love to experience what the community is like there.
19:02 Yeah, a lot of great stuff.
19:03 There are actually a few PyCons that, from what I can tell, are happening in person.
19:08 Around the world, I guess the lockdown situation is very different depending on the country.
19:14 So PyCon Taiwan, PyCon Italia and PyCon Russia, from what I can tell, are still happening.
19:21 So yeah, I know the situation in Taiwan is much better.
19:24 Italy, I think, is late in the year.
19:27 So they're probably hoping that that's going to calm down.
19:29 And Russia, I don't know what's going on there.
19:31 But I picked out a few talks as well that I really liked from some of the regional conferences.
19:36 Deceptive Security Using Python by Kajendra Deshpande.
19:40 If Statements Are a Code Smell by Ali from Chippy.
19:45 That was the PyCon US talk.
19:47 Stop Using Mox by Harry Percival.
19:50 That's a great talk.
19:51 This one is in Japanese and there are no subtitles.
19:54 But if you speak Japanese, Network Analysis and Text PEP in Analysis, which is like an analysis of all the PEPs.
20:01 By Tomoko Faruqi.
20:03 Using Python to Detect Vulnerabilities and Binaries by Terry Oda.
20:07 That was a good talk.
20:08 And Optimize Python and Django with Postgres Superpowers by Louise Graniank, which was a PyCon US talk.
20:17 So yeah, I made a little playlist of stuff that I really enjoyed from some of the regional conferences.
20:22 And the links will be in the show notes.
20:24 These are all great.
20:25 Yeah, love it.
20:26 And you talked about the smaller conferences not necessarily having the AV setup.
20:31 put things online properly.
20:33 You know, all these talks that went online, they were made digitally native, right?
20:38 They were made first for this experience, right?
20:40 They weren't like, oh, there's a camera way back there and we'll just zoom in and we'll try to show it, right?
20:45 It was like yours.
20:46 You had sort of an introduction.
20:47 It was like the video we got here.
20:49 You came back and talking.
20:51 Then it would just focus in on the screen and whatnot.
20:54 So a little bit different there.
20:56 Yeah, definitely.
20:56 And you should definitely watch Brian's talk from PyCon US.
21:00 I did watch your talk, Brian.
21:01 And you should watch mine as well if you're interested, which is on the wise Python slow and Brian's was on parameter.
21:07 It was on testing, wasn't it, Brian?
21:09 Parameterized testing.
21:10 Yeah.
21:10 Parameterized testing.
21:13 I was surprised to hear my name mentioned in Harry's talk, which is surprising.
21:17 Oh, yeah.
21:18 That's cool.
21:20 Yeah, very nice.
21:21 And it's, you know, it's a bummer to not go to these conferences.
21:24 But at the same time, there are a bunch of people who now can experience those presentations who otherwise wouldn't have been able to.
21:31 Yeah, this is a huge benefit.
21:32 And I'm really excited to see, like you said, there's conferences that either had bad video or just couldn't afford a great AV crew or didn't.
21:42 And some of the conferences will just do, like, the entire day video.
21:45 And you have to pick it out.
21:47 And that's more difficult.
21:48 I'm four hours and 17 minutes into it.
21:50 Like, oh, okay.
21:50 Yeah.
21:51 That's discoverable.
21:52 I'm really excited to be able to see all these videos from all over.
21:55 Although I won't be able to.
21:57 I only speak English.
21:58 So how many languages do you speak, Anthony?
22:01 Oh, me?
22:01 Oh, I'm learning Japanese.
22:03 So I was watching the PyCon JP talk and catching every 10th word.
22:08 Okay.
22:09 And the slides definitely help.
22:12 And I speak Pigeon French as well.
22:13 Okay.
22:14 I was impressed that you were watching the Japanese videos.
22:16 That's how I discovered this, your Python testing with pytest book in Japanese.
22:21 It was like part of the, it was on the slide.
22:24 And I was like, it just said lots of stuff on the cover in Japanese.
22:28 And then you just saw the word Brian Okken.
22:29 And I was like, oh, I know that guy.
22:32 Yeah.
22:32 I got to try to get somebody that travels to Japan when things open up to pick up a copy
22:37 for me.
22:38 Yeah, definitely.
22:38 Yeah, that's cool.
22:39 Also cool.
22:40 Speaking of your book, people want to support the show.
22:42 They could get your book.
22:43 Yeah, that'd be great.
22:44 I wanted to do something special.
22:46 I was looking at the reviews online on Amazon, but I know there's reviews other places,
22:50 but this was really kind of cool.
22:51 I'm going to do an expert excerpt from Patrick Kennedy's review.
22:55 This book provides a gentle introduction to what the pytest framework is, how to use it,
23:00 and how to develop tests using pytest.
23:03 I had never understood what fixtures in pytest were prior to this book, but now they make complete
23:08 sense to me.
23:09 Excellent book, and I highly recommend it to anyone wanting to learn about pytest.
23:13 So thanks, Patrick.
23:15 That's a cool review.
23:15 And I went and looked at the numbers.
23:18 There's thousands of people that have read the book, and I know many of the listeners have.
23:22 So I would love to hear more reviews.
23:23 So if you have a review somewhere, either on Amazon or Goodreads or somewhere else,
23:28 let me know where the review is, and I'd love to hear what you think.
23:31 That'd be cool.
23:32 Awesome.
23:32 I think the timing for this will still work out, barely.
23:36 Some of our courses are offered in the Humble Bundle right now.
23:40 So there's a special Python Humble Bundle going on.
23:43 This episode will be out in a week, so it should be wrapping up, but it should still be going
23:46 if you listened soon enough.
23:48 I think it ends July 22nd.
23:50 So before then, if you want to get a whole bunch of Python goodies, including three courses
23:56 from Talk Python, go there and check it out.
23:58 And of course, check out all of our courses as well.
24:01 You get a lot for your value, even without the bundle.
24:03 Yeah, for sure.
24:04 Thanks.
24:05 You know what?
24:07 What happens if you try to zip stuff together as an iter tool zip, and they don't match?
24:12 Does the zipper stick at the end?
24:14 Does it go all the way to the end and then come off?
24:16 Is it when your sleeping bag comes apart in the middle and you're like, I'm going to be
24:20 really cold tonight.
24:21 I can't fix this.
24:21 What happens?
24:22 Whatever doesn't fit just gets cut off.
24:24 Brutal.
24:28 Yeah, so I wanted to highlight PEP 618.
24:30 So I have actually run into this a lot.
24:33 So in the normal circumstances, so zip's a cool thing.
24:37 I'm sure everybody's used it, but if you haven't used it before, it just takes two iterables
24:42 or more than one.
24:43 It's often two in my case, but you can do more than two iterables.
24:48 And then makes a new iterable with pairwise tuples of whatever's in there.
24:53 So if you've got a list with 1, 2, 3, and A, B, C in another list, you can zip them up
24:59 and your elements of your new list will be 1A, 2B, 3C, that sort of thing.
25:05 So often they're used where you just kind of know that all the lengths are supposed to be
25:10 the same because if they're not the same, it chops them off.
25:13 You get a list of the shortest common list.
25:17 And that's surprising and sometimes.
25:21 It might be okay, but it's probably indicative of bad data.
25:25 And who knows if it's off by the end or off by the beginning or they shouldn't go together.
25:30 It's not a good sign.
25:31 When I'm using it and it's kind of a mission critical sort of thing, I'm definitely checking
25:36 the lengths first.
25:37 And it annoys me that I have to.
25:39 So the change is in PEP 618, it's not, you know, it has been accepted for 310.
25:45 So it will go into Python 310.
25:47 And the change is really, there's a new keyword.
25:50 So in zip, you can add strict equals true.
25:53 And that will, if the links are not the same, it'll raise a value error.
25:59 So you'll get an exception if the links are not the same.
26:02 So you can just instead, I think it's a good thing.
26:05 It'll simplify a lot of my code.
26:07 Yeah.
26:07 Anthony, what do you think?
26:08 I never use zip.
26:09 I only use it in the answer to a stack overflow question where that's the solution.
26:14 And I copy and paste it into my code.
26:16 Normally about like, how do I merge two dictionaries?
26:18 I think that's like, and it's like, oh, you just do star, star, list, star, star, zip, star,
26:24 star, something.
26:24 And you're like, okay, I don't understand how that works.
26:28 You're like, star, star, maybe more explicit.
26:30 So let's just stick it in and see if it works.
26:33 Yeah, I never use zip.
26:35 So that sounds useful.
26:36 I did stumble across 3.9 has a, some new functions on the strings, remove suffix and remove prefix.
26:44 Yes.
26:45 Yeah.
26:46 So we talked about that last time, which I don't think we've released.
26:49 So you wouldn't know.
26:50 But it's so confusing because string dot, like if you have the word first, the number one,
26:55 then ST and you said strip ST, it's not necessarily taking away the ST.
27:00 It will, but it might also take an S or a T off the front as well.
27:04 Right.
27:05 It's take away all the characters that are in this list, no matter what, not this exact
27:10 substring.
27:11 Right.
27:11 And so, yeah, that's super valuable.
27:13 I'm really excited to have that because it should have been there before.
27:16 I think they should have come up with a more fun exception than a value error.
27:19 Like it could derive from value error, but it should be like, you know, the zipper broke
27:24 exception error or like, come on, opportunity missed.
27:29 All right.
27:29 Let's stick with the standard library.
27:31 This was really interesting to me.
27:33 I've had Paul Gensel on Talk Python recently.
27:36 I don't know if you guys have listened to it.
27:37 So I might not be able to ask you the question with you actually knowing.
27:41 But this always frustrated me when I go to a time delta.
27:46 I do some math, like subtracting one daytime from another.
27:50 I get it back.
27:51 I'm like, cool.
27:52 It has a certain number of seconds.
27:54 It also has days and other things on it as well.
27:57 But those aren't like total days.
27:59 It's not like 7.2 days.
28:01 It's like eight days and then some negative seconds or something weird, right?
28:05 Really weird, like negative and positive time.
28:08 So those are more for like internal computation.
28:10 As far as I can tell, they probably should be hidden.
28:12 But anyway, if I want to know, say, how many hours has it been?
28:17 How do I do that?
28:18 I would go dt.totalseconds.
28:20 Okay, well, there's 60 seconds.
28:22 So I divide by 60.
28:23 And I want to know, that's minutes.
28:24 I want to know hours.
28:25 So I divide by 60 again.
28:26 And I never put it together.
28:28 I don't divide by like 3,600.
28:29 I divide by 60 and then divide by 60.
28:31 So it's clear I'm trying to take away the, you know, get to minutes and then to hours.
28:35 Is there a better way, right?
28:38 Why is there not a total hours, a total weeks, a total months, whatever on there?
28:43 Like, why do I have to always do math whenever I want to know simple things?
28:46 Like how many hours have passed?
28:48 Okay.
28:48 Well, okay.
28:49 So the people who built daytime, or sorry, time delta specifically, they didn't intend you
28:53 to do math.
28:54 They just didn't make it obvious or very discoverable.
28:58 Because time deltas can be divided by time deltas.
29:00 So if I want to know how many hours it's been, I can say like, take the total time delta and
29:05 divide it by time delta where hours equals one.
29:08 Or if I want blocks of six hours, I could divide it by hours equals six.
29:11 If I want to know how many weeks, I would take the total time delta and divide it by time delta
29:17 days equals seven.
29:18 And that'll tell me how many weeks.
29:19 That's pretty awesome.
29:20 I had no idea that it did that.
29:22 I had no idea either.
29:23 And I was complaining to Paul Gansel, who works on this stuff.
29:26 Like, dude, give us something more than seconds.
29:28 Why are we only getting seconds?
29:30 I want total hours.
29:31 I want total days.
29:32 He's like, just divide it.
29:33 Just set the days to be one and divide it.
29:35 I'm like, what?
29:36 You couldn't do that?
29:37 Why didn't anybody tell anybody this?
29:39 Anthony, did you know this?
29:41 No, but this is a podcast.
29:42 So you probably can see I had my head in my hands for that explanation.
29:45 But division operator would be like, with the last thing I'd ever try.
29:50 I know.
29:50 Yeah, me too.
29:51 I really thought I'm just like, this is the official.
29:55 This is really the way.
29:56 Yeah.
29:56 I mean, yeah, this is the way.
29:58 But after this episode came out, Jeff went to, I don't know his last name, but on the comment,
30:04 he said his name was Jeff.
30:05 So Jeff went to the episode page and said, learning you can divide a time delta by time delta to
30:09 come up with days, weeks, et cetera, is like the Python tip of the year.
30:12 It's certainly going to save me a lot of pain going, wait, there's two 60s.
30:18 I divide by 60 twice.
30:19 Sorry, that was actually hours, not days or whatever, like weird 60th of what I wanted
30:26 or 60 times as many days as I meant.
30:28 So yeah, you could divide a time delta by some arbitrary time delta, like days equal five,
30:35 and you'll get how many blocks of five days would have been in there as a number.
30:39 I'm not saying this is how it should be, but I'm telling you, this is the way to figure
30:44 out time ranges in Python standard library without doing math.
30:49 Well, so I looked it up.
30:51 There's, it isn't obvious that, I mean, it does say that you can do division, but there's
30:56 all sorts of other stuff too.
30:57 You can do like, you can do floor division, you can do modulo.
31:01 Modulo?
31:03 How interesting.
31:04 I mean, it makes sense, I guess, but wow.
31:05 And multiplication.
31:06 Modulo by seven days.
31:08 Yeah.
31:09 It's like crazy.
31:12 I had no idea all this math was available for time deltas.
31:15 Can you use the matrix multiplication operator?
31:18 I wouldn't do that.
31:20 It'll shoot you into the future.
31:21 Oh, wait, Anthony's already in the future.
31:23 I don't know.
31:24 It's worth trying.
31:24 Is it like at star or something?
31:27 Yeah, yeah, yeah.
31:28 Power operator.
31:29 Yeah, yeah.
31:30 Anyway, I thought probably if I was as surprised about this and the other listeners were as well,
31:35 and it sounds like you guys also didn't know about this, like we should at least mention,
31:38 apparently this is a thing.
31:40 Total tip of the year.
31:41 Yeah.
31:42 Yeah, well, totally.
31:43 If you want to make a really tricky job interview, please don't do it.
31:47 Yeah, I remember my kids recently asked me, because we were talking about like weeks and
31:51 these numbers came up and they were like, why do you know how many seconds are in a week
31:55 and how many seconds are in a day?
31:57 Because I took math.
31:59 I'm like, because I've memorized those numbers because I've been programming in languages that
32:04 make you memorize how many seconds are in a week.
32:08 It's because there's not a total hours.
32:09 There's only a total seconds.
32:11 I need to know how many hours this is.
32:12 Exactly.
32:13 Exactly.
32:14 So here you go.
32:15 Here you go.
32:16 Pretty cool.
32:17 So Anthony, are you a fan of Multipython?
32:20 Multipython?
32:21 Yes.
32:22 Yeah.
32:22 So apparently Microsoft is as well.
32:24 Yeah.
32:25 It took me a while to figure out the connection, but it was in the release notes.
32:29 So they've released a new extension for VS Code and I'll explain why, but it's called PyLance
32:34 and it's named after Lancelot from Monty Python and the Holy Grail, who was Sir Lancelot?
32:40 It was, isn't it?
32:41 Yeah.
32:41 He was the first one to get across the bridge with the hard questions.
32:45 So yeah, this is an extension for VS Code.
32:50 So if you're already using VS Code, you should download this and check it out.
32:53 It's designed to be used with the existing Python extensions.
32:57 It's not a replacement for the Python extension for VS Code.
33:00 And I think something about the Python extension is that if you're doing type checking, you're
33:06 like type hints and stuff like that, or you're using a linter.
33:10 If you use the Python extension, you can turn on a linter and it will use one of the Python
33:16 linters from the extension by spawning like a process every time you edit the code and running
33:23 the linter again.
33:23 There's also something called the Python language server, which is written in .NET for some reason.
33:30 And that is then communicated with by the VS Code to figure out like the Python code and
33:36 look at the AST and stuff.
33:39 And that gives some errors and code like highlights when you make mistakes in Python.
33:43 So this PyLance is an extension that basically provides type hints and then does a whole bunch
33:51 of like extra little features like doc string automation.
33:55 It helps you on function signatures.
33:57 It does like type heads.
33:59 You can hover over a function call and it'll tell you the method signature and it'll extract
34:05 that from the library that you're using.
34:08 So if you're using VS Code, absolutely recommend that you download this and check it out.
34:13 There's some cool features that I found.
34:15 Like it does like code completion.
34:17 It suggests parameters for you.
34:19 So if you're like using a lot of libraries like Flask or Django or, you know, any kind of
34:24 popular framework that's got type stubs, then this will basically make your life a lot easier
34:30 because it's going to kind of fill in the gaps for you.
34:33 And as you're typing, you can just press tab and just keep doing auto completion.
34:38 It supports auto imports as well.
34:40 So if you started using a function from a namespace in the standard library or from somewhere else,
34:46 it'll be like, oh, you probably want to import that.
34:48 It will add the import statement for you.
34:50 It's also got go to reference and go to implementation, which if you've used the VS Code extensions in other languages like JavaScript or TypeScript,
35:00 or you can right click on a function and go to go to reference or go to implementation and it will jump to where that function is actually implemented.
35:09 I know you get that with Python, but this it uses, I don't know how up to date everyone is on type checkers,
35:16 but basically there's mypy, which is now part of the Python GitHub organization.
35:21 And then all the big tech companies have written their own.
35:24 Don't know why, but they, I guess there was like, we have to write our own.
35:28 It's like a rite of passage.
35:29 So Facebook has Pyre, Google has PyType and Microsoft has PyWrite.
35:35 They all more or less do the same thing, but in different ways.
35:39 And this one uses the PyWrite type checker.
35:42 So, but the confusing thing is that PyWrite was already an extension.
35:46 So if you had that installed, uninstall it first, otherwise it causes issues.
35:50 And then install PyLance.
35:53 And a couple of other things I called out in the show notes is that there's non-default settings,
35:58 which you should change to make the plugin a lot more useful.
36:01 So there's diagnostic mode, change that to workspace.
36:05 So they'll inspect all files, not just the ones that you happen to have open and change type checkers off by default.
36:13 Change it to basic and it will give you more information.
36:16 And yeah, I've been using it and playing around and stuff like that.
36:19 I think there's a few bugs I still need to iron out, but this is a new release.
36:25 It's not open source, so you can't contribute it.
36:27 But I don't know if they'll change it in the future.
36:30 And I think it's because they're planning on using it for some commercial product.
36:34 But we'll see what it uses.
36:35 But yeah, you should download it and check it out if you use VS Code.
36:37 Yeah, it looks like it takes the Python extension and just powers it up a little.
36:41 Yeah.
36:42 So I'm guessing you don't, Anthony, you don't run the Vim plugin for VS Code?
36:49 No, no, I don't.
36:50 I use this.
36:51 This is the Microsoft Word one.
36:52 I use this.
36:52 It's called a mouse.
36:54 Oh, that's really interesting.
36:56 Does it live in a cage or how do you keep it?
36:58 Do you have to feed it?
37:00 No, I don't do that.
37:02 I was talking to Julian Sequeira from PyBytes yesterday and he was telling me how much he loves Vim.
37:06 And I said, so you edit on production then?
37:09 And he was like, how did you know?
37:13 Actually, I'm pretty impressed with the Vim plugin for VS Code.
37:16 It's really well done.
37:17 Well, this looks like a cool project.
37:18 And thanks for pointing out the stuff that's off, like the type checking and the diagnostics
37:23 for being just file based instead of workspace based and whatnot.
37:26 Another thing I think this adds is multi-root workspaces.
37:29 So a lot of these things are already in PyCharm, right?
37:32 But I've opened a big directory and I want two little directories to refer within themselves.
37:38 Treat those at the top level for code within each.
37:42 And I don't think that was possible previously, but now it is.
37:44 It also says it's IntelliCode compatible, which I don't know how many people played with IntelliCode.
37:50 I really haven't very much because I mostly stick with PyCharm, even though I had VS Code open
37:55 while we were talking.
37:55 It uses AI to predict what you're going to type and need.
38:00 So instead of just showing an alphabetical list, it'll say, oh, you're doing request dot,
38:03 you know, you should probably do get, right?
38:05 We all just do get, don't we?
38:06 Cool.
38:07 You know, things like that.
38:08 So apparently it's compatible with that as well.
38:11 Yeah, I'm not a fan of IntelliCode, but I've used it a lot in JavaScript.
38:16 And it kind of like guesses what the variable or the function is, but it gets it wrong.
38:21 Or at least it did the last time I used it, which is a few years ago.
38:24 But if you like, if one library made a typo or like suggest that, it's like, oh, you wanted
38:30 to do get Getty or something.
38:33 And it's like, oh.
38:33 Yeah, yeah, yeah.
38:34 Because it scans the GitHub repos and then it uses that to predict what it's going to
38:38 suggest for you.
38:39 Yeah.
38:39 Yeah.
38:39 So half the suggestions are normally invalid with a really dynamically typed language like
38:44 Python or JavaScript.
38:45 It's it's it needs to really import everything and properly understand the modules and how
38:52 they're constructed to make sensible suggestions.
38:55 Could this be a theoretical suggestion I could actually make?
38:58 Let's find out.
38:59 Yeah.
38:59 And I think that's what PyLance kind of gives you is that it uses the type into the to figure
39:05 out.
39:05 And this is why PyCharm is so powerful.
39:08 Like it, it has its own typing system.
39:11 So it knows it like indexes all your code indexes all your dependencies, and it figures out like
39:17 what the types of the responses are, even if they don't have type annotations.
39:21 And that's how it knows to what's the suggest, like which functions are available, which properties
39:27 are there and stuff like that.
39:28 So I think this is basically a step towards that.
39:31 Yeah.
39:31 And it's good to see.
39:32 And it will be very powerful.
39:33 Yeah.
39:33 Very cool.
39:34 And it has a Monty Python reference.
39:36 Yeah.
39:36 Well, that's our six.
39:38 Has anybody got any extra news?
39:39 I have some, but I'll let Anthony go first.
39:41 Yeah.
39:42 My book is out in early release.
39:44 So CPython internals.
39:46 And I got an email from somebody called Guido asking if he could-
39:51 Oh, I've heard of that guy.
39:51 I think he does Python.
39:52 I don't even supposed to be sharing this, but he was like, oh, had you read this book?
39:57 Can I have a copy?
39:58 Because I want to like review it and, you know, that sort of thing.
40:02 And I was going to reply as a joke and say, it's quite advanced how much Python experience
40:06 you have.
40:07 I thought, I don't know.
40:10 I know he has a sense of humor, but yeah, my kind of English sense of humor doesn't work
40:16 on everybody.
40:17 So no, he's got it.
40:18 He's reviewing it.
40:20 And he did send back a comment saying he's going to recommend it to people who want to
40:24 become core developers, which is awesome.
40:26 Oh, that's cool.
40:27 And that's kind of why you put it together a little bit, right?
40:29 Yeah.
40:30 Yeah.
40:30 That was definitely the reason.
40:31 What's the name of it again?
40:32 CPython internals.
40:33 And I'm updating it for the peg parser because that got merged like in the middle of the initial
40:40 release.
40:41 So I do have some updates for that.
40:45 So yeah, because a whole bunch of the chapters like show you how the parser works and stuff
40:49 like that.
40:50 So I've been redoing those.
40:51 Yeah.
40:52 Super cool.
40:52 And you were on Talk Python 265.
40:55 So pretty recently back in May.
40:56 Yeah.
40:56 Talk about that as well.
40:58 So people can dig into that as well.
41:00 Brian, how about you?
41:01 Just staying out of trouble and working at a nice fort.
41:03 Yeah.
41:04 Yeah.
41:04 Me too.
41:05 Got to go out and do fireworks with the kids.
41:07 That was fun.
41:07 So for me, I already mentioned the Humble Bundle, but talkpython.fm/humble 2020.
41:13 That's all you got to know.
41:14 $1,400 worth of Python stuff for 25 bucks.
41:18 It's probably worth the risk.
41:19 So there's a way better than the reverse.
41:22 $25 worth of stuff for a thousand.
41:24 It'd be terrible.
41:25 So people will try to sell that, but yeah, for sure.
41:27 Speaking of Python 3.9 peg parsers, Python 3.9 beta 4 is out and ready for testing.
41:32 So if that's a thing that you do.
41:34 Anthony, you probably run in that in production already, given how much you're on top of it.
41:39 No, I'm at 3.10 alpha 1.
41:40 Of course.
41:42 Of course.
41:43 Also, we have a cool course coming at Talk Python training called Excel to Python.
41:48 So if you've been doing a bunch of stuff with Excel and want to get into the data science
41:52 tools instead and do Excel-like things, partner it up with Chris Moffitt.
41:57 We're doing really cool stuff there.
41:58 So people can go get notified about when that course is out, maybe in a month or so.
42:02 All right.
42:02 Are you all ready for a joke?
42:04 Yes.
42:05 Anthony, I usually make Brian play the other half of this.
42:09 So you're going to have to do it.
42:11 All right.
42:12 So this is a cartoon.
42:13 The picture is going to be in the show notes.
42:15 You can even view it in your podcast player if you allow it to show images from Scott Hilburn.
42:19 I couldn't find the original place to link to you.
42:22 So I just put an image up here.
42:23 And it's two computers, a laptop and a desktop looking at each other.
42:27 There's a baseball cap on top of the laptop.
42:31 And he's got little like computer arms up.
42:33 And he's like, sweat.
42:34 He's like, I can't get it off.
42:38 Anthony, what's the problem?
42:40 And the other computer says, dude, that's because your caps lock is on.
42:44 Oh, it's locked on.
42:46 Can't get it off.
42:47 Yeah.
42:48 Okay.
42:48 Anyway.
42:49 So I thought that that one made me laugh, especially the picture.
42:52 So check it out.
42:53 You're a podcast player.
42:53 Yeah.
42:54 I can tell why he's trying to get it off too.
42:56 It looks like a red hat.
42:57 It definitely.
42:57 Yeah.
42:58 Yeah.
42:59 That's probably like Windows Vista.
43:00 I got red hat on it and can't get it off.
43:02 Cool.
43:04 Well, thanks a lot, guys.
43:05 All right.
43:06 Yeah.
43:06 Thanks.
43:06 Great to be here.
43:07 Thanks.
43:07 Thanks as always.
43:08 Bye, everyone.
43:09 Thank you for listening to Python Bytes.
43:11 Follow the show on Twitter at Python Bytes.
43:14 That's Python Bytes as in B-Y-T-E-S.
43:16 And get the full show notes at Python Bytes.fm.
43:19 If you have a news item you want featured, just visit Python Bytes.fm and send it our way.
43:24 We're always on the lookout for sharing something cool.
43:26 This is Brian Okken.
43:28 And on behalf of myself and Michael Kennedy, thank you for listening and sharing this podcast
43:32 with your friends and colleagues.