Python Bytes - #460 Overlooked Python Typing
Episode Date: December 1, 2025Topics covered in this episode: Advent of Code starts today Django 6 is coming Advanced, Overlooked Python Typing codespell Extras Joke Watch on YouTube About the show Sponsored by us! Support o...ur work through: Our courses at Talk Python Training The Complete pytest Course Patreon Supporters Connect with the hosts Michael: @mkennedy@fosstodon.org / @mkennedy.codes (bsky) Brian: @brianokken@fosstodon.org / @brianokken.bsky.social Show: @pythonbytes@fosstodon.org / @pythonbytes.fm (bsky) Join us on YouTube at pythonbytes.fm/live to be part of the audience. Usually Monday at 10am PT. Older video versions available there too. Finally, if you want an artisanal, hand-crafted digest of every week of the show notes in email form? Add your name and email to our friends of the show list, we'll never share it. Brian #1: Advent of Code starts today A few changes, like 12 days this year, which honestly, I’m grateful for. Michael #2: Django 6 is coming Expected December 2025 Django 6.0 supports Python 3.12, 3.13, and 3.14 Built-in support for the Content Security Policy (CSP) standard is now available, making it easier to protect web applications against content injection attacks such as cross-site scripting (XSS). The Django Template Language now supports template partials, making it easier to encapsulate and reuse small named fragments within a template file. Django now includes a built-in Tasks framework for running code outside the HTTP request–response cycle. This enables offloading work, such as sending emails or processing data, to background workers. Email handling in Django now uses Python’s modern email API, introduced in Python 3.6. This API, centered around the <code>email.message.EmailMessage</code> class Brian #3: Advanced, Overlooked Python Typing get_args, TypeGuard, TypeIs, and more goodies Michael #4: codespell Learned from this PR for the Talk Python book. Fix common misspellings in text files. It's designed primarily for checking misspelled words in source code (backslash escapes are skipped), but it can be used with other files as well. It does not check for word membership in a complete dictionary, but instead looks for a set of common misspellings. Therefore it should catch errors like "adn", but it will not catch "adnasdfasdf". It shouldn't generate false-positives when you use a niche term it doesn't know about. Extras Michael: Follow up on tach from Gerben Dekker: tach has been unmaintained for a bit but is not anymore. It was the main product from Gauge which is a Y combinator startup that pivoted to something unrelated and abandoned tach. However, https://github.com/DetachHead forked it but now got access to the main repo and has committed to maintaining it. ruff analyze graph is fully independent of tach - we actually started to look into alternatives for tach when it became unmaintained and then found ruff analyze graph. For our use case, with just a bit of manipulation on top of ruff analyze graph we replaced our use of deptry (which was slower - and I try to be careful depending on one-man projects). A Review of Michael Kennedy’s book, “Talk Python in Production” - Thanks Doug Joke: NoaaS
Transcript
Discussion (0)
Hello, and welcome to Python Bites, where we deliver Python news and headlines directly to your earbuds.
This is episode 460, recorded, unbelievably, December 1st.
I'm Michael Kennedy.
And I'm Brian Ackin.
And this episode is brought to you by us, especially Black Friday things that we have on offer.
I don't know, it's been a great Black Friday for me.
A lot of people really interested in the stuff that I put together, hopefully for you as well, Brian.
Yeah, I kind of forgot about Black Friday.
Well, the Black Friday's been going good.
What I forgot about was Cyber Monday.
So I did add today so people can use Cyber Monday code for the course today.
But, yeah, I just added that this morning.
Well, people can look for an email from me if they're signed up to the newsletters.
Is your stuff, what's yours through?
Is it through today?
I think I'm going to have it end just tomorrow morning.
So in case people are like, oh, no, I always get emails.
I was like, I missed it by an hour, or I'm just, you know, just let it go another day and then turn it off.
So if you're not watching this live, you're kind of S.O.L. Sorry.
No, I mean, they can listen. They can listen today. Like, this is timely news. People,
they've got to stay on top of Python bias. I can't let it, can't let it accumulate.
No, it's fine if you listen backwards. There's a lot of stuff that's not that timely.
But one of my topics certainly is. Anyway, yeah, that's going good.
Subscribe to the newsletter. Follow us on the socials.
make sure to subscribe here on YouTube as well if you're interested in catching that we intend the
podcast to be an audio podcast but while we're doing the live stream we do put stuff up on the
screen and sometimes it helps to see it you know even though we do our best to to keep it audio
friendly yeah speaking of putting stuff on the screen what do you got for us bryd well today is
December 1st and that means that it's the first day of advent of code so i want to that and i could
I would to look to see how long this has been going on,
and I guess I don't, I'll have to look harder.
I don't know how long this has been going on.
This is, so what this is,
it's code puzzles that you can do in any language,
the intent is to do them in any language,
but of course our listeners are probably doing them in Python,
maybe rest this year, who knows?
But this is from Eric.
Assembly as a stretch goal, come on.
Yeah.
This is from Eric Wassel.
And I really appreciate it.
This year's a couple changes.
There's no, let's see, there's 12 days.
And actually, I'm kind of grateful because I've never actually gotten through all 25.
And I might, or 24 or how many of them anywhere.
So I'm kind of grateful for a shorter one.
So I can take a couple days to try them out.
I might try this year.
And there's what are the other couple changes.
There's the global leaderboard has gone away for maintenance reasons.
So I do appreciate, it's one of the things.
things is we should say thanks for people doing cool stuff so advent of culture school it is
sponsored there are some sponsors that um that have helped keep this going but uh one of the things
i noticed this year and maybe it's been there and i just haven't noticed is there's um uh a swag page
you can go look at their look some of the some cool stuff and you can grab a mug or a shirt or
you know something's kind of fun one of the things i kind of like about it is it's not there's the
year isn't on there so this can be one that you can just um you can pull out and wear every year
around christmas evergreen swag yeah like it um so fun thing i'd love to hear if if other people
are using uh or or doing the avonic code this year um yeah uh i'd like to hear about how it's going
the um uh what what another kind of associated with this i saw this up on reddit uh there's
somebody wrote a i know there's been other helpers out there but there's
is a Python project that is called ELF, which is a modern advent of code helper that fetches
inputs, submits answers, and tracks your progress. So we're going to link to that as well.
Just saw this. What up? Oh, they've been working on it for a few months. Getting ready for it.
That's cool. So ELF is a command line interface to kind of play with the advent of code stuff.
So we'll link to that as well. Yeah, very cool. The advent of code stuff is interesting, but I've never
really put much time and energy into it personally. I just have so many projects that I have ideas
for and I want to build and I can't even focus on them. So it's like it is cool. I'm personally
thankful for surviving Hocktoberfest without 10 PR suggesting that I put a comma in my readme.
Did you get any? I didn't get any. No, I used to. I used to get a bunch like, hey, we've
improved your readme and it's like, hmm, you're looking to do a PR.
what you're looking to do and you're just wasting my time but actually no i i maybe people put up
rules around it or they just put up admonishment like please don't bother people like that but yeah not
this year yeah cool um let's talk about uh jango huh that's what i want to cover next actually
yeah jango and what's cool is jingo is coming up with um a major new release they're knocking out the versions
pretty quickly. And as I did point out at the opening, this is expected December 2025. So I'm
expecting this any moment now, Brian. But seriously, Django 6 has some really cool features,
actually some genuinely useful ones. The first thing I want to point out about it is how aggressive
they are at saying no to older versions, like no old Python. They only support Python 312
and above. That's pretty, that's pretty hardcore, honestly. Yeah, yeah, but it's an application. So,
you get to decide it's not like you're if you're building on top of jango you have to you know
support backwards compatible stuff yeah but you may have a five-year-old jango app you want to
upgrade that has some weird dependency that goes up to 310 you know what i mean yeah i'm not saying
this is a i'm not saying this is a bad thing i think this is awesome i think yeah i think there's
a lot of benefit that people are missing out like when i did the the year-in-review sort of thing
article at JetBrains earlier this year. One of the areas I worked on and like sort of did a bunch
of math and like predictions or stats on or whatever was this what version of Python are people
running on and a huge bunch of people are still running on 310 or older. And your code is so much
faster and uses less memory and just so much better. Like forget the new features that you get
to use. Just literally it's like 50% faster or something just by changing what version of Python
you're running on. And this sort of encourages the Python people who also Django to ride at the
further out on the edge of that wave, I suppose, which is really good because, yeah, it's,
it definitely helps. So 5-2 is the last one to support 310 and 311. So they dropped two years
worth of Python in one year. Pretty good. So features, content security policy. We all do not
love our cross-site scripting and other badnesses. So it comes now with a built-in support for
the content security policy standard, so that's cool. Avoid CSS, our XSS, and those kinds of things,
just install it and configure it. Basically, it sets some headers, which then tell the web browsers
how they're allowed to behave, cross-site, and that kind of thing. Another one, I feel like this one
probably has Carlton Gibson fingerprints on it here, is they now have template partials.
This is super cool. So I'm really surprised how much HTMLX,
the JavaScript where you front-end framework where you write no JavaScript sort of thing
is how popular it has become in Django.
It's featured in a lot of talks and stuff.
And one of the things that you really, really need to focus on when you're doing that kind
of programming is how do I take portions of my page and then return them from server-side code?
And you can end up with lots of duplication or other weirdnesses.
So this basically addresses that if you want to return a fragment of a page,
then you can say, I know here's the whole page,
the whole template of HTML markup with a Django syntax.
But in this view, when somebody makes this request,
I want to return just this portion of it.
And you can even do things like,
is the request coming in a regular request?
We'll return the whole page.
No, is it an HTMLX partial request,
then just return the partial.
So this is really, really valuable
and basically makes those kinds of frameworks
that exchange partial bits of HTML,
regardless of whether it's HTML nicer.
That's pretty cool.
Yeah.
Another really nice one is a background tasks.
So just a thread that cruises around in the background that you can throw stuff at,
way more useful than you would think.
Sometimes you want to process something that takes a little bit longer,
but you don't want to block up the request response.
Like, hey, I want to sign up for your newsletter.
If you want to send them a welcome to my newsletter or whatever email,
you could on that request block, let it set there and spin,
fire up your email API, connect, send, wait for that actually to send, get a response back,
and then say, welcome, we've sent you an email, right? That's one way. But that makes your code
potentially slow. It'd be nice to go instantly. Hey, thanks for signing up. You're on the news list
or newsletter. And then kick off a task to the background, like, send that person an email.
For one email, it's not that big of a deal. If you've got to send a lot or do a bunch of stuff,
it can time out your web requests, like, you get normally 20 seconds or something like that.
And if it takes longer than that, it's a problem.
Of course, people are going to be freaked out and reload or whatever as well.
But anyway, this is like a real simple way, so you don't have to run other servers and message cues and all that kind of stuff.
You just put it in the background of your app and let it go.
It's not as durable, but it's great.
Almost every app needs some sort of background task.
So this is awesome.
Yeah, it's included now.
It's cool.
That's included.
Absolutely.
Exactly. Speaking of email, email handling and Django now uses the Python's modern API introduced in 3.6 using email.message. Email. Email.message. Super cool. Easier to send that way. And then a bunch of minor features that I'm not going to go into. Anyway, that's a pretty big set of releases or features for a year.
Yeah. Yeah. So now we have to see how many people are going to like update all of their their Django books and tutorials and everything to do Django 6.
It's both an opportunity and a bit of a challenge.
Yeah.
So, Django's not a, that isn't just a year, though.
Is it, is it, doesn't there is lease cycle like a year and a half or two years or something like that?
Let's see.
I feel like, where's the release?
Here we go.
It's yearly.
Yeah, it's yearly.
Okay.
Well, yeah.
Hold on me, but it depends on what you call.
Like, what is the version bump?
There is a release every year, but it's not always a major version bump.
Like, six is coming, but then six one.
and 6-2 are planned, and I think 6-2 might be the LTS, yeah.
So it bumps between LTSs, and the LTSs is on a three-year cycle, long-term support.
So you're not forced to keep it all in to get security fixes and stuff.
Yeah.
And I think that's because of some deprecation stuff and everything.
All right, cool.
Got to love advancements in Janko.
Yep.
Okay.
Well, I'm going to take a look at some typing stuff.
How does that sound?
I love typing.
Let's do it.
So there's an article called Advanced Overlooked Python Typing, and there's some goodies in here that I didn't know about, which is cool.
So I'm, I was slow to come on board with typing, but I like all of the extra.
I'm kind of a fan now.
Plus, it only takes having one package that's kind of popular that people will demand that you.
So anyway, so some of the, some cool, cool extra things, if you possibly may not have known about the first.
I'll jump into is, oh, there's a disclaimer here that it says that the, it's looking at
modern stuff. So Python 312 or 313 or newer so for some of this stuff. So a certain ever,
I didn't know this was a thing. So let's say you've got a match case thing like switches. And you've
got your catch-all at the end and you want to never hit that. Usually I'll throw an assert there
or something, just in case.
But there's an assert never.
That comes from typing.
Didn't know that was there,
that you can make sure that this default case has never hit.
Or if you have other cases that should never be hit,
throw that in there.
That's cool.
Didn't know that existed.
There's get args.
And here's the idea around get args is,
oh, this is a little small.
So I'm going to see if I can make this a little bigger.
The idea around get args is,
so if you the if you've got um like here we've got frozen sets to have literals there's
literals before but you kind of had to have a duplication of all the the actual literals for typing
for different things and that's a in a set of literals and that's sort of a pain so instead of that
there's um you can do get args which creates a uh essentially a set of literals that you
for types for things that are in something so um you kind of have to see the code here to
understand that but it it helps with keeping it in in line so that if when you when you create
an extra element in your set it won't um it automatically gets an extra type uh type card we've
covered before um i think we've covered it it's it gives gets you the exact type
type narrowing logic um i haven't used type card a lot but there's uh there's sort of a a a
your version is type is a stricter and more precise type narrowing than typecard by enabling
bidirectional narrowing okay so um kind of fun with uh type is anyway some uh some some some extra
some extra unpacking and concatenation for callables oh callable with uh dot dot anyway a lot of goodies
for if you want to like really get into some of the nitty gritty and some of the extra extra
fun things with typing this is a fun article yeah very nice i actually have a
an interesting one to add to that is no return oh really okay so you can go to a
function and you can say arrow goes to int goes to stir goes to optional
customer whatever you can even say it returns none which is literally it
returns none but no return is it's not like a void it's it's different it
basically says the only way that this function exits is through an
exception it there's no way out of it so you might have a while
application is still running, and then in some case, if it decides it needs to stop,
it raises an aborted, you know, task aborted exception.
And it's like, while true, if exit, raise task abort, like there's no regular way out.
The only way out is through an exception than this.
So you might think, why would I ever do that?
Well, some of the web frameworks, when you do a redirect, the way they do the redirect is they
raise an HTTP redirect sort of exception type thing, which is more likely to just like make it
get all the way out right away rather than if you forget to say return redirect right something like that
so you'd put a no return there isn't that a weird one yeah yeah so i would have expected uh like um
one of the commenters i thought no return was equivalent to return none so if you don't ever return
yeah that's not what it means i'm like oh this is a really cool way to say it only returns none ever
which is the case if you never if you don't say the keyword return it still returns none but no
this is the this says the only way it gets out is through exceptions oh yeah it was weird right
timing module annotate functions that never return normally i i wanted a void where's my void you
know what i mean like there's nothing coming out of this uh this is not it but this is like
this is something else in that realm of advanced type yeah and they those things do exist so yeah
interesting they sure do so you know what else exists is misspellings so i got my um talk python
on a production book, Christian Klaus was kind enough
to send me a message saying, hey, you know,
so you may have some misspellings.
And he sent me this thing, right, as a PR.
However, it says fixed typos discovered by code spell,
all one word, code spell.
Wait, what is this code spell?
Well, code spell is a tool that checks
for common misspellings in source code.
It works on other files as well,
but it especially works on different types of source files.
because it, you know, ignores backslash escapes and other things that, you know, are common in code.
Okay.
But it's not a spell checker.
It's a misspelling finder, let's say.
So what it does is it goes and it says, I'm going to look for words that are commonly misspelled.
Like in my example, what two things had had high misspelled.
I had fom instead of from, fom.
I had plausible with able instead of ibble on it, right?
So it looks for common misspellings.
it doesn't look for words it doesn't know because those are super annoying you're like here's
723 misspellings like no those are acronyms you know what i mean yeah um like that is a library
i'm importing it's not misspelled if i change it it doesn't work right like that kind of stuff
so what this does is it looks for like common misspellings like adn or um teh or what you know stuff
like that anyway there's not a whole lot more to say about it other than it's pretty cool
It's configurable.
You can, like, put words that are, you know,
learn this spelling equivalence and put other types of config files and whatnot.
Oh, this is cool.
Yeah.
You can even put it into a piproject.comal.
Its settings, if you wish.
Cool.
Yeah, it's got 2.3,000, 2,300 GitHub stars.
So, yeah, pretty popular, actually.
As somebody that uses a code editor exclusively for all of my text writing needs,
this will be good.
Yeah, indeed.
I think, I think Christian,
set it up as a pre-commit hook. Oh, that's a good idea.
Which is kind of interesting because it's apparently pretty fast.
I think this is the one we were talking about. Yeah, it has like, there's something about
pre-commit right there in the last commit. So I'm guessing it does something with that.
All right. How are you feeling on your extras?
I got a few extras. Okay. Yeah, go for it.
Okay. Let's see. I'll start with, start with Hatch. So Hatch 1.16 came out. So some,
some exciting features of hatch so uh and there's the so for hatch back ends and hatch itself
there's a what do we got we got dependency groups and there are workspaces so workspaces
allow you to have like if you have a monorup repo and you have a bunch of uh different projects
within a mono repo this this might help with that um and then there's um what this is interesting
it supports software bill of materials now so that's going to be that's becoming a growing thing so
update to hatch and another update on a different project we talked about last week was it last
week we talked about in one of the things we talked about was zensicle and a listener over on mastodon
fastonon said one of the things we forgot to mention is zensicles is a replacement for make docks
plus what was it a material theme and also one of the things they talked about was
make docs doesn't seem like it's been maintained since the middle of 2024 so there's a link in here
to um is micdoc still still maintained and i i like scroll to it's an interesting read but i kind
of think the answer is uh maybe ish but maybe not um so if you always have to um you always have to
split that difference of like it could just be done you know certain things are just they really
don't need more and they're supposed to be simple but i feel like mk docs is something that could
continually take on new variations and features and updates yeah um so uh not even to say
nowhere nor longer being maintained is this about anyway uh interesting read if you're curious
and want to depend on that but i think i'll be i'll be checking out zensicle as well right and
as uh you pointed out last week um you said anyway for sure
that it's a rewrite. Zensical is not just building on MK docs. It's just the people that
were working on material for MK docs are now building a completely from scratch documentation
thing, right? Yeah, it's backwards compatible if you used MK docs before, but it is something
completely different. All right. All right. How about, do you have any extras? Or something completely
different. I do. Let's go back to, what was it last week or week before? I talked about TAC, T-C-H, and how it
creates one of those basically architectural layered graphs that let you show which parts of
your app depend upon which other parts of your app, that kind of thing. And it was pointed out
that, hey, hey, that thing looks kind of unmaintained. Well, Gerber Decker sent me a message and
says, tack has been unmaintained for a bit, but is not anymore. It was the main project
of Gage, which is a Y Combinator startup that pivoted to something unrelated and based on AI.
Surprise, surprise. And they abandoned TAC.
However, detached head from GitHub forked it and now has access to the main repo and has committed to maintaining it.
So it's back.
Also, rough analyzed graph.
It is fully independent of tack, and they actually looked into using that as an alternative once it became unmaintained.
But yeah.
Anyway, that's...
Tack is back.
Tack is back.
Tack is back.
Also, quick shout out to Doug Farrell.
And thanks.
He wrote a review my book.
And, yeah, very nice.
So I linked over to that.
if people are interested. Thank you, Doug, for writing that.
TLDR says recommended. So appreciate that.
All right. Are we ready to joke about something?
Yeah.
Okay. So you've heard of platform as a service, P-A-A-S.
You've heard about infrastructure as a service.
I-As or I-A-A-A-S. D-B-A-A-S. D-B-A-A-S.
Sometimes, though, your predictivity just demands that you stay focused
and you just say no, right, Brian?
Yeah.
So I present to you no as a service.
So this is an API that will simply return a random but realistic excuse for saying no, so you
can turn it down and stop.
Oh, nice.
Yeah.
Built by humans, excuses and humor.
This project is sponsored by Git-A-A-S.
I don't know what that is.
But anyway, so if you pull it up, it's N-A-A-A-S, I think it's N-O-A-A-A-S, but you
or whatever.
It's not the domain they got.
And you just get a little bit of JSON.
Reason, I'm fighting an invisible dragon at home.
It's taking longer than expected.
Or not my circus, not my monkey,
so definitely not my act to perform.
Cinderella left one shoe here.
And I need to help her find it instead of going out.
I would come, but I'm trying this new thing
where I just don't.
So if you need to integrate no for whatever reason
into your application, well, here's the API right here.
You get a JSON response.
It is built as an API.
This is great.
You can just, you know, query it.
Yeah, we're going to get probably an MCP built over as well,
so you get integrated into your AI workflow as well.
I mean, it's going to be powerful.
Why use a constant when you can call an API?
Exactly.
Anyway, I thought no as a service is a pretty good joke.
I love this last one.
I would come, but I'm trying this new thing where I just don't.
Exactly.
My favorite is I can't make it because I don't want to.
Exactly. No.
Don't want to.
Cool.
All right.
Well, a fun episode as always.
Thank you everyone for listening.
Thanks, Brian.
Thank you.
Thanks all.
Bye.
