Python Bytes - #357 Python 3.7 EOLed, We Hadn't Noticed
Episode Date: October 17, 2023Topics covered in this episode: QuickMacHotKey Things I’ve learned about building CLI tools in Python Warp Terminal (referral code) Python 3.7 EOLed, but I hadn’t noticed Extras Joke See the... full show notes for this episode on the website at pythonbytes.fm/357
Transcript
Discussion (0)
Hello and welcome to Python Bytes, where we deliver Python news and headlines directly
to your earbuds.
This is episode 357, recorded October 17th, and I am Brian Ocken.
And I am Michael Kennedy.
And our show is sponsored by us.
Check out TalkPythonTraining, of course, with those wonderful courses from Michael
and other people, including myself, and Patreon supporters supporters of course we love patreon supporters
we haven't really talked to him much lately to sending out emails i should do that more
and lastly the complete pi test course please check it out if you want to learn pi test the
fastest way possible uh and you can connect with us on mastodonon, on Mastodon, on Fostodon, both of those. And Michael's
at M. Kennedy. I'm at Brian Ocken, and the show is at Python Bytes. And you can also
listen live if you head over to pythonbytes.fm slash live, and you can watch it when we live
stream as we are right now.
Absolutely.
So Michael, let's kick it off with something hot.
Let's kick it off. I want to
talk about a couple of, well, something I've learned from Glyph when I was at PyBay. Is that
last weekend? Two weekends ago? Last weekend, I guess. Glyph gave a really cool talk. Some of the
talks are starting to show up on YouTube, but it's his talk is not there yet, or I would link to it.
And it was something along the lines of like, how to program your computer with Python,
which sounds silly because we're all pretty good Python programmers.
Like you should think, okay, well I could do that.
But this was about how do I automate stuff?
How do I plug into things?
Like how can I automate Keynote to extract show notes out,
to put into another document or PowerPoint or things along those lines.
And one of the things that he both created and talked about
was this thing called Quick Mac Hotkey
because you might want to have your Python
not have a UI you're interacting with,
but just be chilling in the background.
And if you had a certain hotkey, it does the thing, right?
Yeah.
Yeah.
So this Quick Mac Hotkey does that. And basically
it's super simple to use. It's just a set of minimal Python bindings
for macOS framework APIs using
what does it use for it to pull this off?
Oh yeah, PyOBJC I believe is what it's using.
So it's super easy to write
some code, you want to have a function that's called when a keystroke is down, you just give
it the decorator, quick, hot, quick, hot key, and you say the virtual key is the x, the modifier is
command control option. So just hit all three of those plus x, you know, something that's most
likely not going to interfere
with some other behavior, and then boom, off it goes.
And look how simple that code is.
Isn't that nice?
Yeah.
Yeah, that's pretty cool.
Although I don't know if I can find my command control
and hotkey at the same time, but cool.
Yeah, I use a Windows keyboard, unfortunately,
because there's no ergonomic Mac keyboards.
Apparently Apple hates people, and they want them to have RSI
for the rest of their life.
Does the window key
map to the command key? Yeah, the window key is just
the command key. So it's nothing
too fancy. So there's not a lot of
depth that we've got to dive into this, other
than how cool is it if you want to just add hot
keys here.
Off you go. Okay, so when you
install it, does it just run all the time or something?
I think whenever your app is running.
Okay.
Like,
so you can see the last line of this example,
it says app helper dot run event loop.
Okay.
So that's just like set there in the background and just wait for events.
For example,
it's this quick hotkey callback when somebody presses that.
So one of those though could be exit,
you know,
and just,
you know, I don't know how
you exit the event loop, either raise an exception or just exit or who knows.
There's got to be a way to get out of there.
Reboot your computer.
Exactly.
It's like Vim.
You're just in there.
Nice.
All right.
Over to you.
Well, I'm going to talk about command lines applications a little bit because Simon
Wilson had things I've learned about building CLI tools in Python.
And I really kind of like all the stuff he covered. I really liked them.
I mean, this isn't a super in-depth, like how to write CLI tools,
but some of the things like just high level when you're writing command line
applications it's good to be rather consistent
with other command line applications
to make it easy to use
because it's going to be used by people that like CLIs, right?
So a couple of option things here.
Be consistent with the terms.
Well, you have to kind of understand the terms,
but there's commands, there's arguments,
there's options and flags,
and sometimes flags are options. And yeah, anyway, uh, so commands have our, he's using click applications. So the, um, he actually talks about click and also using
a cookie cutter template that he, he lists, um, at hook app on Simon W on GitHub. But the, or yeah, cookie cutter template to build these,
which is cool.
I like Typer, which is built on top of Click.
So anyway, but these are still good advice.
Like make sure that your options,
you know what options are,
and then make sure you have like a short character.
So if you have dash dash port, also include dash P as a short version
because people are used to that.
There's mostly just a lot of description around making sure your flags
and options and stuff are consistent.
And I actually think people ought to get used to writing more CLI apps because
especially for utilities for yourself and for a team, they're great because you'll use it all
the time and you get used to it. It's easier than building a GUI application. So consistency is
everything. Try to be consistent with it. One of the great thing the great advice here so is
pay attention to your help message so um a lot of cli tools like typer and click kind of build a
help for you so that it prints out like the options and stuff that you can you can list
which is great but you have to go in and add things like um uh put examples so example uses of like the
entire application or the entire option and how to use it um this is extremely helpful and i
really appreciate it even just for myself so that um like six months from now i can remember how to
use it things like that so include options in the help. And then the other thing is the lastly,
oh, examples, examples in help. And there's a couple other things. Oh, include the output of
your help in your online documentation. And there's ways to automate that. But I think that's
great to just list it because I'm looking for it when I'm looking at the, like at the bottom of the read me or something. The lastly is if you have a CLI that's being used by other people,
make sure that you version it appropriately because,
because it is an API.
A command line interface is,
can be used by other programs.
So treat it as an API,
even if the other user is somebody's fingers,
because if things change, people should know about it.
So anyway, good application or a good article about building command line applications.
And then his cool cookie cutter template for Qlik apps.
It's nice.
Excellent.
Yeah, nice work, Simon.
A couple of pieces of real-time follow-up here.
One, audience is on point today.
So Kim out there says,
Rich Click is also fantastic if you use Click.
And I definitely agree on that.
So it's like Click,
but all the help messages and stuff are in color using Rich and little info boxes and stuff.
And then Rhett, who was on TalkPython
to talk about programming Mac apps,
macOS apps,
highlights that this quick hotkey thing
sounds like a good opportunity
for a Rumps menu bar app.
So Rumps is awesome.
I was actually thinking of adding this hotkey thing
exactly for one of my Rumps menu bar apps,
which is just an unfair level of easy
for building a Mac app that just runs in your menu bar. Oh, cool. Yeah. We've talked about that,
but it's been a while. It has been a while, but you've got to, for me, I've got to go and find it
and like make it do the thing. I'm like, you know what? Hotkey. Oh yeah. Here we go. Now it's on.
Now it's going to the next level. So yeah super cool all right that's not what i
want to talk about but some good real-time follow-up what i want to talk about is warp
and this is also an item from pi bay indirectly i ran into elvis who works there and have you
heard of warp brian no well i mean warp speed yes i know okay gotta resist the star wars references
um it's it's super cool So what terminal do you use?
Like when you go to use the built-in Mac one,
do you use iTerm2 or what's your story?
Well, I've used the built-in Mac one on Mac
and then on Windows, I use the what?
The Windows terminal.
Well, that was a good one.
No, the Git Bash, Git for Windows Bash comes with Bash.
So I use that.
Okay.
Yeah.
You should check out the Windows Terminal and then plug the Git for Bash into it.
You get like, it behaves better and you can pick from like nine different shells and like
things that run inside the Windows Terminal.
Anyway, Windows Terminal is awesome.
But we don't have Windows Terminal on Mac, which is just fine because we have iTerm and
other things. But I want to tell you about Warp, because Warp is a new terminal
that has got quite a bit of energy behind it. And it's awesome. So I think there's 30
people working on this project, if I remember correctly. But there's a good number of people
that are working on building this new terminal based on rust and it even is programmed in metal
shaders metals are like the opengl directx mac equivalent for making it super super fast but
basically like there's a bunch of shortcomings that always drove me crazy about the terminal and
there's a lot of things that are pretty nice here so it's a free thing for individuals if you're a
company you got to pay for it if you want any company features uh but it's it's a free thing for individuals. If you're a company, you got to pay for it if you want to company features. But it's worth checking out. So for example, if you write something, Brian,
like I write some multi-line command and you're like, oh no, I forgot the quote at the beginning.
You know, how do you fix it in iTerm? Left arrow, left arrow, left arrow, left arrow, left arrow.
Like even home doesn't work. You know, left arrow, left arrow, left arrow. You wait and you get back there and you type the quote, right arrow, right arrow to get the focus back.
Like clicking where you want to be doesn't work, right?
For example.
Well, you use Vim key bindings and just go there with Vim.
Do you have Vim key bindings in the standard terminal?
Yes.
Everywhere.
Yeah?
Okay.
All right. Everywhere. Yeah? Okay. Alright. Awesome.
Well, so this one, like basically all
the stuff you type at the bottom or
wherever you're typing is
like a full-on editor, which also has
Vim key bindings if you want. Yay! Okay.
Then I'll try it. Okay.
You can turn them on if you want, but you can basically
click in there and edit pieces. Like you can
double-click, it'll select a word, you start typing,
it replaces that. Super cool, it has like a kind of a new way to like keep your
input focused in one area, which is really nice. So instead of it just being at the bottom of the
screen, you can have it like always at the top or always at the bottom. Um, one of the things
that's cool is like, it treats the output of every command as a solid, as one thing. So if I do like an LS and there's
like 50 lines and I tail a catalog or something, and there's like a thousand lines. And then if
you want to go back, you can actually just go back by selecting each block of that. So go back a
thousand lines, go back 50 lines, do a search. You can search just that 50 line section from that one
command, even though your terminal is full of junk. Super super super cool uh it does tons of autocomplete which is super neat um let's see one
thing else um you can if you do some kind of command you're just talking about like simon
asking chat gpt for what does like a command mean so if you said like ls-1 what does the one mean
you know you hover over the one it'll like pop up
little documentation for what dash one means oh that's cool yeah uh also as ai built in if you
want i might use that very much but you could like say hash how do i you know write this kind
of loop in bash or whatever and it'll it'll print it out for you but i don't use that one too much
but anyway super super cool. A lot of interesting
things. It has the control R
history, kind of like
McFly, which I've talked a lot
about how cool McFly is. So
giving this thing a try for a few weeks. Really enjoying
it so far. Cool. Love to try it.
Yeah. So people can check that out.
And yeah, pretty neat.
Kim says we've come a long way from
a few years ago when Windows Terminal and Awesome is in the same sentence.
It's, yeah.
I thought it was a joke also.
I didn't, I can't believe that you said that.
No, Windows Terminal is, it's,
I don't want to be on Wikipedia,
but it is definitely, definitely nice.
So I'm not on my Windows machine
and I'm not sharing my terminal anyway,
but let's see if I can get it to show hotkey. So like, and it doesn't really show it great, but you can
click on this, like you set what the default shell is that you want it to do, but you can
click this. It'd be like the bash shell, the, um, power shell, whatever that these play
music. I can't take it, but yeah. anyway, the Windows, yeah, check out Windows Terminal.
It's actually good.
And Kim is right.
We've come a long ways, but yeah.
Okay.
All right.
All right.
You convinced me, I think.
So I'll try it.
Give it a try.
Give it a try.
All right.
What's your final thing?
People should check out Warp.
It's pretty neat.
I will.
Yeah.
Oh, hold on.
One more important thing here.
Mac only for the moment for people,
but they're working on Linux and Windows.
So you can sign up to get notified
if you're not a Mac person.
So just that caveat for now.
I, did you,
Python 3.7 end of life,
and I didn't even notice.
What?
That was a good one.
That was one of the good ones.
You can trust that one.
So 3.7 end of life was in June, in June 27th. No, that was the first release. End of Life also. End of Life 6.27.23. Interesting. But why did I not notice it? I didn't notice it because everybody's, like you said, 3.7 was one of the good ones. We have data classes in there. F-strings came in 3.6, and they got improved in 3.7,
and then they got improved in 3.10 again,
and all sorts of stuff.
But it is something to pay attention to.
I noticed the first notice today,
I was looking at the VS Code announcement for the new,
what was this?
Python for Visual Studio Code, October, 2023 release mentions, um, that, uh, the three
seven support is still, it's still probably works, but they're deprecating three seven
in support.
So just to be aware, uh, I was also surprised if it didn't work because what was removed
in three eight that was in three seven
like syntax wise not functional wise i i can't think of anything uh yeah so that i so there's
a couple projects or several projects that i'm supporting where i support down to three seven
um i dropped three six a while ago uh but one of the things that catches me a lot,
the remaining thing that catches me is annotations.
And I want to cover, like,
if you really want to still support 3.7 or didn't know that it was this easy,
at least for the code I write,
the main thing is I like to use union types.
So I like to use this or type for unions.
And this came in in 3.10.
However, I can't find this documented anywhere,
but to get it to work down to 3.7,
you can do from future import annotations.
And we've been used to using the from future
for various things for a while,
but it looks like 3 three seven might be the end
of needing from future for a while.
I don't know, maybe they'll come up with something else
that they're backboarding.
But it doesn't look like there's anything else right now
up to 312 that you need to go back down.
It's just annotations so far.
So, and I guess I want to show a little bit of an example
for the annotations.
So for data classes, data classes are awesome because you can type the variable that you're using.
And then I often like to have it be none by default, which so a string, it's going to
be a string or it's none.
So the or none is easy just to do the or none.
And I know you can do optional,
but this is just visually more pleasing to me.
And to get that to work down to three,
seven,
it's yeah,
it's just the from future important annotations and it'll work all the way down to three,
seven.
So it's just what I wanted to mention.
And I think that it's also good to be aware,
I guess that,
that three,
seven is end of life because some
of the things you depend on might start
dropping support for 3.7.
It's fair game at this point.
I mean, open source
projects, they're fair game to drop support
for everything below 3.12
if they want to. No one's
signed a contract with anyone here. They can do
what they want. Yeah, but it's
good to be aware of.
It certainly is. That's a what they want. Yeah, but it's good to be aware of. It certainly is.
It certainly is.
That's a cool graph you got there, too.
Yeah, yeah.
Is that in the show notes?
Yeah, it's from devguide.python.org with the versions.
Yeah, Christian Lederman says,
Walrus was introduced in 3.8.
I don't know if you can do it from future import Walrus.
I don't think so.
If you do, you have to do an emoji, not the actual word walrus.
But you got to put the emoji of a walrus and then it'll work.
Well, I'm waiting for like emoji operators.
So that would be fun to have to put, not just can put, but you have to put emojis in your code.
So what happens when the cat raises its paw against an integer?
Oh, let me tell you, that one's really awesome.
Yeah.
Yeah, some of those conversations,
like Christian was saying that,
I think where I was saying,
what is in 3.7 that's not in 3.8?
And those are all true, all those things.
There are new things,
but if you wrote 3.7 code and then ran it against 3.8,
it should still validate in MyPy.
It should still work in Python, right?
There's no thing that was in 3.7 that because MyPy is not supporting it, it will say removed that caused all sorts of drama for me because some library I was using didn't use the word async.
They just used the decorators.
But even that, a decorator should still validate in MyPy with that context, right? Maybe I'll revisit my opinion of supporting 3.7,
so we can use the Walrus operator in 3.8.
But Henry Schreiner also notes that the equal for F strings,
so that you can say X equal, and it'll print the X equal.
That's super handy.
Yeah, it's good for debugging.
Yeah, and just having having that
stuff in your uh in your code like that'd be great so yeah and these things are super small
and subtle like the walrus operator i take i took the website down with the walrus operator once i
said i told that story before yeah and like not even the main website just it was in a little
utility but it got parsed by the route finding thing and killed it. Well, that's it for items, huh? Yeah, it is.
Awesome. Extras?
What you got? I got a couple since I got my
screen up. Just one of the examples
I showed was from a new
plugin that I just released
called PyTest Paramscope, and this
allows you to
for parameterized fixtures, or for
parameterized tests, to have a
startup that goes,
a setup that happens before all the parameters
and a teardown that happens at the end.
It's still, the API is up, there's a warning here
because the API might change with respect to teardown,
working on yield functions for that.
I also, I was gonna cover this as a full thing.
Oh yeah, this is just sort of
how you use it you get like a setup and turn it oh no this is this is how i want to do it this is
the change that i might do of adding yield so anyway um uh simon willison uh wrote a article
called uh stop defining people no not simon willison sorry josh simmons uh sorry josh uh wrote an article called stop
defining people by what they are not um and he was referring to non-code contributors and i kind
of agree so i wanted to highlight this article this is this is great just basically saying all
contributions are awesome and trying to and elevating code contributors above non-code contributors
is just not right, so don't do that.
Also, it's just referring, I mean,
if somebody only writes, just mostly helps with your test code,
you don't have to call, I mean,
you can say somebody that's contributing test code.
You don't have to say, oh, that's non-code.
Well, that's still code.
But anyway, you know what I mean.
Yeah.
People helping with documentation is great help.
People helping with writing tutorials is great help.
Everything is good.
So, anyway.
Sometimes it's more important to have a good example so people can get started quickly.
Oh, yeah.
And enjoy the project rather than like one more feature, you know?
Yeah. And also things like cleaning, triaging issues and answering questions and keeping, you know,
making sure that all the issues are closed when their things get fixed and all
that sort of stuff is tons of work. So it's great help.
Yeah, absolutely.
Do you have any extras?
I got a couple quick ones here.
So OpenAI has released the beta version of their Python SDK. It's pretty
exciting. So if you don't want to implement your own raw HTTP, JSON parsing, and hope that you got
everything right, you just go there, start calling the functions that they write for you. And it
should be going nicely. So it's still in beta, but people can check that out. That's pretty awesome.
I think, was it here? I can't remember somewhere. No, it wasn't here. Maybe it was on the linked
article. There was somewhere where there's a bunch of people whinging, like, why can't people just
call HTTP? They're so lazy. They want a library for it. Like, you know what? Maybe like let somebody
else handle the evolution of that API. You just call a stable Python set of functions and not
worry about that. Wouldn't call that lazy.
I would call that PyPI and call it awesome.
Anyway, so people are into open AI.
What do you need Python for?
Just call the raw C API.
Exactly.
Can I just do this with like a bunch of bash scripts and some curl?
Let's go.
All right.
So sad news here is, um, chat GPT is how not that overflow.
I'm probably because partly a chat GPT, get that in order right there. Stack overflow
is laying off 28% of their staff. It's kind of surprising, huh? Yeah. Which turns out to be
a hundred to 200 people. Like a lot of people, not like they had four people and they laid one of them off.
But he was really important.
What exactly would you say you do here?
No.
I didn't know that Stack Overflow had so many people working for him though.
I know. It was founded just by Joel Spolsky and Cody Norgay, whose name I don't remember anyway.
But yeah, it's growing to be super, super big. And I don't know. I always sometimes wonder like, do you really need a
thousand people to run that website? I mean, maybe, but maybe you just don't anyway. Uh,
that's a whole different discussion, but, um, so there's some interesting conversation saying
maybe this is because of chat GPT and Google Copilot and all these other things.
Like instead of going to Stack Overflow to go, how do I connect this type of thing to that type of database?
You can just ask your coding assistant or your chat buddy and you'll get a great example.
Oftentimes more specific, right?
Like, yeah, but I'm using this version.
Oh, well, if it's that version, you got to pass this argument too.
Right.
Thanks.
Got it.
You know?
So this is pretty interesting.
Kind of odd or weird, like six months ago, Stack Overflow wrote a blog post that said,
what's different about these layoffs in the tech industry?
Not us.
We're fine.
Everyone else.
And then, you know, six months later, you know, go back and read you an article sadly so that's uh
an interesting thing to be aware of i guess yeah uh yuri selyevanov just pointed out or posted
on the ext that uv loop uh 18 is here with python 312 support so i was trying to use 3.12 on a couple of the TalkPython things and the websites
are like, nope, UV loop, no, AIO HTTP, definitely not going to work on Python 3.12, which is,
I think AIO HTTP still doesn't work. And sadly, some rummy dependency that I have is like
using that library, which itself is not being upgraded to 3.12, at least as of like a few days ago.
So this gets me halfway there, the two things that wouldn't install.
One more to go.
Hanging in there for AIO-HDB.
Come on now.
But good news nonetheless.
Thanks, Yuri, for doing that.
Oh, and thanks, Kim, for reminding us that it was Jeff Atwood.
Yes, of course it was.
Thank you, Kim.
That's the guy that went by Coding Horror.
That's what happens when you have too popular of a nickname that you've given yourself like Coding Horror
in your blog. Yeah, plus that
logo or icon that he's
got. I can just see it in my head.
I can too. I can. Like the hair on fire
developer picture. Yep.
Alright, those are all my extras that I got for now.
Yeah. Ready
for a joke? I am. We might even
have two jokes, but we'll see about that. Yeah, I've got one
I wanted to share also.
All right.
So this one comes from Command Line Magic, but was pointed out to us by Lizzie.
Said, I love it.
Hey, I'm Kennedy.
Maybe for the show.
And the Command Line Magic says, I've always read that global variables are bad.
So this is the Star Trek thing.
And can I make it bigger?
Yes.
The Star Trek thing shows, I can't remember this character's name,
this woman scientist on a shuttle.
This is all from Star Trek.
And they're going right through near the edge of the sun to do some studying.
And she wants to be real careful to make sure that the ship doesn't melt.
So she says, computer, notify me if temperatures get too hot. Beep,
beep. Please define hot, says the computer. Let's say 1.9 million Kelvin. Okay, fair. Later,
Captain Picard is at the little food making thing that materializes food. It says, tea, Earl Grey,
hot. It just melts. It just sets it at 1.9 million Kelvin in his captain's quarters.
Yeah. That's awesome. Isn't that good? Yeah. I like it. Yeah. A little too hot.
Somebody should test this. Yeah. A little too hot. Maybe that tea was real hot.
Yeah. All right. What's your joke?
So my daughter shared this with me and I just like, I haven't stopped giggling about it. So
you've been to the Oregon Zoo, right?
Yes.
Yeah.
Did you, do you know there's a new exhibit there?
No.
It's just a baguette in a cage.
It's bred in captivity.
Oh my gosh.
Bred in captivity.
Yeah.
That's hard to do.
You know, a lot of times you try, but it just doesn't happen.
Does it?
I guess they pulled it off.
Yeah. Awesome. This know, a lot of times you try, but it just doesn't happen, does it? I guess they pulled it off. Yeah.
Awesome.
This bad, bad dad joke.
Those are very bad dad jokes.
But I was just thinking about going to the zoo.
I haven't been there since maybe a year.
I was thinking about taking my daughter back there.
What's weird is we almost always go to zoo lights.
Yeah.
So I see a lot of animals all in they're all in lights instead
of actual the actual animals exactly we need to go yeah just put them on the wall and have them
flashing for christmas that's right yeah i actually i really appreciate the uh during
covid they like started doing the the drive-through zoo lights um and they still do it like partly
part way so you can do drive through for a couple days or something and then they switch drive-through zoo lights. And they still do it like partly partway.
So you can do drive through for a couple of days or something.
And then they switched to walking.
I like driving through.
It's nice.
So yeah,
it is nice.
Definitely nice.
All right.
Well,
we're coming up on the end of the year,
so we'll have to get a report on the zoo lights.
Yeah.
All right.
And the bread and the captivity bread.
Bread.
Bye.
All right.
See y'all.