Latest / Talk Python To Me / #441: Python = Syntactic Sugar?
Transcript
- 0:00You've probably heard the term syntactic sugar.
- 0:02That is syntax within a programming language
- 0:05that is designed to make things easier to read or to express.
- 0:08It makes the language sweeter for humans to use.
- 0:11It turns out Brett Cannon has spent two years diving into
- 0:16and writing about Python's sweet language features
- 0:19and how they really work down inside CPython.
- 0:22He joins me on the show today to dive into a few of the more relevant posts
- 0:26he's written about.
- 0:27This is Talk Python To Me, episode 441, recorded November 1st, 2023.
- 0:32Welcome to Talk Python To Me, a weekly podcast on Python.
- 0:50This is your host, Michael Kennedy.
- 0:52Follow me on Mastodon, where I'm @mkennedy,
- 0:54and follow the podcast using @talkpython.
- 0:57Both on fosstodon.org.
- 0:59Keep up with the show and listen to over seven years of past episodes
- 1:03at talkpython.fm.
- 1:04We've started streaming most of our episodes live on YouTube.
- 1:08Subscribe to our YouTube channel over at talkpython.fm/youtube
- 1:12to get notified about upcoming shows and be part of that episode.
- 1:17This episode is sponsored by us over at Talk Python Training.
- 1:21Did you know that we have over 250 hours of Python courses?
- 1:25Yeah, that's right.
- 1:27Check them out at talkpython.fm/courses.
- 1:29Brett, welcome back to Talk Python To Me.
- 1:34You've been here a time or two.
- 1:35Always great to have you here.
- 1:37Well, thanks for having me yet again, Michael.
- 1:38I'm glad I've not worn out my welcome quite yet.
- 1:41You always have so much cool stuff going on
- 1:42and so many interesting perspectives.
- 1:44Some would call them interesting.
- 1:47Whether that's a positive or negative is still open to interpretation.
- 1:51May you program in interesting times,
- 1:53as the old ancient proverb goes.
- 1:55Mm-hmm.
- 1:56So, been here a bunch of times,
- 1:57but real quick, just tell people a bit about yourself before we jump in.
- 2:01Sure.
- 2:01Just in case they don't know you.
- 2:02Yeah.
- 2:03Name's Brett Cannon.
- 2:04I live in Vancouver on the unceded territories
- 2:07of the Squamish, Tsleil-Waututh, and Musqueam First Nations.
- 2:10I am currently the dev manager for the Python extension in VS Code.
- 2:14I am serving my fifth and, as of now, final term
- 2:19on the Python Steering Council.
- 2:20I'm stepping down just because when we first created the Steering Council,
- 2:24I said five years seemed like a good term limit.
- 2:26We actually don't have term limits, but figured I'd stick to my word.
- 2:29And I'm also, thus, also a core developer.
- 2:32I've been doing it for just over 20 years.
- 2:34Lucky for me, I got it, my first commit bit right after the,
- 2:38sorry, my first commit bit after the first PyCon.
- 2:40So, I get to use the PyCon anniversaries as a way to keep track of that.
- 2:43So, that's convenient.
- 2:44That's kind of the biggies.
- 2:46Have a cap.
- 2:46Yeah.
- 2:47That's usually the other thing people like.
- 2:48Something about VS Code?
- 2:49I've heard that word.
- 2:50It's an editor, right?
- 2:51Yeah, I know.
- 2:52Someday, you'll say you use it,
- 2:54and I'll be very happy that day.
- 2:55I had it open today.
- 2:57Oh, all right.
- 2:57Well, there, I'm happy today then.
- 2:59Yes, indeed.
- 2:59No, awesome.
- 3:01So many cool things you got going on.
- 3:03And despite all of that background in steering council, core dev, here, this time, you're
- 3:10here to give us, like, diet advice, eating advice, like something about sugar.
- 3:15What is it?
- 3:15Yeah.
- 3:16Just a slight story behind all this.
- 3:18My wife was taking the certificate in data science course at the University of British Columbia,
- 3:24which is actually our alma mater and where we met.
- 3:26And she was doing her homework in a JupyterLab notebook through the browser via JupyterHub.
- 3:35And she stopped doing the homework to go, I can't remember if it was lunch or dinner, but
- 3:39basically stepped away for like an hour or so.
- 3:40And then she came back and the run buttons on the cells weren't working anymore.
- 3:44I was like, well, what's going on?
- 3:45And I looked and I was like, oh, well, you got disconnected from the server.
- 3:48I said, well, isn't that happening in the browser?
- 3:51Like, no, Python doesn't run in the browser right now.
- 3:54It's not a thing.
- 3:55Oh, OK.
- 3:55I think about a day or two later after she thought about it, we were in the car and I
- 4:01still remember the exact location in Vancouver where this occurred.
- 4:03My wife said, you know, you should probably fix that problem of Python not working in the
- 4:08browser.
- 4:08And I explained like what WebAssembly was and how big of a thing that would be to make
- 4:12that all happen and all that.
- 4:13And she literally took about a beat to wait and said, no, you should go fix that.
- 4:18Part of that led me down the road of trying to figure out what the minimum viable Python
- 4:24was, right?
- 4:24Like, what is the minimal amount of Python I would have to implement in the browser or in
- 4:29WebAssembly in this case to make Python work?
- 4:32And I had realized that, you know, a decent amount of Python is actually what's called syntactic
- 4:37sugar, which is really just syntax that you could actually devolve and unravel into other
- 4:43syntax of a language and have it do the exact same thing, right?
- 4:47It's just basically syntax that's a shortcut.
- 4:49And so I ended up going on this very long journey, unexpectedly long, of trying to go through
- 4:56all of Python syntax and trying to figure out which parts of the syntax was like crucial
- 5:01and you couldn't actually re-implement it in pure Python itself and which parts you could
- 5:05actually just make it work with Python code itself.
- 5:08With the idea that at the end, it would have basically a list of the bits of Python that an
- 5:13interpreter would have to implement and the other bits of syntax where you could run some
- 5:17tool over it ahead of time.
- 5:18It would just translate from Python to different Python code.
- 5:21And in that way, I would just know what the exact target would have to be.
- 5:25It might not run very fast.
- 5:26Don't get me wrong.
- 5:27But it would at least be a very clear definition of kind of what you have to have to really call
- 5:33something Python.
- 5:33It's everything else.
- 5:34Right.
- 5:34kind of just work around.
- 5:36Right.
- 5:36So the standard Python syntax we expect still works.
- 5:40But how much do you have to work behind the scenes to make that happen?
- 5:43So examples that come to mind for me are context managers, the width block.
- 5:47Awesome.
- 5:48I love them.
- 5:49But we have try finally.
- 5:50And you could simulate a context manager effectively with maybe a try finally, maybe an accepts in
- 5:57there as well.
- 5:57But you don't actually need width in the language to accomplish what it does.
- 6:02Right.
- 6:03Yeah.
- 6:03Decorators are also another really good example, right?
- 6:05Like where the concepts for that syntax predates it.
- 6:09And it happened to just be something where Python core development team looked at where people
- 6:15were in terms of development and what they needed from Python and realized, you know what?
- 6:20That common pattern that people are doing would actually be would be very well served via
- 6:26a piece of syntax.
- 6:26So why don't we just do that?
- 6:28Why don't we introduce that piece of syntax?
- 6:29Make things happen.
- 6:30As you said, with context managers were a perfect example, right?
- 6:33Where before, if you wanted to do the right thing when you opened a file is you call the
- 6:40open function for your file, sign it to a variable, do your try block of everything you want to
- 6:44do with the file.
- 6:46And then in the finally part of the try finally close that file, which I mean, if you just think
- 6:51about it compared to a with statement is four lines, assuming you're doing reasonable formatting for
- 6:57the assignment, the try, the finally, then the close call versus the single with open to get the exact
- 7:03effect.
- 7:03And then you've also got the possibility that the context manager, the thing that's used in
- 7:08the with block can do something different if there's an exception, right?
- 7:12Like if there's an exception, it could say if it's a database transaction, it could roll back the
- 7:15transaction automatically.
- 7:17Rather, if there's no exception, it could commit it automatically.
- 7:19But there's no real magic there.
- 7:21If you think about it in the end, you could have written that all out by hand.
- 7:23It just would have been cumbersome.
- 7:25But that makes the with statement very much a piece of syntactic sugar where you could totally
- 7:29write it out, get the exact same semantic outcome.
- 7:31It might be a little slower.
- 7:33Probably similar performance as well.
- 7:35And maybe similar.
- 7:37It really depends on the syntax, right?
- 7:38Like how complicated it is, how much of it's going to call into, at least in CPython's
- 7:43case, into the C code and stay in the C code versus not.
- 7:46Like with context managers, probably won't just because the point is you're going to call
- 7:50that dunder enter method or that dunder exit method.
- 7:53So you're calling Python code.
- 7:54So no real, probably big shift.
- 7:56But for stuff that we'll probably cover in this podcast, there are other bits that go into
- 8:01the C code and stay in the C code.
- 8:03And when that happens, stuff can go really, really fast.
- 8:05Yeah, especially with all the work the faster CPython team's done around stuff and all that.
- 8:09So the point is you can just start to just kind of leap into C code, stay there and get
- 8:13stuff done way faster.
- 8:14Comparative to writing out by hand where you're staying in the Python world, it can just take
- 8:19a bit longer.
- 8:19Yeah.
- 8:19So the word sugar, I think it's a good one here.
- 8:23I love like these ideas like code smells, code sugar, all the things.
- 8:27It makes it sound a little frivolous, maybe like little, it's nice to have.
- 8:33It sweetens it up.
- 8:34You don't really need it.
- 8:34But I do think having these different constructs, like when you see a with block, it instantly
- 8:40conveys meaning.
- 8:41It means we're going to create a thing.
- 8:43We have a cleanup section.
- 8:44We don't have to deal with it.
- 8:45As opposed to if you see a try except finally, you have to read it and process it and see,
- 8:50okay, does it actually do the things that would be accomplished?
- 8:53I think these sugars let you also think, not just write less good, but think in different
- 8:59levels of abstraction.
- 9:00Yeah.
- 9:00I mean, as you said, the use of the word sugar is meant to mean something sweet, something
- 9:05nice.
- 9:05It's a treat.
- 9:06It's a bonus.
- 9:07So from the perspective of if you didn't have it, you could still accomplish it.
- 9:11But that can potentially, in a way, as you've suggested, not quite denote the benefit of it,
- 9:18right?
- 9:19Like if we think of sugar in terms of not something good for your diet.
- 9:22Yeah.
- 9:23What is your perspective on sugar, right?
- 9:25Are you a fan of desserts or are you trying to cut it out?
- 9:27Yeah.
- 9:27But yeah, I mean, the hope is whenever we add syntax to Python, it's for everyone's
- 9:32general benefit, right?
- 9:34This is why we don't do it very often.
- 9:35And when we do do it, it's a very thoughtful discussion, very long discussion, sometimes
- 9:40contentious discussion.
- 9:41Walrus operator is the famous one for that.
- 9:45I don't understand the contention in the Walrus operator.
- 9:47It's such a small change to the language.
- 9:50There's so many other things that are bigger changes that could have been battles.
- 9:53But I guess it just came to a head at that point or something, right?
- 9:56For those of you who don't know the Walrus operator is the thing that pushed Guido kind
- 10:00of over the edge to finally step down as being the bit of a dictator for life.
- 10:03And it was just due to the veracity of the opposition to it and just how basically angry
- 10:10it made people.
- 10:11And you're right.
- 10:13It's very small.
- 10:13And to be honest, I've used it and I like it.
- 10:16I get use out of it.
- 10:17It means it.
- 10:18I use it for its purpose, which was to add some basic syntax for those up those situations
- 10:23where you always have that assignment and then you do something like an if.
- 10:26for something and then you're going to do something like just be able to inline certain
- 10:30things to just do the right thing.
- 10:32It's not a huge thing, but it's a nice thing.
- 10:35And in that case, I don't know.
- 10:37Honestly, a lot of people got really concerned that they didn't see the usefulness enough that
- 10:43they thought it was going to be a slippery slope or people are always very concerned about
- 10:49Python getting too big and it's no longer fitting in their brain.
- 10:53Yeah.
- 10:53Maybe it was kind of the last straw sort of thing rather than like maybe stuff came before
- 10:57and they're like, all right, that's it.
- 10:58And now the walrus, the walrus, like, you know, I don't know.
- 11:02I don't know.
- 11:03I mean, I don't think people realize that we actually cut syntax out when we moved from Python
- 11:06two to Python three.
- 11:07Yeah.
- 11:08That was all kind of brewing.
- 11:09Yeah.
- 11:09Like the back ticks went away.
- 11:11Like no one knows about the back ticks anymore, but we used to have syntax for using back
- 11:14ticks and that's now that's gone now.
- 11:16So it's not like it's always been a add, add, add.
- 11:20But I think it's just one of these things where it's just people were very concerned that
- 11:23Python would get too big, too complicated, and it wouldn't be fully understandable.
- 11:26I will say whenever we do this, we very much consider how easy it would be to understand
- 11:32if you saw it for the first time and never received any instruction about it.
- 11:35Right.
- 11:35Like I would argue that walrus operator is a bit obvious if you look at the code around
- 11:39it of what it does.
- 11:41And so you can probably figure out what it does without being told ahead of time versus
- 11:45other syntax and other languages where you go, I have no clue what this does.
- 11:49Right.
- 11:49Exactly.
- 11:50Right.
- 11:50Like why does plus plus and C do different things if it's in the front or the back?
- 11:55And what's the difference?
- 11:56Like unless you know prefix versus suffix increment and the difference in terms of referencing the
- 12:02pointer and all this crazy stuff, like you're not going to necessarily pick up
- 12:05on the difference unless you run your code versus something where you can just look at
- 12:08it and just learn on the spot.
- 12:09Well, I want to give you all a bit of a compliment, I guess, or encouragement.
- 12:14I think the Python language is not changing too fast.
- 12:17I think it's the stability over time is really good.
- 12:21You compare that to other languages.
- 12:22I mean, here's one that's kind of close to home for you since you're at Microsoft, like
- 12:26C#.
- 12:27I feel like that language is pretty nice, at least in the early days.
- 12:30And now there's a whole team who are employed.
- 12:33You don't have to make any comment.
- 12:35I know you work there, but there's a whole team who's employed to shepherd that language.
- 12:41And I feel like there's a feeling they always need to have some new language features because
- 12:45it's their job to have language features.
- 12:47There's just like a constant kind of turn, like for properties, like we have properties,
- 12:51they have properties.
- 12:52But I think there's four to five different ways that properties in C# that have evolved
- 12:56over time.
- 12:57And you're just like, yeah, it's a little better, but it's why do we have so many ways if you're
- 13:01going to be there?
- 13:01Right.
- 13:01And so when I at least look at Python compared to like my background in C++ or in C#
- 13:08or JavaScript, I feel like it's comfortable.
- 13:11It's not stale, but it's not.
- 13:13We don't have five ways to do properties.
- 13:15That's a good thing.
- 13:17Even if there's a better way to do it, it might not be worth having two to three ways just
- 13:22for that for a slight advantage.
- 13:23Well, thank you for the kind words.
- 13:24Yeah.
- 13:25I mean, we do have the Zen of Python does kind of outline the general guidelines we try to
- 13:30follow when doing making these discussions decisions.
- 13:32For those who've never read the Zen of Python, look, just run, import this from the REPL and
- 13:37you'll find it.
- 13:38And yeah, it's just the way it's designed, right?
- 13:40We don't, hopefully there's one and hopefully only one obvious way to do anything.
- 13:46And so it's just something we've kind of leaned into now, granted things shift.
- 13:50Like I'm sure someone will point out the myriad of ways you can format a string now, but a
- 13:54lot of that's backwards compatibility and just realizing, you know what?
- 13:57We just have to accept the fact the first way we got it is no longer the best way we
- 14:02can think of.
- 14:02And it's enough of a jump from using string interpolation with the percent sign to using
- 14:07f-strings that it was worth adding a second way.
- 14:11Now, maybe someday we'll take out string interpolation.
- 14:14I doubt it because it just works and it's just sitting there and it's not worth breaking
- 14:18really old code.
- 14:19But I mean, it's just the way we approach things.
- 14:21And luckily, most people like it.
- 14:22And I think that's kind of why some people always freak out is the words afraid somehow
- 14:26we're going to go downhill from here and it's just the start of things or somehow Python
- 14:30is going to be harder to learn.
- 14:31Well, we very much try to make sure Python is a gradual curve of learning, right?
- 14:35The basics are very straightforward and good.
- 14:37And as you get into more advanced things like the match statement, right?
- 14:40You'll be able to see it and understand it.
- 14:42It'll make sense, but not something you'll necessarily learn the first month or two,
- 14:46but it's there for when you do need it, right?
- 14:48Like we very much try to make sure that everything makes sense on a curve from beginner to advanced
- 14:53and try to make sure the language is useful to everyone from both a beginner to advanced
- 14:57user.
- 14:57It's tricky, but I like to think we're doing a decent job.
- 15:00Yeah.
- 15:00One of Python's really, one of its powers is that you can be super effective with it with
- 15:05a really partial understanding of what it is, right?
- 15:08You don't have to understand namespaces, classes, async, et cetera, et cetera.
- 15:12You're just like, well, I think I can write these four lines in a, without even a function
- 15:15and I'll get a cool graph that'll show my, my work or whatever, right?
- 15:18Yep.
- 15:19Exactly.
- 15:19Yep.
- 15:20And I think I have a pretty partial understanding of the match statement.
- 15:22I know it can get pretty advanced in like how it captures and changes values, but I wrote
- 15:27one yesterday with a partial understanding.
- 15:29It went great.
- 15:29Nice.
- 15:30Yeah.
- 15:30Indeed.
- 15:31All right.
- 15:31Before we move on though, got to go back to the, the, your opening because you said,
- 15:37I created this to understand, like, if I were to solve that problem, your wife had about like,
- 15:43you got to fix that thing about the browser.
- 15:44And I know there's some folks in Texas who have thoughts on this as well in the PyScript
- 15:48team, but is this project you're actively working on or just, let me gather up, do some
- 15:55research and deep thinking about what is actually in the language that would have to carry
- 15:59over or where's it coming from?
- 16:01I guess.
- 16:01No, it's not an active project of mine at the moment.
- 16:04It ended up being mostly just an exercise and just snowballed into a thing where I just
- 16:10didn't want to stop until I completed it.
- 16:11Yeah.
- 16:12How do you feel about the micro Python, PyScript angle of approaching this?
- 16:18Yeah.
- 16:18I mean, I think it's great that, I mean, that was the other hopeful benefit about all of this
- 16:22is trying to nail down the definition of what Python is.
- 16:26Yeah.
- 16:27Cause I've heard those arguments made against micro Python that it's not quite Python cause
- 16:31it doesn't quite run all the syntax or it doesn't have the entire standard library.
- 16:35I've gotten into arguments with people online where they got very upset when I suggested that
- 16:41the REPL was an optional part of Python and actually not a requirement.
- 16:45And I just viewed it as a learning experience for me, hopefully a learning experience for
- 16:50others as well.
- 16:51And then after that was just trying to hopefully clarify and like, like, look, this is truly
- 16:55what you have to have to really be Python.
- 16:57You literally cannot implement the rest of the language without this, but everything else,
- 17:01you could totally just do it yourself.
- 17:02You could totally just write your tool and make it all work.
- 17:05And as long as this existed, you could totally get it by with it.
- 17:08And so that's kind of where I ended up.
- 17:10I luckily the tooling around WebAssembly got far enough along.
- 17:14Pyodide's continued to do well in the browser.
- 17:16I've been working on the WebAssembly, the system interface, WASI side of things, and that's
- 17:21been going pretty well.
- 17:22So that's at least taken care of itself.
- 17:25So I've ultimately not tackled the huge problem of trying to reimplement Python from scratch,
- 17:31probably in Rust, just in a minimal fashion to try to make it work better in the browser.
- 17:36That's probably a project for when I retire.
- 17:38And I suspect that's at least a decade out, if not more.
- 17:42So that's probably going to be put on the back burner for a while.
- 17:44Right.
- 17:45Yeah.
- 17:45We could all install Bpython and run Brett Python built in Rust.
- 17:49There you go.
- 17:49Rust does seem to be having quite the influence.
- 17:55an outsized influence for how popular Rust is in terms of the number of developers, but
- 18:00it seems to be really leaving its mark on Python and other areas as well these days.
- 18:05Yeah.
- 18:05Well, I mean, I will fully admit I have bias because I am a fan and I do like using the
- 18:11language, but it's one of those things where if you've been living in the C and C++ world
- 18:15and it never was that satisfying to you, but you had to be there for whatever reason.
- 18:18And then you discover Rust and it does things that saves you from very chronic problems.
- 18:24Yeah.
- 18:25Including yourself.
- 18:25Yeah.
- 18:26You would hope that you, people would notice and latch onto it.
- 18:29And I mean, that's, I think that's basically what's happened is people have just discovered
- 18:32that, oh yeah, this is useful and good.
- 18:35And just there's enough C and C++ code in the Python community due to CPython C API that
- 18:41I think there's just a nice cross section, right?
- 18:44I think it's just one of these things where people have just gone like, well, I've got to
- 18:47be, I got to do the system level programming anyway.
- 18:49So I might as well use something that's seems like a better, a little more modern language.
- 18:53Yeah.
- 18:53Yeah.
- 18:53Yeah.
- 18:54A bit more modern.
- 18:54And so I think that's kind of what's happened here.
- 18:56Yeah.
- 18:57That makes sense.
- 18:57All right.
- 18:58Let's talk about the sugar.
- 18:59Okay.
- 18:59So I think we covered pretty much what syntactic sugar is.
- 19:02And you started this whole thing out saying the goal of this is really to kind of nail
- 19:07down that minimum Python.
- 19:09And I agree that the REPL is optional.
- 19:11I like the REPL, but just, just so I can also get mail about it.
- 19:16I like the language.
- 19:17Like you can't take away these features once you add them.
- 19:21Right.
- 19:21And so it's like, what could you survive with as a minimum?
- 19:25And then you can kind of like, what are the, what's the extras?
- 19:28What could you build up from there?
- 19:29Yes, exactly.
- 19:30And the final destination maybe being, you know, CPython proper.
- 19:34Yeah.
- 19:35So you've got a whole bunch of different aspects of Python that you are unraveling in
- 19:41this syntactic sugar.
- 19:42And basically to highlight what's actually happening, how much of this is going on as you've already
- 19:47laid out.
- 19:48So I want to point out that I'll link to how many articles you've got here, but two years.
- 19:5320, I think.
- 19:55Yeah.
- 19:55Like looking like close to 30, maybe.
- 19:57I don't know.
- 19:58Just eyeball it.
- 19:59There's a lot there.
- 19:59So I think I picked a, you know, half of those out or some, some reasonable subset.
- 20:05That we can talk about.
- 20:06And there's some code and stuff in here.
- 20:08So we'll kind of have like, my thought was we could just talk about kind of like, what is
- 20:12the essence of this?
- 20:13Like what's really happening when you do attribute access?
- 20:16What's really happening when you write the word pass or use a width block as we've talked
- 20:21about a little bit.
- 20:22So the first one here is unraveling attribute access in Python.
- 20:26You want to tell us a bit about what actually happens if you just say, you know, like object
- 20:31dot attribute.
- 20:32It seems so simple, Brett.
- 20:33There's just one dot.
- 20:35That's the big deal.
- 20:36Yeah.
- 20:36Why doesn't this just, what's there to talk about?
- 20:38I mean, when I just do something dot something magically, I get back what I expected, but there's
- 20:44actually a lot going on there.
- 20:46Right.
- 20:46And it, it comes down to multiple layers, but it's all ties around Python's object model.
- 20:51Right.
- 20:51How do all, because I always find this weird to say, but Python's more object oriented in
- 20:57my opinion than Java.
- 20:58Java has these primitive types like instant quotes that have to get boxed and unboxed to
- 21:03fake, to make them look like an object to Java itself.
- 21:06Python doesn't have that.
- 21:07Everything is an object.
- 21:08A function is an object.
- 21:09An integer is an object.
- 21:11True is an object.
- 21:12Seven is an object.
- 21:13Exactly.
- 21:14There's nothing you can name in Python.
- 21:16That's not somehow an object.
- 21:17Yep.
- 21:17This idea of attributes and all this permeates all the way down into the object model, which
- 21:22once again, defines kind of everything in a way.
- 21:24So the key thing here is there's kind of two parts to it.
- 21:27It's how do you look up based on inheritance, what thing is going to service the call asking
- 21:34what is this attribute value?
- 21:36Basically, what object is bound to this name for the attribute?
- 21:39And after that is what methods are going to get called to make that happen?
- 21:43Because effectively, almost everything in Python at the end of the day leads to a method call
- 21:48or a function call.
- 21:49Yeah.
- 21:49First of all, it leads to a lot of times to an op code, which leads to a method call, right?
- 21:54A Python bytecode thing.
- 21:57And I think it's maybe also worth pointing out, like have you point out to everyone listening
- 22:01is Python compiles to this intermediate language like Java and .NET compiled to intermediate languages.
- 22:08It's just what happens then, right?
- 22:11Like in those other ones, they JIT compiled to machine instructions.
- 22:13Here it goes through like the big C eval loop and delegates to some internal C operations.
- 22:19And a lot of those, these unravelings, like kind of look at what happens at that step, right?
- 22:23Yeah.
- 22:23So CPython itself is an interpreter, right?
- 22:27So what happens is when you load up your Python code is Python parses it, what's called an abstract
- 22:33syntax tree or AST.
- 22:34It then takes that AST, does some stuff with it, and then it compiles it down to Python bytecode.
- 22:41I actually gave a talk on this at PyCon Canada way back when, for those who are interested,
- 22:46that basically goes from the steps of literally source code all the way to execution, if you
- 22:51want more detail.
- 22:52But effectively, yeah, we compile it down to bytecode of our own design to then execute
- 22:57in more or less what's a big for loop in C.
- 23:01That is a really big for loop.
- 23:03Very big for loop.
- 23:03And it's gotten a bit fancier thanks to the faster CPython team, right?
- 23:08Like there's now kind of like lower level opcodes that are very type specific.
- 23:12And we actually auto-generate the loop now thanks to them so that it's easier to maintain and
- 23:18make tweaks to.
- 23:18But essentially, it's literally just a set of instructions that are extreme, that kind of
- 23:23encompass key bits of semantics in Python.
- 23:27So for instance, for attribute access, there's literally a opcode called load adder, where on
- 23:34the execution stack, you basically push the object you care about, the name of the thing you
- 23:38want, and then you just call load adder on it, and it'll just look it up.
- 23:42Actually, technically, I guess it doesn't push the name on it.
- 23:44That's technically stored in the function.
- 23:47There's little details I'm kind of hand-waving over, literally hand-waving if you're watching
- 23:51the live stream.
- 23:52But effectively, you push the object you want, you call load adder, give it an argument of
- 23:57what it should, what attribute it wants, and then load adder opcode behind the scenes is
- 24:01the thing that does all the magic of calling everything you'd expect, et cetera, et cetera.
- 24:04Yeah, excellent.
- 24:05And to view that, a lot of times what you'll do is you'll just use the dis module.
- 24:10So if people haven't used dis, you can just dis.dis, a lot of disrespect on this function,
- 24:15and then it tells you what the opcodes it's made of are, yeah?
- 24:19Yeah, exactly.
- 24:19I mean, dis is short for disassemble.
- 24:21So literally, you can pass it a function, and it will effectively disassemble what the
- 24:26function does into the bytecode, which is just stored as an attribute of bytes on the
- 24:32function object and print it out nicely because the disk module knows how to map the bytes
- 24:37to what the opcode's name is and just gives it a nice way to look and actually read and
- 24:42understand it.
- 24:43Okay.
- 24:43In this example, you said, all right, look, here is the case statement in that tremendous
- 24:47for loop switch thing that does the execution.
- 24:51What do we do if we see load adder?
- 24:53And ultimately, it comes down to this pyobject underscore git adder.
- 24:58So it seems so simple.
- 25:00It's just object dot attribute, object dot field, whatever.
- 25:02But it turns out there's just so many variations and so much going on down here.
- 25:07And I don't necessarily want you to go through all the details because it's pretty, some of
- 25:11it's pretty intense C and like a lot of it, you know, optimizations and stuff.
- 25:15But just give people a sense of what actually happens down in the guts when you try to do it.
- 25:21Well, so in the case of attribute access, right, that effectively ends up calling the
- 25:27git adder built-in function, right?
- 25:29And in that case, it needs to check how many arguments it gets to start, right?
- 25:34Did you give it two arguments or did you give it three arguments so you return a default value
- 25:38if the attribute doesn't exist?
- 25:40And then at the C level, we have to check whether or not what you gave it, right?
- 25:44Because there's like a Python level, the C code all types to what's called the to py object,
- 25:50which is basically a massive struct in the C that represents any and all Python objects.
- 25:55So even at the C level, we don't know if you gave us a string or an integer or what did you
- 26:02give us for the name of the attribute that you want.
- 26:05So we got to do that, right?
- 26:07And so there's just basic, like just safety checks to go like, nope.
- 26:12Like when you, if you call git adder with wanting the attribute 42, which is a number,
- 26:17it's going to throw a type error.
- 26:19Well, that code's got to exist somewhere and this is where it exists.
- 26:22Yeah.
- 26:23Yeah.
- 26:23Right.
- 26:24And then effectively just bubbles all down to the C API where a lot of this stuff gets exposed
- 26:28in its own way.
- 26:29And specifically in this case, it ends up calling py object git adder.
- 26:33Yeah.
- 26:33And I think another thing that's pretty interesting here is it's not always just a value, right?
- 26:38That object dot adder, that adder could be a property.
- 26:41That adder could be a descriptor, which I guess is a generalization of a property.
- 26:45It could be on the class type, but not on the instance type.
- 26:49So you got to find that.
- 26:50It could be on the instant type overriding, but only there, right?
- 26:52Like it could not exist.
- 26:54All of these scenarios that you got to go through.
- 26:57And so it really, you know, it really emphasizes how much is actually going on in the runtime while
- 27:02this single simple line seems to be running, right?
- 27:05Yeah.
- 27:06I mean, in the simple case, hitting the dots, not complicated.
- 27:10Like in general, what you end up doing is you have your object, you hit dot.
- 27:15And what it does is it looks in the dunder decked attribute of the object.
- 27:19And there's a key matching the attribute name.
- 27:21And it just gets the thing in the dictionary and that's it.
- 27:23You're done.
- 27:24But as you alluded to, how the heck do you even get to that basic case?
- 27:28Or those more complicated cases, as you said, descriptors, right?
- 27:32Which are how we actually implement properties.
- 27:34Or if it's on the class versus the instance.
- 27:38And what happens if there's inheritance or multiple inheritance?
- 27:43Yeah.
- 27:44Or dunder git adder was defined, right?
- 27:45Like basically almost all of this ends up flowing through the git adder built in, which effectively
- 27:51ends up calling the appropriate dunder get attribute method off of an object.
- 27:55And this is one of those bare level kind of things, right?
- 27:58Where you have to implement this to make Python work.
- 28:01You have to basically implement the git adder built in.
- 28:03And it has to understand how objects are structured underneath the hood to know how basically methods
- 28:09and stuff are attached to an object.
- 28:10You really can't fake that.
- 28:12There's no way to not kind of have that as a low level detail that you can just unravel.
- 28:17It has to be implemented by the interpreter.
- 28:19And in this case, effectively, the way Python does things is it knows the order.
- 28:24You can always actually call the MRO method on any object in order to use the method resolution
- 28:29order.
- 28:29And effectively what Python is doing is if it checks on something to see if it has it or not,
- 28:35it will effectively end up calling the dunder get attribute object of method, sorry, on
- 28:40object.
- 28:41That's usually where it bottoms out.
- 28:42And unless you happen to have a dunder git adder, if that fails, but that's only in the
- 28:47failure case.
- 28:47But really, in the end, almost everything passes through object dot dunder get attribute.
- 28:52And that's really where all this ends up going.
- 28:54But as you said, there's a lot of little twists and turns.
- 28:56Yeah, a lot of these internals, you'll see the method resolution order calls.
- 29:01And it's all about, well, there's a lot of classes and a lot of objects.
- 29:05They can override things and they can override operators.
- 29:08And so there's a lot of navigation to just figure it out.
- 29:11Not just calling these git adder type of things, but what level does that even supposed to happen
- 29:17on, given what I'm working with, right?
- 29:20Yeah, exactly.
- 29:21And I think this is a good example.
- 29:23And the reason I started with this is so fundamental, right?
- 29:26Like, how do you unravel something if you don't know how to even get an attribute off of something?
- 29:31So this is why this was the very first post in this series.
- 29:33Partly why I went into such detail on how to figure all this out, right?
- 29:37Like, kind of one, this is almost a template for anyone else who wanted to go exploring on their own.
- 29:41But I think it's also a good example of how much complexity and flexibility Python hides from users in order to make the simple work, but give you the flexibility to make the complicated possible.
- 29:53Right.
- 29:53Yeah.
- 29:54Like for the vast majority of any of us for our code, it's not just does what you would think it would do.
- 30:00And it's pretty straightforward.
- 30:01But as soon as you get into the fancy world of descriptors.
- 30:04SQLAlchemy.
- 30:06Yeah.
- 30:07I can both have a value or I can do a database query with the same thing.
- 30:10How is that possible?
- 30:11Right.
- 30:11Yeah.
- 30:12You want that magic?
- 30:13Language has to support it somehow.
- 30:14And it requires a lot of finesse and thinking through and a lot of mechanisms that generally get hidden from you.
- 30:22But someone's got to write that code somewhere.
- 30:24And in this case, it's a Python.
- 30:26And this kind of outlines how that all happens.
- 30:30And it's surprisingly complicated.
- 30:32It's not horrible.
- 30:33That was my main takeaway, too.
- 30:35Yeah.
- 30:36I mean, you can totally read it and follow it.
- 30:37I don't want to scare anyone saying it's so complex you can't follow it.
- 30:40It's just it's not just a simple two if statements and you're done.
- 30:45It's no.
- 30:46There's subtlety to it to make sure the common semantics make sense to people.
- 30:51It's not going to trip people up because it's doing something weird.
- 30:54There's a lot of thought that goes into these semantics to make sure it makes sense for the common case.
- 30:59This portion of Talk Python To Me is brought to you by us.
- 31:03Have you heard that Python is not good for concurrent programming problems?
- 31:08Whoever told you that is living in the past because it's prime time for Python's asynchronous features.
- 31:13With the widespread adoption of async methods and the async and await keywords,
- 31:18Python's ecosystem has a ton of new and exciting frameworks based on async and await.
- 31:23That's why we created a course for anyone who wants to learn all of Python's async capabilities,
- 31:28async techniques and examples in Python.
- 31:31Just visit talkpython.fm/async and watch the intro video to see if this course is for you.
- 31:36It's only $49 and you own it forever.
- 31:39No subscriptions.
- 31:40And there are discounts for teams as well.
- 31:45Another takeaway I got from looking at this is, wow, it's nice that dictionaries are fast.
- 31:49And how fast are they to make this impossible to lean on them so much to make this happen?
- 31:54Yeah.
- 31:54I mean, I will say when Guido chose to use dictionaries as the namespace, it was kind of a unique decision at the time.
- 32:01It might still be, honestly.
- 32:03But it did simplify some things conceptually and also made it so that any wins in how dictionaries work is just a massive win universally across language.
- 32:14Right.
- 32:15Like if you make dictionaries work in any way better, you not only make it work when you just you personally use it as a data structure, as a container,
- 32:24but also literally every attribute access will get faster.
- 32:27Right.
- 32:28Like, yeah, there's a reason why it's so fine tuned and why we don't really touch it very much because it's been tweaked over the decades by a lot of people to be extremely fast and for good reason.
- 32:40Yep.
- 32:40Indeed.
- 32:41One final thought on this.
- 32:42You know, you think of optimizing both the memory and also the performance a little bit by doing things like slots on your classes to maybe like short circuit some of this.
- 32:51It feels like somewhere in this world lives like some kind of massive optimization that maybe that if you said I'm going to for this class, I'm going to give up some flexibility.
- 33:00Is there some way attribute reads and writes could get lots faster?
- 33:04I don't know.
- 33:05What are you?
- 33:05I'm sure this has gone round and round because it's such a hot.
- 33:09It's just involved in almost every line of Python code, stuff like this.
- 33:12Right.
- 33:13Oh, yeah.
- 33:13Yeah.
- 33:13I mean, this plays into what the faster CPython team has been doing, right?
- 33:18Trying to make things faster by looking at what the patterns are and if you can just kind of skip stuff.
- 33:24Right.
- 33:25Like, how do you short circuit this thing?
- 33:26Can you go like, well, I just know this object's always looked this way.
- 33:29Like, this is some of the stuff that the self programming language team at UC Santa Barbara did, I think, in the 70s, maybe 80s.
- 33:38I'm just like, well, if we know the layout of the object is going to be consistent.
- 33:42Yeah. Can we go seven bytes in and get four bytes?
- 33:44That kind of thing, right?
- 33:45Exactly.
- 33:46And you just kind of have to, and you start to be able to calculate the shortcuts.
- 33:51You know, like, hey, did anything change from the last time I made this assumption?
- 33:54No? Okay.
- 33:55Well, then I can use my assumption.
- 33:56That's way fast.
- 33:57Right.
- 33:57Nobody's mocked it.
- 33:59Nobody's dynamically messed with it.
- 34:01Like, maybe it is just a plain thing.
- 34:03Until somebody puts it into an edge case, is there a short circuit, right?
- 34:07Yeah.
- 34:08And, I mean, I don't want to go off on a tangent, but...
- 34:12Well, I'm one of 17 topics here, Brett.
- 34:14Like, I know probably we got lots of time.
- 34:15I have thought about, like, after doing this, what...
- 34:20Is there something syntactic here to add, right?
- 34:22Is there a way to kind of come up with effectively a class definition that's way simpler for the really common cases?
- 34:31Yeah.
- 34:31That could be optimized extremely fast because you give away some flexibility and then the interpreter can make assumptions.
- 34:41PyPy could make assumptions, et cetera, et cetera.
- 34:44And would there be enough wins on that to warrant doing it, right?
- 34:48Like, could we take the concept of kind of a data class that was just data, roughly, or something along those lines?
- 34:55Yeah.
- 34:55And just what could we get out of it?
- 34:57And what kind of perf wins could we get out of it?
- 34:59And would it be worth it?
- 35:00Would it be worth adding syntax to the language for that case?
- 35:04If you look at Mojo, for instance, they have a struct.
- 35:07And that struct works in a very specific way for performance because when you say, like, this thing can't have new attributes, which you can do with slots.
- 35:15And for those of you who don't know what slots are, if you define a dunder slots attribute on your class, you're effectively telling Python, don't create a dictionary for me.
- 35:23Just create effectively a list underneath.
- 35:25It's technically a C array.
- 35:27And when I need to access something, just get it off this array.
- 35:31So there's no dictionary.
- 35:32You can skip all that dictionary overhead.
- 35:34Plus, you shrink the memory because now the only amount of memory you need is that array for pointers to the PyObjects and not a dictionary, which grows and shrinks and who knows what size it's going to be.
- 35:44If we had that built in syntactically, would that be beneficial to people or not?
- 35:49And I have a prototype in Python code of what I'm thinking of.
- 35:53I did a blog post on this earlier this year to try to feel out people in the community and what they thought in terms of restrictions and would it be too much or too little?
- 36:02I subsequently prototyped what I wanted.
- 36:04And there'll be a follow-up blog post about this is where it sits now.
- 36:08What do people think?
- 36:09And do people think this is worth trying to get syntax for?
- 36:12Just don't worry about it.
- 36:13It's too close to data classes or what?
- 36:16Maybe it could be a keyword to the data class decorator that just makes it behave differently.
- 36:21Who knows?
- 36:22Yeah.
- 36:22But so unfortunately, the tricky bit with that is it's still flowing through Python code, right?
- 36:26Data classes is still just a module in the standard library.
- 36:28So you can't, it's really hard to optimize that stuff without syntax to specifically say, hey, this will be different.
- 36:35You get to treat it differently and we can literally lock it down by literally creating a different type of object at the C level that just literally doesn't give you access, right?
- 36:43Like tuples are a good example.
- 36:45Tuples at the C level very much just don't implement the stuff that you mutated.
- 36:50What happens if we want to do that for classes?
- 36:51Like how do you do frozen data classes?
- 36:53It's a ton of properties.
- 36:55But what happens if we had a way to just say, yep, nope, we're just literally not giving you access.
- 36:59Would that, how much faster could that be?
- 37:01I don't know.
- 37:02But I suspect it would be decently faster.
- 37:04Yeah.
- 37:05Computers are surprisingly fast.
- 37:07Dictionaries are surprisingly fast.
- 37:08But there's a lot of stuff here that could be skipped that I think might be.
- 37:13To me, I had the same thought at least.
- 37:15Probably not with the level of sophistication you did.
- 37:17But like, wow, there's some way to sort of do a more of a C style, just like we know the structure and the offsets.
- 37:23Yeah.
- 37:24Like for a restricted set, because that restricted set is mostly what people do actually do in Python.
- 37:28They don't go crazy dynamic with stuff coming and going like sometimes, but not usually.
- 37:33Yeah.
- 37:34I mean, you can go read my original blog posts.
- 37:36And if you follow me on Mastodon, you can see the follow up conversations.
- 37:39But like the original thing, if you've been a longtime Java user, you'll know the acronym POJO, plain old Java object.
- 37:47It was effectively the equivalent for Python.
- 37:49Some people love that idea.
- 37:51Some people were like, I really need methods.
- 37:53I can't not have methods kind of thing.
- 37:56It really depends on what people are after and what they think makes sense.
- 38:01But there will be a follow up blog post.
- 38:03So if you follow my blog, you'll eventually see what this hopefully all leads to, which may be nowhere beyond what I put up on PyPI.
- 38:08But who knows?
- 38:09Maybe it'll become Zindax someday.
- 38:11It really depends on how the community reacts to it.
- 38:14Cool.
- 38:14Well, I didn't know you're looking into that.
- 38:17So very interesting.
- 38:17Next one.
- 38:18Let's move on to something that also seems pretty straightforward is A minus B.
- 38:25Yeah, right.
- 38:26Yeah, exactly.
- 38:27You think it makes.
- 38:28Yeah.
- 38:28How hard can A minus B be, right?
- 38:30Like two objects just subtracting from one another, right?
- 38:35We all know how this works.
- 38:36There's I mean, there's an opcode just called binary subtract.
- 38:39Just like there's a binary add, a binary multiply, binary divide.
- 38:42You put the numbers on the register.
- 38:44You do the instruction set on the CPU and you're good to go.
- 38:47Yeah.
- 38:48Hey, I know what five minus three is.
- 38:50How much work can it be to make that work in Python?
- 38:51Oh, yeah.
- 38:52The numbers happen to be arbitrarily large and sometimes they're not numbers.
- 38:57Sometimes they're matrices or strings or.
- 38:59Oh, boy.
- 38:59Okay.
- 39:00Exactly.
- 39:00And subtraction is not communicative.
- 39:02So what matters here.
- 39:04So, yeah, it gets surprisingly complicated very quickly.
- 39:07Yeah.
- 39:07So, yeah.
- 39:08From from a conceptual level.
- 39:09Yeah, it seems simple.
- 39:10But when you figure out what that opcode actually does, it becomes way fancier.
- 39:14Yeah.
- 39:15And so as you dig into this, you start to realize like, OK, so this is actually controlled
- 39:20by the Dunder sub operator on the type.
- 39:23Right.
- 39:24And then how do you get that method?
- 39:25Well, this is the method resolution order on that type.
- 39:29So you got to start navigating that.
- 39:30And that gets pretty interesting.
- 39:32Right.
- 39:32Yeah.
- 39:33Yeah.
- 39:33Well, and let's be clear here.
- 39:35You're a bit foreshadowing because you said, oh, you called the Dunder sub.
- 39:38Yeah.
- 39:39To start.
- 39:40If that works.
- 39:41Right.
- 39:42Like for a lot of these things, there's lots of fallback to once again, give you that
- 39:46flexibility to make things work as necessary.
- 39:49So for a lot of things in Python, you can return the not implemented singleton, which you may
- 39:55have some people may have noticed and wonder what the hell is this thing for?
- 39:57And it's a singleton to signal to Python that, hey, there's not it's not an error happened.
- 40:03It's just I just don't know how to handle this.
- 40:05Right.
- 40:06So for instance, if let's say you have left hand side minus right hand side, the first
- 40:12step is you check to see if the left hand side has a Dunder sub method.
- 40:17If it does, you can call that with left hand side dot Dunder sub and pass in right hand side.
- 40:23Well, that method has the option to do something and return a value.
- 40:28And that's what left hand side minus right hand side becomes.
- 40:30Or it can return not implemented and say, just tell Python, nope, I don't know how to do this.
- 40:35Probably should ask someone else.
- 40:36Right.
- 40:36And then this adds an extra little wrinkle now, because suddenly when you do that, that
- 40:42says, OK, well, you know what?
- 40:43Let's give the right hand side a try.
- 40:45Maybe the right hand side knows how to do left hand side minus right hand side.
- 40:48It might not be the front thing, but it might just magically know.
- 40:51Right.
- 40:52So in this case, for instance, you could have something of your fancy object minus four,
- 40:57which would be your Dunder sub method.
- 41:00And so you know how to handle integers and it works.
- 41:02What happens if it's four minus your object?
- 41:05Yeah.
- 41:06Four doesn't know what to do.
- 41:07Yeah.
- 41:07Four's never seen your thing before.
- 41:09I don't know what the heck to do here.
- 41:10So in that case, four would return not implemented thing.
- 41:14I don't know what to do here.
- 41:15Good luck to you.
- 41:16Maybe you'll figure it out.
- 41:17And in this case, your object Dunder, our sub would get called with four.
- 41:22And then maybe you'll be able to say like, hey, I might not be on the left hand side,
- 41:25but I know how to handle myself on the right hand side.
- 41:27And I can make this work.
- 41:28So we try to make sure that even if some other objects don't know how to work with you,
- 41:33as if you're involved, there's at least the opportunity for you to make it work.
- 41:36Yeah.
- 41:36That's pretty interesting.
- 41:37Yes.
- 41:38An example could be like the number four, a constant minus a vector that's meant to be
- 41:43like a mathematical vector.
- 41:45And it's like, okay, we just subtract that from every dimension.
- 41:47Right.
- 41:47And that would be totally reasonable.
- 41:49But the four has no idea how to do that.
- 41:51Yes.
- 41:51And this is still the simple case.
- 41:52Yeah.
- 41:53So if I'll need a, I need a slight refresher on this one, but effectively there's scenarios
- 42:02here where you call the right hand side first.
- 42:07If it's the left hand side, one can say, I don't know what to do with this object, I think
- 42:12in return and not implemented from the subtract, something like that.
- 42:16Right.
- 42:16There's also a subtle optimization in these binary operators where if it is a direct subclass
- 42:24of the other object, you get first dibs.
- 42:28Oh, right, right, right.
- 42:29So that's the thing.
- 42:30Yeah.
- 42:30There's a lot of spam and bacon and vegetable spam and stuff that you did in here that people
- 42:36can check out.
- 42:36It gets surprisingly complicated.
- 42:37But the thing here, basically, this is, let's see, you have a left hand side and a right hand
- 42:42side, right?
- 42:42Once again, left hand side minus right hand side.
- 42:45Left hand side might be an integer.
- 42:46Your right hand side, though, might be a subclass of integer, like fancy integer.
- 42:51Okay.
- 42:51Now, if you do int minus fancy int, it will understand how to do it because you're a subclass.
- 42:57So it's just going to do it.
- 42:59And it'll just do the math and return you whatever it is.
- 43:01So like if you did five minus fancy three, five is going to return the integer two.
- 43:07But maybe that's not what you want with your fancy int.
- 43:09Maybe you would always, maybe you'd rather get fancy int two.
- 43:12So how does Python make sure that you get that opportunity if you happen to be on the right
- 43:16hand side instead of the left hand side?
- 43:17Yeah.
- 43:17Well, in that case, Python checks first.
- 43:20Okay.
- 43:21I have a left hand side and a right hand side for subtraction.
- 43:24Is the right hand side a direct subclass of the left hand side?
- 43:28If that's true, then you know what?
- 43:29I'm going to give the right hand side a chance first so that they can return their subclass
- 43:34and not have the left hand side kind of just blindly not realize that it's a different type
- 43:39and return something else.
- 43:40So that when it's, as I said, five minus fancy three, we actually give fancy three the first
- 43:45chance instead of five so that you have the chance to return fancy two like you wanted and
- 43:50not have five self-return.
- 43:52Boring two.
- 43:53Yeah.
- 43:53So I think one example that comes to mind that I think might be relevant would be working with
- 43:59units.
- 44:00So we've got cool libraries like pint and others where you can say this is not just the
- 44:06number five, but this is five kilograms.
- 44:09And if I subtract, you know, a hundred milligrams from it, it's not negative 95.
- 44:14It's, you know, four point, whatever, nine, five or whatever it turns out to be.
- 44:18And so in this case, if you took a regular number and one of these numbers with units, you
- 44:23could get a number with units back potentially.
- 44:25Yeah.
- 44:26No, that's a very good example, right?
- 44:27Yeah.
- 44:28This is where those, once again, very simple syntax that in the common case and in your
- 44:33general use day to day makes total sense and happens has some really important, but subtle,
- 44:38if you don't know about them semantics to make sure that those reasonable expectations are met,
- 44:44right?
- 44:44Like I totally didn't even think about this when I was doing, when I was writing this blog
- 44:48post that like, oh yeah, God, that's a good point.
- 44:51Like I do want to make sure that I get my special version of everything when I happen to be on the
- 44:56right-hand side, just because I happen to be written on the right-hand side.
- 44:59Yeah.
- 44:59Plus is a really good example.
- 45:01This one, right?
- 45:01Like you could have written a plus B or B plus a makes zero difference.
- 45:05I mean, that operator is supposed to be communicative.
- 45:07So it can be totally just dumb luck based on how I just happened to be thinking that day,
- 45:11what I put on the left side and what I put on the right side.
- 45:14And that would suddenly make a difference.
- 45:15And in this case, it just helps make sure that what you would think is the priority order of who you'd
- 45:21want to handle this for you gets that priority.
- 45:23But once again, it's a thing you just never think about day to day.
- 45:27But in actuality, when you think about the really key ways that Python operates, makes a surprising
- 45:32difference.
- 45:33Yeah.
- 45:33That seemingly leakiness of the language of like, well, sometimes it gives you an answer.
- 45:37Some it doesn't.
- 45:38Depends on how you add.
- 45:39People wouldn't love that.
- 45:40Yeah.
- 45:40And then the last bit of subtlety on that one is this only happens if, by the way, Dunder
- 45:47Sub and Dunder R Sub are different.
- 45:48So that's another check we do because at the C level, they're actually equivalent.
- 45:53Like there is no left side versus right side thing here.
- 45:56So we actually check to make sure we don't waste our time asking you, hey, can you do this
- 46:00and get back not implemented and then calling it the reverse and give me the exact same result
- 46:05because underneath it all is the exact same method.
- 46:07Right.
- 46:07So it's one of those fun things of, once again, lots of little things here to try to optimize,
- 46:11as you said, as best we can.
- 46:13And in this case, it's one of those.
- 46:15Well, if we know you're not going to work this way with the exact same method, we just swap
- 46:18the order of this stuff.
- 46:19Why are we going to ask you again?
- 46:20So we just skip that.
- 46:22So it's a minor thing, but semantics are there to try to help with the performance.
- 46:26I think people, as people go through your series here, I think they're going to get a deep
- 46:31appreciation for edge cases.
- 46:33Yeah.
- 46:33Subtlety.
- 46:34Yeah.
- 46:34Yeah.
- 46:35I learned a lot.
- 46:37I mean, it was one of the reasons I finished it is I finished this series as well, even though
- 46:41I part way through went like, yeah, you know what?
- 46:44I'm not going to implement Python from scratch, but I was learning.
- 46:48And it was fun.
- 46:50Like I got to dive a bit deep.
- 46:52I got to ask the Python core team is like from people, primarily Guido, who obviously
- 46:56were there when these decisions were like, why this way?
- 46:59Like, why do we choose this?
- 47:02And just trying to understand somewhat historically, how did these things happen?
- 47:06Right?
- 47:07Like I think a lot of people don't realize how old Python is, right?
- 47:11Like February of 1991 is when Python came out.
- 47:14It predates Linux going public.
- 47:16Like people really forget that fact.
- 47:18It's been around for over 32 years.
- 47:20Yeah.
- 47:21Decisions were made a long time ago.
- 47:23And I know everyone got all upset over the two to three transition.
- 47:26And some people still got upset whenever we push new changes or whatever.
- 47:29But do realize.
- 47:30Yeah.
- 47:31I can't believe you just canceled three, seven.
- 47:32I like that version.
- 47:35But the key thing here is the core concepts still work.
- 47:39Subtraction still works, right?
- 47:41From the way it worked back then.
- 47:43There's not been a massive upheaval here.
- 47:45It's just a lot of us end up using stuff that's kind of fancy.
- 47:48And sometimes the fancy stuff gets a little tweaked and stuff.
- 47:51But the really core low level stuff really hasn't shifted very much.
- 47:54So if at all, depending on your view.
- 47:57Give people a sense of the timing.
- 47:58Like the release of Python predates by a couple of years, the release of the web.
- 48:02Right?
- 48:02The web was 93, I think.
- 48:03And so, yeah.
- 48:05Yeah.
- 48:05One of the early browsers was actually Guido was writing in Python and TK.
- 48:09Incredible.
- 48:10Gradle.
- 48:10So we talked about simple things like thing dot value A minus B.
- 48:15The next simple one is the import statement because imports are simple.
- 48:18Honestly, I think imports are, if you come from a compiled language,
- 48:23they're really, you've really got to change your mindset.
- 48:26Right?
- 48:27And so I think this one actually is maybe the opposite end of that spectrum a little.
- 48:30Oh, yes.
- 48:31I will fully out my code.
- 48:32Some of my coworkers who are, because VS Code is written in TypeScript as an electron
- 48:37app.
- 48:38So they live in TypeScript all day long.
- 48:41The fact that Python's imports work the way they are in terms of flexibility and just the
- 48:45way it works.
- 48:46And you're not just specifying file paths to everything just really throws them for a loop
- 48:50and they go like, why is it so complicated?
- 48:52Once again, the flexibility that Python gives you where the base case, normal case of if you
- 48:57just do things the way just kind of just it's Python code and directory kind of thing just
- 49:02works versus I can also import something from a URL if I want.
- 49:06That's totally optional.
- 49:08You know, I could keep all my code in a SQLite database and import from there.
- 49:12Totally possible.
- 49:13Right?
- 49:14So it's one of these things, once again, where if you're coming from a Python mindset
- 49:18of just what makes sense, it all just works.
- 49:21I realize when you come in with an outside perspective, it can look kind of crazy.
- 49:25But you also have to understand that a lot of the designs were made A, decades ago.
- 49:30And B, there's a lot of flexibility there that you may or may not be taken advantage of.
- 49:34But there are others who are.
- 49:36And so that's kind of why it exists that way.
- 49:38Yeah, indeed.
- 49:38And yes, this posts.
- 49:40Yeah.
- 49:41So for those of you who don't know, I actually am responsible for Import Lib and re-implementing
- 49:47Python's import system in Python itself.
- 49:49And so I know these details a little too well.
- 49:51This one you live deep in this world.
- 49:53Yeah.
- 49:54So.
- 49:55You still have nightmares about some of them?
- 49:56No, luckily.
- 49:57I'm just kidding.
- 49:58Luckily, Import Lib, in terms of actual import itself, like this, I'm ignoring Import Lib.resources
- 50:05or Import Lib.metadata.
- 50:07Jason Coons mainly manages those modules.
- 50:09It's been stable enough for long enough now that there's no real crazy surprises anymore.
- 50:14Honestly, the biggest headache is people doing imports in their threads.
- 50:18So my word of advice to everyone, don't do imports in threads.
- 50:21If you're going to do imports, do them on your main thread up front.
- 50:24Then spawn your threads.
- 50:26Don't do imports as a side effect of anything either.
- 50:29It's circular imports.
- 50:31Same thing.
- 50:32It's just, just, just don't.
- 50:34Your life will be so much easier.
- 50:35But that's honestly where any of the bug reports that ever come in come from is due to either
- 50:40circular imports and people wondering why or weird race conditions with threads on imports
- 50:45and just trying to get the locking down such that things lead to the right outcome.
- 50:49Yeah.
- 50:50Actually 3.12 almost got held up a little bit due to a slight memory leak from the newest
- 50:55version of tracking imports via threads.
- 50:59There was a slight leak of it.
- 51:00Wow.
- 51:00Basically an empty dictionary every time you did an important thread and we didn't want to have
- 51:04that leak.
- 51:04So we cleaned it up.
- 51:05But yeah, it once had a lot of subtlety.
- 51:08Oh, we got lots of memory, bro.
- 51:09We don't need to worry about those things anymore.
- 51:10No, just kidding.
- 51:11Yeah.
- 51:12There's no reason everyone gets excited every time Apple launches a new M chip, right?
- 51:17We've had enough processing power since we got someone on the moon with how many hertz?
- 51:22Exactly.
- 51:23No one needs more than seven hertz.
- 51:25You know the favorite thing.
- 51:27You know, one of the real big differences I think here is that like import runs code,
- 51:32right?
- 51:32Like rather than tells the compiler these things are in scope if you want them.
- 51:37But no, it's like running code.
- 51:39And if people are wondering where that weird dunder name equals dunder main, so you don't
- 51:46run too much code during imports and those sorts of things, right?
- 51:49Yeah, actually.
- 51:50And this is an interesting case where it's very much syntactic sugar, but it's also very much
- 51:55syntactic sugar actually for the bytecode.
- 51:58Yeah.
- 51:58So the thing here is when you do import spam, right?
- 52:02Or whatever module you want to import, it effectively ends up being a call to the dunder
- 52:07import built-in function where it passes in spam as the name, and then it passes in all
- 52:11the globals and the locals for where it gets called for name resolution and stuff like this
- 52:16is where you do relative imports with dot, you know, like dot, dot something.
- 52:20Yeah, exactly.
- 52:21When I first saw it, like, why are all these arguments going to import?
- 52:23You just need to know where a, a dot pi or the package a lives and you're good to go
- 52:28until you say, you know, dot, dot this or from dots.
- 52:32Yeah.
- 52:33From dot, dot a import B kind of stuff.
- 52:35Like there's a surprising amount of information you need to pass in to do those kinds of resolutions
- 52:39and such from imports, right?
- 52:42All that kind of thing to make sure those things all exist.
- 52:44Because what you're effectively doing, you know, from import is if you list multiple ones, you're
- 52:49basically importing the module that those things are in and making sure that attribute gets set
- 52:53on the thing you're wanting so that you can then grab it later and all sorts of stuff.
- 52:57But the other key thing is, is the Dunder import function is structured to kind of make the
- 53:02up code easier, right?
- 53:03Because it's very structured to just push things onto the snack that Python's executing and then
- 53:09make the call to Dunder import where it's just like, yeah, everything's already there.
- 53:12Right.
- 53:12But it's also why it's so funky.
- 53:14You should never call it directly in your own code, right?
- 53:17Like Dunder imports very much.
- 53:18It's borderline implementation detail on this kind of thing.
- 53:21This is why you choose import lib dot import module, right?
- 53:24That function exists specifically.
- 53:26And I designed it specifically for those cases where you need to do dynamic imports.
- 53:30And you want a very clean, simple API because like the return type for Dunder import very much
- 53:36is designed for the op code so that whether you're doing an import something or from
- 53:42something import other thing, right?
- 53:44Like the return value makes sense or that for the bytecode level does not make sense for
- 53:49human beings, right?
- 53:50So once again, do not call Dunder import directly.
- 53:52You should always be calling import lib dot import module if you need something dynamically to
- 53:57import.
- 53:58Or just use the word import.
- 53:59Yeah.
- 53:59Or just import.
- 54:00Yeah.
- 54:01Just import.
- 54:01Yeah.
- 54:02In your right up here, you have all the different variations.
- 54:05Like what does it mean to say from thing import something as or just import something or
- 54:11relative imports?
- 54:12So people can see all the different, again, back to that flexibility that you talked about.
- 54:17Exactly.
- 54:17So it's definitely one of these things though where in the end, it effectively just boils
- 54:22down to a function call, right?
- 54:23Like that piece of syntax of import really is just a function call with an assignment in
- 54:29the end.
- 54:29Yeah.
- 54:29And it's really all it is.
- 54:31It's the unraveling.
- 54:32All the trickery is really behind the Dunder import function, but the actual syntax is
- 54:37not, it's not crazy actually.
- 54:38But it literally is a function call.
- 54:40Yeah.
- 54:40You can fully re-implement import.
- 54:42Yeah.
- 54:43But just calling Dunder import and just doing the proper assignment.
- 54:45Nice.
- 54:45Some confirmation of your advice out there.
- 54:48Nathan says, my data science professor always says the same thing.
- 54:50Import first, which is good.
- 54:52But also, is there a way to remove syntactical sugar on an example, but not fully through disassembly?
- 55:00You can actually write a tool that will take Python syntax and unravel it.
- 55:04I actually started it, but it was just too much of a headache because there's so many variations
- 55:08and edge cases and all that stuff to handle.
- 55:10And there was no package out there that was going to, that quite did what I needed it
- 55:14to do to make my life easier.
- 55:16And I had other things to do.
- 55:17Yeah.
- 55:17What's the canonical, what's the destination, right?
- 55:20Like if I undo a with statement on a lock, like how far do I want to go back?
- 55:25You know?
- 55:26Yeah.
- 55:26Well, and I can understand people wanting to do it to maybe learn, but I mean, it's going
- 55:32to be a learning thing, not really a performance thing.
- 55:35It might be slower, right?
- 55:37Because some of this stuff is happening at the sea level.
- 55:39Oh yeah, exactly.
- 55:40Like, like if you go back to our A plus B example, it actually definitely will be slower
- 55:45as things, as things happen in Python, because once again, with the speed performance improvements
- 55:53that have been going in, like, like the byte code is able to go like, all right, is
- 55:58this an intent and an end?
- 55:59Okay.
- 55:59Well then we're, we know exactly how to do integer math.
- 56:02Let's just do it.
- 56:02Right.
- 56:03And then it can add cards in and go like, okay, quick check AB.
- 56:06Yes.
- 56:07Okay.
- 56:07Do the binary int add thing.
- 56:10Right.
- 56:11Where it just very, very obviously does that.
- 56:14But if you unravel it, you can't do that because now you're just doing method calls.
- 56:17Right.
- 56:18You can't hide those details anymore and put all that.
- 56:20Exactly.
- 56:21But yeah, but to answer the question, you totally could write a tool to do this.
- 56:24And I kind of started one and it just wasn't fun.
- 56:27So I just stopped because I just had a thing.
- 56:31You know, sometimes you see this in the editor as well, when like editors will give you previews.
- 56:35So for example, if you use optional of a thing or thing pipe none, and then you hover over
- 56:41it in the editor, it'll say, even if you used optional, it'll say thing pipe none, because
- 56:45it, it's like, those mean the same thing.
- 56:47I'm going to just represent them in one way.
- 56:49And yeah.
- 56:50Yeah.
- 56:50Interesting.
- 56:51Okay.
- 56:52We have a bunch more things covered, but we don't have really any time.
- 56:54Like my goal with this, having you on here to talk about this stuff, it's really kind of
- 56:58like the highlight, the whole series and people should go.
- 57:00And we've been kind of hand waving because reading C code on air is not ideal to give people
- 57:06an idea, but really to highlight your whole series and people can just dive into this pretty
- 57:11deep.
- 57:11And, and I think they'll have a much better appreciation for when you write this one line.
- 57:16Oh my goodness.
- 57:17This is actually what's happening.
- 57:18And how I actually found a bug in Python.
- 57:21Thanks to it.
- 57:22Okay.
- 57:22Tell us quick about that.
- 57:23Yeah.
- 57:23It's covered in the in place binary operator, augmented assignment post.
- 57:28So, you know how you can do a plus equals B and it's like doing a equals a plus B.
- 57:34Yeah.
- 57:34Yeah.
- 57:35So it turned out it was broken for pal.
- 57:36So when, you know, when you could do a star, star B, that's a to the B power.
- 57:41Yeah.
- 57:41It turned out the semantics were busted for star, star equals.
- 57:45Wow.
- 57:45Okay.
- 57:46And no one had ever noticed because obviously people do not write custom implementations of
- 57:51thunder pal.
- 57:52Yeah.
- 57:52Yeah.
- 57:52Yeah.
- 57:52Yeah.
- 57:52Yeah.
- 57:53turned out was, and someone actually discovered it and reported it.
- 57:56I just didn't know about it.
- 57:57that basically when you did that.
- 58:00So the in place augmented assignment, there's I versions of everything.
- 58:04Like I add a dunder.
- 58:06I add dunder.
- 58:07I mall dunder.
- 58:08I pow, right?
- 58:09It turns out for all of them, they did the right thing except for power where it would
- 58:13check for I pow.
- 58:14And I mean, in all these scenarios, because a plus equals B is the same as a equals a plus
- 58:20B.
- 58:20If the I version returns, not implemented, it falls back to just doing the binary operator
- 58:26and then doing the assignment.
- 58:27Right.
- 58:27So like if I plus, so I plus equals B unravels to a dot I pap, I, a dot dunder I pow with
- 58:35B as an argument.
- 58:36If that returns not implemented, then it devolves into a plus B a equals the result of that.
- 58:42Right.
- 58:42In the pow case, if you return not implemented on dunder I pow, it didn't fall back to pow,
- 58:47dunder pow.
- 58:48Okay.
- 58:49It just crashed.
- 58:50You said, I don't know what to do here.
- 58:51It was just an exception.
- 58:52It was like, yeah, no.
- 58:53I suppose that's better than the wrong answer.
- 58:54Like actually the square of nine is 18.
- 58:57Carry on.
- 58:58It threw me for a loop because I wrote code to verify all my unraveling and how did the
- 59:04augmented assignment for power just kept not working.
- 59:06It was like, what the heck's going on?
- 59:08And then I had to dig into the C code.
- 59:09I was like, what am I doing wrong here?
- 59:11Yeah.
- 59:11Wait a second.
- 59:12That code unravels calling this C code, calling this C code.
- 59:15And it didn't check that return value on calling it under ipow.
- 59:19It's like, well, did it return not implemented?
- 59:21And if it did, then we've got to try the other version.
- 59:23It just didn't.
- 59:24It's like, oh, no, it's just the value just got returned.
- 59:27It just didn't even check.
- 59:28I think we figured out it happened when the third argument to pow got added and it was just
- 59:33someone overlooked it.
- 59:33But I see it been sitting there for years.
- 59:36Like I think it was a decade.
- 59:38Yeah.
- 59:39You're looking through these things.
- 59:40You can tell that they're pretty subtle.
- 59:42There's a lot going on in the different special cases.
- 59:44So I can see it wouldn't hit you in the face that you necessarily miss something right
- 59:47away.
- 59:48Exactly.
- 59:48Yeah.
- 59:49Yeah.
- 59:49Yeah.
- 59:49I don't fault anyone at all.
- 59:51I think we were just missing a test case somewhere to make sure that that happened.
- 59:54Because and once again, I don't think people define their own custom pow operator for their
- 59:59types.
- 1:00:00There's a whole bunch of mathematicians going, we do.
- 1:00:02We do.
- 1:00:03Or physicists or something.
- 1:00:05Yeah.
- 1:00:06All right.
- 1:00:06We're pretty much out of time to go any deeper on this.
- 1:00:08And I think that I think people got a really good sense of what's happening, you know,
- 1:00:13like what you mean with your series here.
- 1:00:15And hopefully they're inspired to go check it out.
- 1:00:17But I do.
- 1:00:17While I have this import stuff on the screen and you've done so much work with import lib,
- 1:00:21will there ever be a time where like hot reload type of stuff is a thing?
- 1:00:27You know, like I edit this file in this web app and it's got this project.
- 1:00:31It's been running.
- 1:00:32And I just, just maybe could we have a file watcher trigger this module to re-import?
- 1:00:38Not necessarily saying it's a good idea, but have you.
- 1:00:40Do you mean like you want automatic import lib.reload?
- 1:00:43Yes.
- 1:00:44Or, you know, even like the lib reload stuff.
- 1:00:46A lot of times like you can do it, but it's kind of discouraged because I think largely because
- 1:00:50of the side effects.
- 1:00:51What can happen there?
- 1:00:53No, so to be very specific, if you call a module, if you call import lib.reload on a
- 1:00:58module, it effectively reruns import on that module.
- 1:01:01The problem is, is all the references you have to objects don't change.
- 1:01:07Yeah, exactly.
- 1:01:07So if you got something out of that module, like let's say there was a global dictionary
- 1:01:13that you stored a reference to a way that you expected.
- 1:01:15Right.
- 1:01:15Or a function or a class.
- 1:01:17Maybe.
- 1:01:18Yeah.
- 1:01:19And then you call reload, everyone else in the future is going to get the new module
- 1:01:23and they'll get the new version of all the things that were in that module.
- 1:01:26But all that stuff you still have reference to do, that didn't get magically taken away
- 1:01:30or garbage collected.
- 1:01:30And we can't really necessarily swap it underneath you either because the whole type could have
- 1:01:34changed.
- 1:01:34Right, right, right.
- 1:01:35So, I mean, if you really wanted to set up your own import system that does file monitoring
- 1:01:40and Omnic calls import.reload, you could totally do that today.
- 1:01:43There's nothing stopping you.
- 1:01:45But you have to just be very aware that.
- 1:01:48Only sometimes will it have a good effect.
- 1:01:50Yeah, it'll have an effect.
- 1:01:52Yeah.
- 1:01:52It's just whether it's going to do what you expect.
- 1:01:55And that's why import.reload is discouraged because people often don't quite understand
- 1:02:01the side effects and the things you have to watch out for to understand that it's going
- 1:02:05to do what you expect.
- 1:02:06And especially when you import, do from imports, right?
- 1:02:11Because then you're getting the direct objects off the module instead of the module itself.
- 1:02:14Because if it doesn't in place reimport.
- 1:02:17So, if you did import spam and you reloaded spam, the attributes off of spam will now be
- 1:02:23the new stuff.
- 1:02:24Because we actually changed that dictionary in place.
- 1:02:26But if you did from spam import function, function is not going to change.
- 1:02:30There's another reason why I always tell everybody, don't import the objects from a module, import
- 1:02:34to the module.
- 1:02:35I personally find it more readable because I can look at the code no matter where I am
- 1:02:39in the file and know where that function came from.
- 1:02:41It's not from this module.
- 1:02:42It's from somewhere else.
- 1:02:43I am always with you.
- 1:02:43I'm almost never from thing import other thing.
- 1:02:46Yeah.
- 1:02:47Unless it's a deep module in a package, in which case that makes sense.
- 1:02:50Because you'll still do module dot thing.
- 1:02:53Right.
- 1:02:53Right.
- 1:02:53Well, even though I have that, if it's like four levels deep, I'll do the first three.
- 1:02:57And then from the first three, import the last step of the module.
- 1:03:01So, you can say like data layer dot, you know.
- 1:03:03Exactly.
- 1:03:04Update rather than just update.
- 1:03:05Like, well, what does update mean?
- 1:03:06I don't know.
- 1:03:07Exactly.
- 1:03:07Yeah.
- 1:03:08I mean, the canonical example is random.
- 1:03:10You see the function random in your code.
- 1:03:12Whose random is that?
- 1:03:13Is that from the random module?
- 1:03:14Is that from NumPy?
- 1:03:15Did you implement random?
- 1:03:17Whose random is that?
- 1:03:18Yeah.
- 1:03:19You just know.
- 1:03:19But if you saw np.random, you'd know.
- 1:03:21Exactly.
- 1:03:22Yeah.
- 1:03:22If you knew what np was.
- 1:03:23Yeah.
- 1:03:23If you did.
- 1:03:24Of course.
- 1:03:25Right.
- 1:03:26I guess give you a chance to kind of summarize.
- 1:03:29Final, final thoughts here on your Syntactic Sugar series and, you know, tell people how
- 1:03:34to get it and stuff.
- 1:03:34You can go to my blog.
- 1:03:35It's on Snarky.ca.
- 1:03:37It has the tag Syntactic Sugar.
- 1:03:39I'm sure Michael will include it in the show notes.
- 1:03:41Don't feel the need to read all of it, but do look at at least the first one or two because
- 1:03:47I do go into more detail on how you can kind of go exploring on your own in way more detail
- 1:03:52in those posts than I do towards Anne because I'll be honest, I lost a bit of steam and
- 1:03:56going diving into all the deep layers.
- 1:03:58I wanted to get the blog post series done after two years.
- 1:04:01It was one of those.
- 1:04:02Okay.
- 1:04:02Go look at the earlier ones.
- 1:04:03They'll explain how to how to figure out how to go from syntax to the bytecode to the C code
- 1:04:08and then know where to look in the C code, which, by the way, you don't have to understand
- 1:04:11the C code.
- 1:04:12It's not a is not crazy C code, but it's also not necessarily critical.
- 1:04:16I do try to write down the Python equivalents for everything.
- 1:04:19So it's there if you do understand C, but don't feel intimidated if you don't.
- 1:04:23And hopefully you just find it interesting, right?
- 1:04:25Like you've always wondered how the heck does this work?
- 1:04:27If it's in that, if it's in the blog post, you'll be able to have a better understanding
- 1:04:33hopefully of how things work.
- 1:04:33Because as I said, I honestly even learned some details that I forgot or never even knew
- 1:04:37about some of the semantics behind Python and how, like how things actually work underneath
- 1:04:42the hood.
- 1:04:43And it just gave me a better understanding to understand when things do and don't happen
- 1:04:46the way I expect.
- 1:04:47And honestly, appreciate all the work everyone's put into language over the decades to make it
- 1:04:52all seemingly seem simple.
- 1:04:53And yet it's surprisingly complex.
- 1:04:55Yeah.
- 1:04:55I don't think you need to read them all either as somebody who read most of them the last couple
- 1:04:59of days.
- 1:04:59No, you don't.
- 1:05:00I mean, if you're a completionist, go for it.
- 1:05:03But yes, you definitely do not need to.
- 1:05:04But I do think going through it, you know, pick out the ones, there's a whole bunch of
- 1:05:08different topics.
- 1:05:09Pick out the ones that are like, oh, I did always wonder how that one worked.
- 1:05:11And pretty much with the exception of pass, I think you'll be like, oh my gosh, I had no
- 1:05:18idea what was involved here.
- 1:05:19Yeah.
- 1:05:19Pass was very much just a, I had a checklist of every piece of syntax and every single keyword.
- 1:05:24And that was that the blog post on pass, I think is like three sentences and half of
- 1:05:29it saying this is going to be the shortest, shortest post in this whole series.
- 1:05:32Yeah.
- 1:05:33Pass is.
- 1:05:33Yeah.
- 1:05:34It was contending with dot, dot, dot, which we haven't even had a chance to talk about
- 1:05:38ellipses versus pass, but I think we're out of time, Brett.
- 1:05:42So thanks for being here.
- 1:05:44Thanks for all you do.
- 1:05:45I mean, steering council, core dev, author, VS Code, et cetera.
- 1:05:50A lot of contributions.
- 1:05:51Thanks.
- 1:05:52Thanks for having me back on yet again.
- 1:05:53And hopefully I've not worn out my welcome still.
- 1:05:55No, you're already thinking about what next WebAssembly Rust thing we'll get together on.
- 1:06:01Thanks for being here.
- 1:06:02See you later.
- 1:06:03Thanks, Michael.
- 1:06:03This has been another episode of Talk Python To Me.
- 1:06:07Thank you to our sponsors.
- 1:06:08Be sure to check out what they're offering.
- 1:06:10It really helps support the show.
- 1:06:11Want to level up your Python?
- 1:06:14We have one of the largest catalogs of Python video courses over at Talk Python.
- 1:06:18Our content ranges from true beginners to deeply advanced topics like memory and async.
- 1:06:23And best of all, there's not a subscription in sight.
- 1:06:26Check it out for yourself at training.talkpython.fm.
- 1:06:28Be sure to subscribe to the show.
- 1:06:30Open your favorite podcast app and search for Python.
- 1:06:33We should be right at the top.
- 1:06:35You can also find the iTunes feed at /itunes, the Google Play feed at /play,
- 1:06:40and the direct RSS feed at /rss on talkpython.fm.
- 1:06:44We're live streaming most of our recordings these days.
- 1:06:47If you want to be part of the show and have your comments featured on the air,
- 1:06:50be sure to subscribe to our YouTube channel at talkpython.fm/youtube.
- 1:06:55This is your host, Michael Kennedy.
- 1:06:57Thanks so much for listening.
- 1:06:58I really appreciate it.
- 1:06:59Now get out there and write some Python code.
- 1:07:01I'll see you next time.