Transcript #352: Helicopter Time Comes to Python
Return to episode page view on github00:00 Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to earbuds.
00:05 This is episode 352, recorded September 12th, 2023. I'm Michael Kennedy.
00:11 And I'm Brian Okken.
00:12 And this episode is sponsored by us, supported by us. Support the podcast by choosing our courses,
00:20 listening to our podcasts, including the new one by Brian, Python People,
00:25 and the Patreon supporters, and find us on Fostadon.org. Brian, me, and the show.
00:31 The link's in the show notes. And also, the show notes have how to attend the live session, if you want.
00:37 Yes.
00:37 Brian, what do you got to start our day here?
00:39 I feel like it's the start of school, so I feel like a helicopter parent.
00:44 That's right. You got your homework done? Was anyone mean to you? Can I help you out, sweetie?
00:51 So, the first topic is called Heliclockter. And it is, like, apparently, it's a pun on helicopter parenting, maybe? I don't know.
01:01 So, like, helicopter, but clock, get it? Kind of a helicopter.
01:07 So, this was submitted by Peter Nielsen. I think he was involved in this, but the idea is, it's like date times, but they're a little bit better.
01:18 So, apparently, one of the frustrations that this group had was with normal date times, and they looked into other things,
01:25 is being able to just have a date time where you can just enter, like, the time, but have it be, like, aware of what time zone it's in.
01:35 So, the big thing about this is a subclass of date time with some extra features.
01:41 So, you've got a date time TZ, which is a time zone aware date time.
01:48 And then you've got a local one, which ensures that the time zone is local time, and then a UTC.
01:53 So, there are some other solutions out there that deal with just assume UTC plus zero, but that's often not convenient.
02:02 And I guess one of the things they had was they wanted to be able to have date time items as objects,
02:08 and then be able to sort them, but have them keep, like, maintain what time zone they were created in and stuff,
02:14 which is kind of an interesting thing.
02:16 So, they've got, it looks just like working with time zones.
02:21 So, it looks pretty easy to work with if you've ever worked with time zones.
02:25 They do have some other cool features, like statically type checkable and Pydantic integration, which is kind of neat.
02:32 Anyway, they've got also an article about why they created it.
02:38 Time flies when you're having zones.
02:41 Nice.
02:41 So, it's a pretty interesting discussion going through why they chose the solution they did of creating their own and everything.
02:51 And being able to use it with mypy also is kind of cool.
02:54 So, yeah.
02:55 Yeah.
02:56 Neat time zone.
02:57 Shout out to Arrow and Pendulum as well, or some of the other well-known ones.
03:00 Yeah.
03:00 Yeah.
03:00 Even a Datetime UTC they found, but it's UTC zero.
03:06 And then they even talked about why that, like, how they designed it and why.
03:09 So, their first thing was just create a completely new type, but then they, you know, came up with some problems with that.
03:16 So, they came up with subclassing.
03:18 So, then these new types are types of Datetime also.
03:23 So, you can use other things to go with them.
03:25 So, I think that's a cool solution.
03:26 I'm not usually a fan of subclassing, but I think the subclassing in this case makes a lot of sense.
03:32 Anyway, what you got for us?
03:35 Yeah.
03:35 That looks good.
03:36 You know, I think it sounds so easy to be working with time, but it's always so tricky.
03:41 Yeah.
03:42 I have something keeping with the same color scheme here, a new release for Wagtail.
03:47 And I don't believe we've talked about Wagtail before.
03:50 It's possible.
03:51 I, I did get a chance to use our search today, you know, and just reminded how nicely that goes.
03:59 I guess we've talked to at least mention it somewhere.
04:01 But Wagtail is, a CNS, the CMS, the leading open source Python CMS built on Django, but you don't necessarily have to know Django.
04:11 It's kind of like WordPress in the sense that you could just go through the setup steps and run WordPress and not even worry about the fact it's written in PHP.
04:20 So Wagtail is a little bit like that, but just pip install Wagtail to go get going.
04:26 And it's got some really cool features.
04:27 I haven't really explored it too much, but it's got this really cool visual designer for people to build out web pages and stuff.
04:33 Isn't that cool?
04:34 So you can like hit a little plus and you get like a nice WYSIWYG.
04:38 I'm going to insert a heading or insert a table or, like a image gallery with these images.
04:44 It has a cool tree structure so you can organize your content.
04:47 And because it's a Django, you can extend it doing Django things, which is pretty sweet.
04:53 And it has a bunch of, you can make little snippets that you can use inside your pages.
04:57 So that's pretty neat.
04:58 And it even has a library for managing your images.
05:01 So pretty cool stuff.
05:02 And the news item today is an article by Megan Voss.
05:07 Come over to the dark side with Wagtail five.
05:10 So Wagtail 5.0 is a new release here with a bunch of cool things.
05:16 So dark mode, if you want your website, which is backed by Wagtail to have dark mode, well, dark mode is a thing.
05:22 It's pretty excellent.
05:23 I'm a big fan of dark mode.
05:25 It has SVG image support in addition for scalable vector graphics.
05:30 In addition to just JPEGs and stuff.
05:32 It has an accessibility and enhanced accessibility checker.
05:35 That's pretty cool.
05:36 Like if you're creating content and it's hard for people who have to use screen readers or something, it can tell you that you're not doing that.
05:42 Like missing paragraphs as headings, misusing paragraphs as headings, use proper tags, incorrect heading hierarchy, avoid skipping levels.
05:50 Oh, wow.
05:50 And, you know, things like that.
05:52 Right.
05:52 Which is certainly my handwritten stuff.
05:55 That's only, you know, if I remember that that's how it's supposed to go.
05:57 Right.
05:58 So pretty sweet.
05:59 What's wrong with five H1s on one page?
06:01 I know.
06:02 I know.
06:03 I really, I really have a lot to say here.
06:05 So it's all H1s.
06:06 It also has, what is the, when you, if you want to delete, like say you have an image or something and it's in your gallery and you're like, ah, I'm not going to use this after I'll hit delete.
06:16 It keeps track of if it's used in any other pages so you don't accidentally delete something that's being used in some part of the site you didn't know about that someone else created.
06:25 That's pretty awesome.
06:26 More snippets, more validation, and they threw away a bunch of old code so they can work better, which, you know, may even have a blog post on addressing technical debt.
06:37 But so a few breaking changes, not too many, but, you know, check it out.
06:40 Anyway, Wagtail looks pretty awesome, right?
06:42 I think I may have talked about it a long time ago, but anyway, not the 5.0 release because that's quite recent.
06:47 Yeah.
06:47 I think it's pretty cool that that's there.
06:50 And I do have plans to play with it at some point, but I've had plans to play with it for a while.
06:55 So anyway.
06:56 Indeed.
06:57 Kim out in the audience says, I know several one-person technical businesses that really like Wagtail for their sites.
07:02 Easy to use for technical competent users, but doesn't require much of their time to maintain.
07:07 Yeah, that seems great.
07:08 Yeah.
07:08 Nice.
07:09 Over to you.
07:10 Well, I guess I go away from Python a little bit, but we use it all the time.
07:17 So I want to talk about Git.
07:19 So I don't think I use any other revision control systems anymore other than Git.
07:26 No CVS?
07:27 No.
07:28 No CVS?
07:29 Any of that good stuff?
07:30 Of course.
07:31 Subversion.
07:32 Actually, I touch on subversion once in a while.
07:35 I still have kind of good feelings towards subversion.
07:38 The other ones make me a little queasy.
07:40 Anyway.
07:41 The thing that I often want to know is just like the stuff that happened recently on a file or something or just on a Git repository.
07:50 RCS.
07:51 Mike Felder.
07:52 Oh, field.
07:52 Fiedler.
07:53 Sorry.
07:53 Nice.
07:55 RCS.
07:55 Wow.
07:57 Takes me back.
07:58 But so one of the things is to Git log.
08:01 So looking at what's happened recently.
08:04 But the Git log output is not something I like to do.
08:08 Actually, using Git log is one of the reasons why I often pop up like a visual tool to look at my Git repository because it's gross.
08:18 But I forgot and I knew that you could customize it, but I kind of forgot how to.
08:24 So I haven't been.
08:25 But this now I have because of this article.
08:28 So there's an article called Git log customization from Justin Joyce.
08:32 And so the default is something like that, which we're showing.
08:35 It's got a really long hash number and a bunch of information, but it's hard to find the information you need.
08:42 One of the things that Justin points out is that you can do just something really easy by passing in one line.
08:51 Just the flag, like two dashes in one line, all one word, will make it pretty nice, actually.
08:59 It just does a short hash and you can kind of see what's going on a little bit better.
09:04 But it goes a lot further.
09:06 And I'm going to hop down to this really cool customization.
09:09 One of the things is using graph.
09:12 Graph is great.
09:13 --graph so that you can see kind of it does like kind of a visual representation of the different.
09:19 What are those?
09:21 The branches and the merges.
09:23 That's it.
09:25 I always forget branches and branch or fork.
09:27 No, it's an ASCII art for the win there.
09:29 Yeah, ASCII art.
09:30 But then you can do like color and stuff.
09:32 So there's the graph does color also if you have that on everything.
09:39 It talks about how he also talks about how the one line is actually a like a combination of pretty one line and abbreviate commit, which is kind of cool.
09:51 And then what I really love is this the thing that he like comes up with at the end so that I didn't know that you could put aliases in the get config file.
10:01 So or at least I did once and I forgot about it.
10:04 But this is a pretty cool long alias.
10:06 He's got LG instead of log.
10:09 So save a character of typing right there.
10:11 But it defaults to.
10:13 So it's an alias for log with a graph with 10.
10:17 So default to the last 10 commits.
10:19 And then this long format thing that is kind of ugly to look at.
10:24 But what you get is he talks about what it all is, but what you get is the brand, the graph.
10:31 But you also get somebody's name highlighted of who did it.
10:36 And then also how long ago.
10:38 So was it 19 hours ago or 24 hours ago or two days, three days?
10:42 Really cool.
10:44 Exactly what I need usually when I'm looking at a get log.
10:47 So I love it.
10:48 This actually inspires me to maybe play with this as well.
10:51 I usually use source tree.
10:53 I really like source tree.
10:54 But, you know, sometimes you're already in the terminal and just, you know.
10:58 Yeah.
10:58 And so all I did, what I did is I just like opened up my home directory, get config and added this alias.
11:04 And now I just use get LG.
11:06 That's and then I can forget all of this.
11:09 The other one of the neat things I'm like, well, if it says by default, you can put the default, whatever you want for this alias.
11:15 But like 10 lines.
11:17 What if I want to see like 20 lines or 30 lines?
11:19 Well, if you say get LG, even though it has the dash 10 built into it and pass in like a dash 20 or dash 30, the second one overrides it.
11:28 So that's clever.
11:30 Works just fine.
11:31 So nice.
11:32 So thank you, Justin Joyce, for writing this up.
11:36 Nice job, Justin.
11:38 That's pretty awesome.
11:38 All right.
11:39 I saw that David Lord was the one listed there in the example.
11:44 Yeah.
11:45 Let's keep, let's keep going that theme over to historically from the flask side of things.
11:51 So I want to talk about flask.
11:53 I want to talk about Jinja.
11:55 So Jinja is the template language that is the default for so many frameworks.
12:01 It's not best.
12:02 I don't think come on chameleon.
12:04 So much better.
12:06 But it doesn't matter if everyone's using Jinja.
12:09 Like that's what people are using.
12:10 Right.
12:11 It's built into all the frameworks.
12:12 You got to jump through hoops to like use chameleon with say FastAPI.
12:16 Right.
12:17 Like I created a library to do that kind of stuff.
12:19 But this is about Jinja and its origins come from flask originally created by Armin Roeneker.
12:25 No longer the maintainer, David Lord and folks over at pallets is.
12:29 But this new project I want to give a shout out to does come from Armin and it's called mini
12:34 Jinja.
12:35 Like Jinja, but smaller.
12:38 So mini Jinja is a powerful, but minimal dependency template engine for rust.
12:44 That's compatible with Jinja and Jinja2.
12:46 So if you've got a rust project and you want to have those templates, you could use this
12:50 and you'd be like, okay, Michael.
12:52 Well, a Python podcast.
12:53 So yeah, rust is popular, but it's comparable.
12:56 If you've got a Python app, it is basically not a hundred percent identical, but pretty similar.
13:02 Right.
13:03 The other thing though, that's kind of interesting is it does works with Python through as project
13:09 called mini Jinja dash pie.
13:12 And that allows you to use the rust runtime backed template engine on whatever thing it
13:19 is that you're working with.
13:20 Right.
13:21 Flask FastAPI, whatever.
13:23 Right.
13:23 So you might want to use this instead when the full set of Jinja2 features is not required
13:29 and you want to have the same experience across Python or rust.
13:32 There's places where you can get a slightly better performance sometimes than Jinja.
13:37 It was created using maturing in py03, which is pretty cool.
13:43 Like the, the rust Python bindings.
13:45 And yeah, it just shows you how to set up and whatnot.
13:48 So if you're out there doing the web things, you know, maybe have a quick look at mini Jinja.
13:54 If somehow that's relevant to you.
13:55 Continuing the rustification of Python.
13:58 Indeed.
13:59 You know, it's been around for a long time, over 30 years.
14:02 So surely some rust is starting to develop.
14:04 I wouldn't have expected to come on so quickly all at once like that.
14:07 But there you go.
14:08 Yeah.
14:09 Nice.
14:09 That's it for all of our items, I would say.
14:12 Okay.
14:13 And I've got some extras, but I know you do too.
14:16 So maybe you go first.
14:17 Okay.
14:18 Well, I was up.
14:20 We were just talking at the beginning of this before we went on air that I was having some audio trouble last night.
14:27 But I was getting the pytest Primary Power course ready and launched last night.
14:32 So chapter six, got done recording that yesterday morning and in the evening, finished editing the audio.
14:38 So the first course in a series, pytest Primary Power.
14:43 And so what does it cover?
14:44 It covers test functions, fixtures, built-in fixtures, parameterization, markers.
14:49 And it's really the set of things I think that you have to know to be able to be using pytest effectively.
14:55 You could just take this first course and I think run with it for quite a long time.
14:59 So to celebrate getting it done and back to school.
15:02 I know everybody's with kids.
15:04 Kids are probably started last week or the week before.
15:07 It might sound like it's for school, but now the kids are out of the house.
15:11 You actually have time and energy to study things again.
15:14 That's my house anyway.
15:15 Yeah.
15:16 Yeah.
15:16 So I'm offering a deal for it.
15:19 So 49 bucks for the first course.
15:21 And if you want to do the bundle, $99.
15:24 And the bundle is kind of fun because I've already had some, we've got a lot of channels to get feedback.
15:29 I had some feedback this last night and this morning saying, hey, I'm trying this on Python 3.8 and it's, it doesn't work.
15:37 So, but it does now.
15:38 So this morning I did the, it was like the from future import annotations I had to do to make the annotations from 3.10 be compatible to Python, way back to Python 3.7.
15:50 So I tested it on 3.7 this morning.
15:52 So everything should be working.
15:54 So anyway, pretty excited about that.
15:56 Excellent.
15:57 Yeah.
15:57 Congratulations.
15:58 That's a big step.
15:59 If you see something like this, you're in the right place.
16:01 So thanks.
16:02 How about you?
16:04 The testing code logo and roll in the course for 49 bucks.
16:07 Awesome.
16:08 Keeping with the course theme a little bit.
16:10 I have three new courses coming out at Talk Python Training.
16:14 We have a new HTMX plus Django course, which is going to be excellent.
16:19 A new language based course without more detail on that.
16:23 And one or two data science courses coming in quite soon.
16:27 And since it's a bunch of, a bunch of things, all of them not quite released yet.
16:33 Just point people at Talk Python training.talkpython.fm/getnotified.
16:38 And there, if you're not already in the mailing list, put your name and email in here and you'll
16:43 get to hear about them when, or keep listening to the podcast.
16:46 I'm sure I'll talk about it then as well.
16:47 I also just want to give a shout out to Cloudflare Turnstile.
16:50 I've been going through and classifying trucks, cars, crosswalks, stoplights.
16:58 Holy moly.
16:59 What a dreadful, unnecessary thing.
17:02 So way back in 304 on October, 2022, I talked about Turnstile, which is a privacy friendly,
17:12 user friendly, privacy preserving alternative to reCAPTCHA and all those things.
17:18 And it just sits down here.
17:20 And while we're waiting, you know how, like sometimes if you are slow filling out a form,
17:23 it'll say your selection of taxis has expired and you got to do it again.
17:29 This one automatically, I saw it while I was waiting for you to talk about your new course
17:35 and bundle.
17:35 That thing just did a little flicker and regenerated its validation with no user input,
17:40 just in the background.
17:41 Telling you.
17:42 Come on.
17:42 So how does it know you're not a robot?
17:44 Do you know?
17:45 It runs some JavaScript and it also, I think, you know, I don't remember all the details.
17:51 It runs through a bunch of other heuristics that like they know from, I think from your
17:55 IP address talking to, because, you know, Cloudflare like fronts something like 25% of the internet.
18:01 So they can tell if you're going to a bunch of different sites and things.
18:04 And it kind of uses that background information.
18:06 I think.
18:07 I think.
18:08 But anyway, I have not even had to find a taxi to be able to submit that.
18:12 But it's made it so that you don't have a bunch of automated stuff coming in.
18:17 Exactly.
18:17 People used to be hammering on it, doing all sorts of bad stuff.
18:20 Yeah.
18:21 That's not good.
18:22 Yep.
18:23 So, yeah, I had to add it for like the login page and for the registration page.
18:30 A bunch of bots were signing up.
18:31 I'm like, I don't understand why they're signing up because it's a free account and you don't
18:35 really get anything for free.
18:36 So I couldn't understand why they were all, but hundreds of them were signing up.
18:39 I'm like, okay, I'm going to do something.
18:41 And then this is an improvement over reCAPTCHA.
18:43 All right.
18:44 PyBay.
18:45 PyBay is coming up October 8th.
18:48 I will be there speaking about Python type hints and how you can superpower your apps.
18:55 Something like five amazing ways and tools you can use with your apps, I believe is what
19:00 my topic is roughly supposed to be.
19:02 But I will be there and people can, they happen to be in the San Francisco area or wanting to
19:08 be there.
19:08 They can check it out.
19:09 They gave me a coupon.
19:11 It's a friend of speaker.
19:13 If you use that friend of speaker, no spaces, you get 20% off regular tickets.
19:16 So that's always fun.
19:18 Nice.
19:18 Yeah.
19:19 Always a fun trip, a road trip down to San Francisco.
19:22 And let's see, following up on your doc strings, we got some really nice follow up here, Brian.
19:27 Rhett Turnbull says, with regard to the doc strings article Brian covered last episode, the Google
19:34 format allows for a raises section.
19:37 Remember I said, oh, it'd be awesome if you could say actually what errors could happen.
19:41 Yeah.
19:41 That's really cool.
19:42 And Rhett uses Google doc string format for projects, type hints, descriptive variable names,
19:47 MK docs and MK docs strings.
19:49 Get pretty docs are free and VS Code will pull doc strings.
19:52 So you can see them in the editor and copilot practically writes the doc streams for you, which
19:57 is excellent.
19:57 And one second attribution.
20:01 John Hagan sent over something saying pretty similar.
20:04 Say, remember we said, look, you don't necessarily need to include the type in the doc string.
20:08 If there's a type hint and sure enough, you don't have to.
20:11 Oh, cool.
20:11 You can just give it a description, which is cool.
20:13 And also points out the syntax for how you use the raises.
20:17 So you say raises and you give it a list of exception types.
20:20 And then the description of when the, the scenarios, when that might happen.
20:24 So for example, raises invalid factorial error.
20:27 If, and is less than zero is the time that that happens.
20:30 Oh, cool.
20:31 Isn't that cool?
20:32 Yeah.
20:32 Yeah.
20:32 And finally, John also points out that high charm has the integration for Google,
20:39 doc strings somewhere in here.
20:42 Yeah.
20:42 for Google doc format and how to set that up.
20:45 So it'll, it'll automatically auto complete and render Google doc strings.
20:50 When you say, give me the quick help control Q and it'll like, just pop that up as a
20:55 rendered sort of thing there.
20:56 So a lot of followup on the doc strings.
20:58 Awesome.
20:59 Cool.
20:59 Yeah.
21:00 And that's all I got for my extras.
21:02 How about a joke?
21:03 What do you think?
21:04 Yeah.
21:04 You ready?
21:04 I've got your joke.
21:06 And then I want to do a dad joke also after that.
21:08 Awesome.
21:09 So this one is a lesson in optimization.
21:11 Careful what you measure, careful what you ask for.
21:14 Right?
21:14 So there's this picture of two tennis ball containers.
21:18 You know, those tubes that are vacuum sealed.
21:20 Yeah.
21:20 One of them is not at all optimized.
21:22 It stores only three tennis balls, but the one to the right says, look, if you cut the
21:29 tennis balls in half, you can, you can store six tennis balls in this container way more
21:34 efficient use.
21:35 Yeah.
21:36 Yeah.
21:37 I mean, your tennis game might suck, but that's awesome.
21:40 Yeah.
21:41 Yeah.
21:41 So there you have it.
21:42 Yeah.
21:43 Okay.
21:43 So over to you to close it out.
21:45 I've got a joke that I just, I was reminded of the other day with, shared with
21:51 my kid.
21:51 It's told dad joke.
21:52 So, have you seen birds fly in a B formation before?
21:56 Sure.
21:56 have you ever noticed that sometimes that one side is a lot longer than the other or
22:01 it's longer than the other?
22:01 Yeah.
22:02 Do you know why that is?
22:03 There's more birds.
22:04 Optimize.
22:04 Amazing.
22:08 Anyway, it's terrible.
22:11 I love it.
22:12 I love it.
22:13 So perfect dad joke.
22:14 All right.
22:14 Well, perfect episode as well.
22:17 Thanks for being here.
22:17 Thank you.
22:18 Thanks everyone for listening.
22:19 Yeah.