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