Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds.
This is episode 337, recorded May 23rd, 2023.
And I am Brian Okken.
And I'm Michael Kennedy.
I want to thank everybody that's watching, but anybody that's listening,
I encourage you to at least once in a while drop by YouTube
and see the upcoming list of events at pythonbytes.fm/live to be part of the audience.
It's usually fun.
It's usually Tuesdays at 11 Pacific time.
Occasionally we switch.
If you'd like to connect with us, we're all on Fostadon, or at least the three of us, Michael and I on the show.
It's mkennedy at Fostadon and at Brian Okken and at Python Bytes.
And with that, let's jump into our first topic.
Let's jump into it.
It's not going to be a rough one, is it?
So the first topic is rough, which is obviously, you know, Charlie Marsh's project.
It's very successful.
People know that.
It's not exactly rough.
It's a way to use rough.
And this one comes to us from John Hagen.
John runs this project called Python Blueprint.
So he's been playing around a lot with that project and PyCharm and rough and realized that now there's a plugin for all the JetBrains IDEs, most notably PyCharm, called just rough.
And the idea is that, you know, PyCharm has all these little squigglies and warnings and maybe even more importantly, the auto corrections.
So it'll do things like if you wanted to replace double quotes or single quotes, you can just hit Alt-Enter and it'll suggest, hey, why don't we just do that for you?
All right.
Things like that.
And so this integrates all the rough functionality into that same basic UI system, right?
You get little warnings or errors on the screen based on rough output.
So it has inspection and highlighting.
It can set it up so it runs rough on your code when you run reformat code or just hit the hot key, Command-Alt-L, Control-Alt-L.
It has the quick fixes that I was just talking about.
And it will actually run, you could run rough-fix as an action.
And you can even run that when a file is saved just automatically.
Like, hey, if there's stuff wrong with it, just fix it rough.
Just do that for me.
You can configure which version of rough is running.
So basically the plugin lets you specify, do you use a global one, maybe managed by pipx, do you use a local one in a virtual environment?
I sort of feel like isolating that to a per project basis is the right thing.
So that's what I'm doing, playing with this.
And yeah, you can run it as a new process.
You can specify a config option, like a YAML.
I'm not sure what the format that is, but whatever the rough config file format is so that you can say, you know what?
I don't really care about the line length for this thing.
So just ignore that and don't ever run that and so on.
So yeah, you can even run it out of a WSL Windows subsystem for Linux.
And there's some nice screenshots, as all UI things should have in there.
You can even see some of the settings if you want to try it out.
So it has 4.8 out of 5 ratings and looks pretty new.
But yeah, anyway, I think it looks like a good option.
So people can check that out.
Also, yeah, I'm really excited about it.
I've installed it and going to give it a try.
You can go check out the, it's open source, obviously.
So you can go check out basically the repo for the plugin.
And John sent over to us and I'm linking to this thing where it says you can add additional PyCharm specific instructions for both black and rough.
So he's got this section that shows you basically how to integrate both black and rough at the same time as automatic code formatters and PyCharm using the file watchers plugin.
So just follow along with the steps there.
And even has NOC support.
But yeah, cool.
So if that sounds interesting to you, if you want to have kind of auto rough just built into PyCharm and you use PyCharm, then check this out.
It looks cool.
Thanks, John.
Yeah, that's nice.
And rough, of course, is written in Rust.
And I'd like to talk a little bit more about Rust.
So there was an article I ran across called, it's from Koblo's blog.
Don't know who, that's a first name or last name, but thanks, Koblo's.
Writing Python like it's Rust.
And what I haven't written Rust yet, but a little bit.
Anyway, the thing I liked about this article was really basically he's going from Rust back to Python programming in both.
And one of the things he misses is some of the safety that types give you.
So he's discovered that he's changing or they're changing how they're using types within Python.
And I kind of liked some of the suggestions.
I think these are some of the things I didn't even think of before.
The obvious one, of course, is for function signatures.
So we really want to, if it's not obvious, like there's an example with a find item with records and check.
But what is that?
What are those types of those things?
So it's really helpful to your call, the people using your API to specify what the parameters look like or what you expect them to look like.
And there's so many options within Python now.
And also that, too, return value.
And here is an example.
It's optional item.
So I actually hadn't thought about that, of like using optional as a return type.
That's pretty cool.
Which means you can either, and you could probably do like item or none to say,
it can return none or something.
That's a, it is good to, especially if it's something, if it's possible to return none,
good to have that in the types.
So that's the low hanging fruit.
That's, I think a lot of people have gotten there yet already.
The other thing that I found recently is I've got some types that are like tuples or dictionaries or specifically a specific kind of dictionary,
like a string to any or even I use name tuples a lot, which are a little bit better than just your normal types.
But his recommendation is to go ahead and use data classes because they're more descriptive.
even if it's similar information, you can write up a little data class.
And then like in the example, instead of saying that you're returning a dictionary, go ahead and return like a person item, specific types.
And I'm kind of used to that from C++ of like writing little types because they're more, they're more descriptive and they're easier to read sometimes.
So bringing this into Python is kind of a cool idea.
The other, one of the things I thought was really awesome is this idea.
There's an example using the, where he's using like these packet types.
And since I work with communications a lot, this, this really hit home of you have, you have, you can, a packet might be either a header or payload or a trailer.
This is a Rust example, but you can do the same sort of thing within Python to say, I can have different data types using data classes to specify what kind of information you're going to get from these.
And then you can create a union type and have a, have that be a different name, but related to everything.
And I, I kind of love this idea of using a union type instead of, instead of using the ores.
I mean, using or for types is good too, but combining that into a union type is pretty slick.
Yeah.
That is pretty interesting.
I like that.
It's, so is that if you're going to receive say a packet off a network and it had first the header bit and then the payload and then the trailer or something like that?
Yeah.
Or I'm like a function that takes, that can like count the bits in there or something like that.
And it can either be a header or a payload or a trailer.
You could do something different with those and having a union type is pretty, pretty cool.
Now within it, I'm not, and here's an example of what, how do you do with that?
Deal with that.
You'd still with inside, you'd have to either do pattern matching or if clauses.
I've been using a lot more pattern matching lately to be able to just, you know, this is, this is great for you.
You take the packet type, but then you can match it against either a header or payload or trailer.
This is a really clean way to have union types and then unpack them with the pattern matching.
It's a pretty cool way to deal with that.
So.
Yeah, that is actually pretty clean.
That's one of the better examples of pattern matching that I've seen lately.
And this is just like a third of the article, but the rest of it does talk about different ways to basically, we have a lot of these tools within our within Python now to make it more to utilize data types that we are used to in other languages.
And you can kind of write some really clean looking code and easier to read.
So it's nice.
Yeah, very nice.
I like it.
So Kim out there has a question in the audience.
Ryan, is there possibly some overlap with writing Python after writing a bunch of C as you do?
As in same way, Rust leads to some good ideas in Python.
Yeah.
Well, I mean, that's, this, this is a, this person's writing it from the experience of Rust, but I'm looking at it going, this is a lot of the C++ stuff that I use.
So it is, yeah, I'm looking at it.
We're, we're actually, my team is being, is having a lot more fun with Python with the pattern matching statement because the, I know it can do a lot more stuff, but it really does.
Even if you're just using it to, to get away from a long list of if clauses and make it more like a switch statement, it is so much nicer.
It's one of the, well, easy bits.
So that's a good example.
Cool.
Yeah.
Marco out there says, but do a lot of Rust missing mismatch as well.
All right.
Shall we move on?
Sure.
All right.
Well, go ahead.
Go ahead with your first.
I know you had an announcement as well.
You wanted to give out.
No, I was just wondering, do we want to, today's episode is not brought to you by an external sponsor, but it's brought to you by us.
It is brought to you by us.
And I'd like to hear some of the news from Michael.
Well, the big news for me, which I have sort of put in as an extra now and then is the mobile apps.
So people go out there, download the mobile apps, talkpython.fm/apps.
And in there, if you create an account or log in with your account, at a minimum, you'll find like six different courses that are free.
You just tap on them and you can take those courses right away within the mobile apps.
If you get this super, super quickly, if you're one of the very, very prompt listeners, there's a chance that our Git course actually is free as well as part of a celebration of the mobile app launch.
But that lasts for about eight hours from the time of recording, which will be a few less hours from the time I actually release this to the general public, not in the live stream.
So you'll have to act fast on that one.
But do check out the mobile apps if you're interested in Python courses.
They're a great way to take it.
They have some free ones and they also are the best way to take ones that you paid for as well.
So four months of work.
Finally, really, really nice apps that we got out there.
I'm listening to a couple, watching and listening to a couple, a couple of courses right now.
Not right now, but in some of my free time.
I love the mobile app.
It's working great.
Awesome.
Thanks.
And you also have a thing to shout out as well, right?
Yeah.
I wanted to let people know I wrote a book.
No, you all know that.
But the exciting bit, I just got this email this morning.
So my book, Python Testing with pytest, second edition.
I've had a lot of great feedback of saying I didn't.
People saying they read the first one and it was good.
But the second one really nailed.
They really got some of the concepts in.
So I'm glad that I wrote the second.
So the news, I just got this morning, an email from Pragmatic saying that there is a sale right now.
So there's a whole bunch of other books, but Python Testing with pytest is one of them.
And if you use the coupon code spring 2023, and you can save 50% off of the e-book.
And that's up.
That expires June 1st.
So don't delay.
Spring 2023.
Awesome.
Let's bring you to some testing.
Well, that's us.
How about a new topic?
Yeah, thank you everyone for supporting the show by supporting our work.
Let's talk about pip.
So this is about a month old.
I've been looking to grab a slot to talk about it, but there's been other sort of higher important stuff.
But I do want to point this out.
So Zyrtex over on Reddit, who if you follow over to the GitHub and then from GitHub, I think to Twitter, maybe named Damien.
Not entirely clear.
So I want to give credit, but it's not easy to do.
It says that pip 23 or points out that pip 23.1 was released with massive improvements to backtracking.
And backtracking is an algorithm that is part of the requirements resolver.
So if you say, you know, pip install requests Flask and, you know, something else.
PIP has to say, okay, well, we know what those are.
But both requests and Flask may depend on some library.
I don't think that's true, but I don't think there's an intersection there.
But, you know, follow along.
If they did, then it's got to figure out, well, okay, Flask requires this range of versions and request requires that range.
So let me find a version that will satisfy both of those requirements.
Right.
And there might be a transit of dependency upon that, right?
Like that, that shared, potentially shared library itself has another thing that it depends on.
So the article or not article, Reddit post says, you know, for example, let's say you require package A and B.
The latest versions of A and B are downloaded.
PIP checks their requirements and it finds that A depends on C version 2, but B depends on C version 1.
And so it's got to figure out, like, well, can I go back and get an older version of A that would allow, say, C equals 1 to work, right?
So prior to pip 20.3, the default process would allow pip to install conflicting requirements with a warning saying that this may or may not go well.
We couldn't find one.
That was a good fit.
But that's no longer an option.
I have very mixed feelings about that.
I love that it tries to be more strict and correct.
But at the same time, the alternative or the tradeoff is we guarantee correctness 100% of the time in terms of a version match for all the transitive dependencies across all the different things.
And instead of saying, well, install something that doesn't work or may not work because there might be some functionality that you may or may not interact with that is incompatible version-wise, we're just going to say your application cannot run.
It's impossible for your app to use these dependencies and run.
Personally, I would prefer to say, huge warning, this is not a great idea, but at least you can take a shot at it rather than it's impossible for you to run this application.
But, you know, that's the tradeoff pip made.
And because of that, it has to be even better at tracking down these version matches as best it can because the alternative is your application cannot be installed and run.
So there's a lot of interesting history here, but it talks about some of the algorithms that have been used and points out that pip now separates out the resolution logic into a library called ResolveLib.
And it was discovered that there was an error, logical error that both for performance and for correctness as well, you know, better backtracking technique called back jumping and an actual error that were fixed and implemented in ResolveLib and now come out in 23.1.
So if you're using pip and if you're listening to us, there's a real good chance that you are.
You want to upgrade your pip to 23.1 or higher.
Whenever I install requirements, I just have like a multi-step macro or alias.
The first thing it does is say, pip install --upgrade pip.
Now go try to do the other stuff, you know, just it's like a concept for me, but I know not everyone does that.
So when you see that little warning that says, hey, warning, your pip is out of date.
If it's less than 23.1, you probably want to take that advice and update it this time.
Yeah.
Just this morning, I got a message.
Sorry, we cannot install your website because some, you know, Sentry requires this version of EuroLib 3 and Request requires a different version of EuroLib 3.
So you can't run your app.
Goodbye.
It's like, come on.
I'm sure that it's not actually using the conflicting.
And one thing that this does point out here is traditionally people haven't had to worry about this.
So you'll see things like one of the dependencies will say it has to be exactly like 1.2.3.
When really what it means is it's got to be lighter than 1.2, you know, and they've just pinned it overly tight.
And you end up with this crash where, you know, for sure that it wouldn't actually be a problem in your situation.
Like, how do you know?
Well, because before pip 20.1, it was running, you know, those kinds of things.
And so there's this little bit of, you know, I know it's great that it's trying to be more accurate and precise, but sometimes I'd rather have at least an option than none.
And so, I don't know, there's a whole interesting discussion down here.
People can check it out in the comments.
It devolves into a debate about Python 2.3 for a little while, which is weird.
And then just skip that.
That's not productive reading.
But there's some interesting conversations going on there.
And also, before we move on really quick, Brian, there is, I think it's Damien, as I said, points out that there is a PEP 658, which is accepted.
Or what version of Python is this?
I don't know, 2021.
So a couple versions ago.
That allows the metadata.
It used to be that pip would actually have to download and install a package just to see what the dependencies were.
And now that's separated out the metadata so you can get a very simple, small download without trying to do stuff to it to go, what does this actually need?
This version needs what?
Right.
So there are some improvements that are being brought into here, but still, there we have it.
Yeah.
A couple of comments, which I kind of agree with.
It'd be from Grant.
It'd be nice if there was a worn unresolvable or something to keep the old behavior.
I agree with Grant on that, yeah.
So I guess this is a reminder to library authors as well that your dependencies, you might know that you have a lower limit on some dependency that you need.
You need version like 1.2 of this library or above.
Think about it.
I prefer to have libraries in their dependencies, the transitive dependencies in a lower bound and not upper bound version because, I mean, you don't know what the upper bound is unless you do.
Unless there really is, there was a breaking change and you really know that there's a break.
Right.
The thing for me more is about, which I agree with you, Brian, and the comments, but it's about like there might be an absolute 100% conflict.
Like if this library tries to do, so for example, let's say like request tries to use Kerberos authentication instead of basic authentication.
And in that scenario, this other library does something crazy.
It crashes unless it's high enough.
If I'm never using that authentication mechanism, I'm never going to.
So like, yes, it is actually a break and change, but it's not a break and change for me.
Oh, yeah.
In my use case of that, the combination of those two things, right?
Like that's, that's kind of where I've been thinking about this.
Oh, yeah.
Interesting.
Yeah.
Because there's a lot of like a lot of Swiss Army knife libraries out there and you're not using all of them.
You probably, it's very unlikely you're hitting 100% surface area of a thing and its dependencies, right?
Exactly.
Yeah.
Interesting.
Yeah.
All right.
Well, anyway, this is, this is an improvement.
I feel like we're kind of like debating the 20.3 debate.
This is an improvement on the stuff that's already been decided to be done.
So 23.1 is a good way to go.
Yeah.
It's good.
Last item was a kind of a cool tool called Markdown Code Runner.
So this, this did remind me of a tool that I've known before.
So the Markdown Code Runner is a package that automatically executes code blocks within a Markdown file.
It's, it can include hidden code blocks.
So you can have, the code blocks can be in comments.
And so you can't see it in the Markdown file.
It just runs it.
So it runs the snippet and then you can have the output show up somewhere.
So this, in the example, let's run to an example.
You've got a little, a code block that says Python, but instead of just Python, you say, you know, you got your back ticks and then you say Python space Markdown dash code dash runner.
And then it runs the code in the code block and then it pops it out.
You've got another couple of comments for output start and output end, and it'll throw the output in there.
The kind of the neat thing is it's not just for Python.
It's for bash also.
So you can run some bash scripts.
Like if you want to show a, I was thinking if you wanted to show what the, the, the directory looked like with the tree command, you can go ahead and run tree within, within a Markdown file and run it or other stuff.
Has, has, has several examples that they think would be neat.
Things like, oh, I don't know, like diagrams or tables or various things that you might want to output with Python visualizations.
You can use that.
This is really cool.
Yeah.
It did kind of remind me of cog, but the, the syntax is a little different.
So cog from Ned Batchelder has, is a similar sort of thing.
You throw, you throw some code in, in place with some special tags.
He uses like a three bracket tags instead of an actual code block.
So the thing I kind of like about this is a lot of times I actually do want to show the code block.
So you can go ahead and show the code block and then run it.
So that's neat.
So some, some, it's fun.
I tried it a little bit.
There's an example of using rust.
So you can have actually running rust also.
I couldn't get the rust example to work, but I got the, the markdown and the, or the, the Python and the, the bash examples to work.
So actually pretty cool.
The, within the documentation, it also talks about running this as a Git lab or a, yeah, get, get, get, github, a CI snippet.
So, and that, that'd be a great place to do it is to just rerun your, rerun, like reproduce the code output from your readme on the new code.
So kind of a cool idea.
Yeah.
My first thought was, Oh, I have a code example and it says the output is this, like rather than trying to maintain those, just let it put the output there.
But it's also could be useful for just, I have a little Python bit of code that generates some other output that is, is useful, right?
Like here's the go through and generate a little, all the topics that it saw in the subjectry or something like that.
Yeah.
Like kind of a, just a markdown, like a macro within a markdown.
Generate a table of contents or something.
Yeah, exactly.
Something like that.
Cool.
That's all of it, right?
That's all the main topics.
That is our main topics.
Yes.
All right.
I have a few extras to throw out here.
Let's jump over there real quick.
So same person who pointed out the rough plugin, John Hagan also pointed out, you know, I had talked previously about how I wish pip would update itself when I create a virtual environment by default.
So if I say Python 3.0.
So if I say Python 3.0.m.
V and V and V, the very next thing after activating it is your pip is out of date.
My God, geez.
Okay.
So hence, that's partly why my first thing to do is always upgraded is just to not see the warning more than anything, honestly.
But pointing out that since Python 3.0.m.
But pointing out that since Python 3.9, there's an additional option you can pass to the virtual environment creation story.
So instead of just dash M, V, and V and V directory, you can also pass --upgrade depends, which will automatically do that upgrade of pip and dependencies as well.
Pip setup tools to the latest version as part of creating the virtual environment.
Yeah.
So nothing major, but quite nice, right?
Yeah.
I mean, I usually have that as a second step within my little macro.
So do I.
And I was looking to replace that.
And I'm like, you know what?
Not quite.
Because I also want to install things like pip-tools and a couple other things that this doesn't include.
So I'm like, I still would have to write that line.
So I'll just leave it.
But anyway, still, it's really nice to have --upgrade depths.
You want it to have a shiny new virtual environment all the time.
Yeah.
And one of the things I really love that came in like a few versions ago is the if you do the --prompt and give it a dot.
It uses the directory name.
Yeah, that's really excellent.
It names the virtual environment containing directory names.
So it has like the name of the virtual environment is the name of your project often, which is great.
Yep.
All right.
More things, more extras.
One is PyCon South Africa.
PyCon ZA will be held in Durban.
And the most important part here is that the call for proposals is out.
And when is the time frame?
Kim will have to let us know.
I know he's out in the audience.
But yeah.
Oh, here we go.
Talks need to be submitted by August 18th, 2023.
And it's pretty good.
I think it's both virtual and in person.
So some good options for people to attend and down in October.
And it's pretty convenient for Africa, Europe, much of Asia, although less so for, you know, you and me, Brian.
That's all right.
Yeah, cool.
So people, if they want to talk at PyCon South Africa, be sure to submit that talk.
And Kim says that's a soft deadline, but sooner is better.
Okay.
Generally true.
I got a friend that's in the cybersecurity area, and he's up all night anyway.
Yeah, there you go.
Yeah, you could definitely do it if you just live off hours.
Yeah.
Real quick follow-up from something before, Brian, and then we'll get to a joke.
I had put out a call to everyone and say, help me find some off-road trails for this adventure bike thing that I got into.
I didn't really get any feedback.
So I'm going to instead pay it forward to other people out there who might be listening to my ride.
So some really cool apps on X off-road.
You can go through and find, you just click a spot on the map, and it'll show you, like, here's all the public legal trails for you to go tear around on.
And they're even rated, like, 5 out of 10 or 7 out of 10 with pictures and distance and challenges.
So you can decide up front whether or not you want to go down that path, I suppose.
There's also GAIA, G-A-I-A, which is a similar thing.
And then backcountry discovery roads, which allow you to find, like, how do I traverse my state, at least in the U.S., or similar things in Europe with the Tet.
How do you, say, traverse all of Oregon, almost 100% off-road through the forest and the mountains and the deserts?
And so there's this app that has all these, like, GPS trails.
So anyway, I found some cool trails way up in the mountains using this app and can recommend it to people.
Neat.
Cool.
Yeah.
Cool.
All right.
A joke.
You got a joke for us.
Yeah.
I can't remember where I found this, but there's a website called userinyourface.com.
So instead of user interface, userinyourface.com.
So you just have to fill it out.
So...
It's like an anti-pattern, a whole combination of anti-patterns into one UI.
Okay.
So just start off right off the bat.
So for people listening, I'm sorry, you're going to have to watch this on the video or something.
Or visit the link.
Or go visit the link.
It says, Hi, and welcome to User Interface, a challenge exploration of user interactions and design patterns.
To play the game, simply fill in the form as fast and accurate as possible with a button that says, No.
Big green button.
So it says, Please click, underline, score, underlined click here to go to the next page.
And the next page is highlighted.
And the trick is, the only thing that you can click on is the here button.
It's not a button.
It's just, that's it.
Okay.
And then it...
Okay.
The site uses cookies.
Is that a problem for you?
Yes.
Yes doesn't do anything.
Okay.
No, not really.
That goes away.
Can we help?
There's a help field with no enter.
Just send the bottom.
One of those dreadful chat messages that pops up.
Yeah, it's great.
Choose your password.
You click on it.
And the highlighted choose your...
Or the preview text is already there.
So if you add your password to it, it doesn't delete the old one.
You got to like fill that out.
Oh, you can't tab through anything.
So you have to click.
Oh, the email's bad too.
Yeah.
Instead of a placeholder, it's just gray, actual gray text.
Yeah, but you also can't delete it.
Domain.
Oh, this one you have to delete also.
And oh, there's a hurry up.
Time is ticking.
A pop-up.
One minute.
A four.
Can I hit the...
Oh, the X isn't an X.
It's a maximize button.
Lock?
The copyright's a close.
Lock, unlock.
This doesn't do anything.
Oh, the close is the copyright.
Right.
That isn't obvious.
Yeah, okay.
I do not accept these terms.
Okay.
Cancel.
Oh, I'm not...
No, I meant okay.
Are you sure you want to cancel?
Cancel to cancel.
Next.
Oh, it says already selected.
I do not accept.
So you have to uncheck it to accept the terms and conditions.
What are the terms?
Yeah, okay.
Good luck getting out of that dialogue.
You got to scroll down to accept them now to get out of it.
Okay, well, we're stuck now.
Because you can't even...
Okay, this is terrible.
Anyway, I did get through it.
The fastest time I have so far is like five minutes.
People are going to speed run the in-your-face interface.
Yeah.
I'd love to see a speed run to see how fast...
If somebody can really get through it in like a couple minutes, please do a video.
I want to see that.
So...
Jeff out in the audience says, I worked for the company that made that site.
Yeah.
So, yeah, the company looks like Veerheart.
So, nice.
Yeah.
All right.
Well, that's enough frustration for one day.
Indeed.
Thanks again for joining us and doing another Python Bytes.
Thank you, everybody, for watching and listening and supporting us through the courses and books and everything.
And Patreon supporters.
We still have Patreon supporters.
Thank you, Patreon supporters.
Absolutely.
And thanks, Michael.
Thanks, Brian.