Latest / Talk Python To Me / #214: Dive into CPython 3.8 and beyond
Transcript
- 0:00Python 3 .8 is coming soon. It's scheduled for release at the end of October 2019, and you can
- 0:05already download test versions today. Given that Python ships on an 18 -month cycle, it's time to
- 0:10talk about what's coming for us Python developers in the fall. On this episode, I meet up with Lucas
- 0:14Lenga and Anthony Shaw to chat about the highlights of this upcoming version of Python.
- 0:19Also, quick show note, we recorded this on location in Cleveland at PyCon 2019. There may be a small
- 0:25amount of background noise, but I think you'll barely notice. This is Talk Python To Me,
- 0:29Episode 214, recorded May 5th, 2019.
- 0:46Welcome to Talk Python To Me, a weekly podcast on Python, the language, the libraries, the
- 0:51ecosystem, and the personalities.
- 0:53This is your host, Michael Kennedy.
- 0:54Follow me on Twitter, where I'm @mkennedy.
- 0:56Keep up with the show and listen to past episodes at talkpython .fm and follow the show on Twitter
- 1:01via at Talk Python.
- 1:03This episode is brought to you by Microsoft.
- 1:06Be sure to check out what they're offering during their segments.
- 1:08It really helps support the show.
- 1:10Lucas, Anthony, welcome back to Talk Python, both of you guys.
- 1:13Hello.
- 1:13Hi, Michael.
- 1:14Good to be back.
- 1:15Yeah, it's great to have you back.
- 1:16We are not recording over Skype far distances, but in fact, we're right here at PyCon.
- 1:22And who knows how the audio for this is going to come out, but hopefully it'll sound good
- 1:26enough, but it's great to be here on site in Cleveland with both of you. It's a
- 1:29unique
- 1:30experience to actually see you doing the recording.
- 1:32Yeah, it's really good to be here in Cleveland.
- 1:34The sun has finally come out today after the third day of PyCon.
- 1:38The fog was pretty incredibly epic and that was pretty special. And yeah, Lucas,
- 1:42the latency on this video call is incredible, man. It's so, it's lifelike.
- 1:46Yeah. So this video call is like 3D. It's amazing.
- 1:49Yeah, it's amazing. So thank you both for being here. We're going to talk about Python 3 .8 and
- 1:54maybe looking a little bit beyond that, some of the peps that are out there and all the cool stuff
- 1:58there. But, you know, let's just start with PyCon. Like, how's your experience this year? It felt a
- 2:02little different to me. I'll say why in a minute,
- 2:04but you go first. I'm Kashlanga. I've been co -chairing
- 2:07the Language Summit this year with Mariata, and this is an absolutely new experience for me. So
- 2:12that was interesting, actually herding all the cats at the right time to the right spots,
- 2:17you know, pre -selecting talks, actually making sure that everybody has the opportunity to speak,
- 2:22making sure that everybody is engaged.
- 2:25That was new.
- 2:25So I was very happy to have it over with after that day.
- 2:30I've heard it went pretty well.
- 2:31So I was happy about this.
- 2:33The rest of PyCon was also rather intense so far for me.
- 2:37I've had a talk about Black and then an extended Q &A
- 2:40that I just performed during the poster
- 2:43session on Sunday morning.
- 2:44That's really awesome.
- 2:45I feel like Black is one of these things that has just taken off.
- 2:49I often ask people what module they recommend or package.
- 2:52or what is like special that they've seen.
- 2:55And it's way more than any other single answer is black.
- 2:58That's awesome.
- 2:59Congratulations.
- 2:59Yeah, thank you.
- 3:01I'm very happy about it.
- 3:01In fact, I think there was at least five talks
- 3:04that mentioned, you know,
- 3:06using black as a good thing in them.
- 3:08So it seems like, you know,
- 3:10we've solved an issue that people had.
- 3:12We've solved a problem that people had.
- 3:13Yeah, we've had these linters
- 3:14and they've tell us what you're doing wrong.
- 3:16And we're just like, can't you just fix it?
- 3:18Like, I don't want to be told what's wrong.
- 3:20I just want it to be better.
- 3:21Yeah, well, the difference
- 3:22between Black and other autoformatters,
- 3:24of which we have a few in the Python community,
- 3:27is that Black was kind of brave,
- 3:30obnoxious enough to tell you
- 3:31that it's going to just be done in one way.
- 3:34It's not really configurable.
- 3:36But that kind of changes it to a workflow tool
- 3:38where if you decide to use the tool,
- 3:40now the question of autoformatting sort of disappears.
- 3:43The question of how to format your code
- 3:45is no longer a problem
- 3:47when you're developing your own projects.
- 3:49Yeah, and if you're on a team,
- 3:51you don't have to have this debate anymore of how we do stuff, right?
- 3:53You just run black and that's how you do it.
- 3:55Absolutely.
- 3:55Awesome.
- 3:56Okay.
- 3:56Anthony, how's your PyCon going?
- 3:58Like, what do you notice this year that's special?
- 3:59Yeah, this is the first PyCon I've actually given a talk.
- 4:03So that was definitely a milestone for me.
- 4:04Yeah, what was the talk?
- 4:05It was on code complexity.
- 4:07And I talked about Wiley, which is a project I've been working on.
- 4:10And then the principles of code complexity and why complexity is bad.
- 4:13So how awesome cyclomatic complexity is?
- 4:16I actually talk about how it's inevitable,
- 4:18the more users you have to have more cyclomatic complexity.
- 4:21people ask me how the talk went and my response so far has been i don't remember because i was so
- 4:27nervous that it was just a sort of adrenaline fueled dream so that was um yeah really cool and
- 4:32then yesterday there was mentored sprints that's new right which is a new thing this year and that's
- 4:39probably the highlight actually for pycon so far is actually just being in there and mentoring people
- 4:44and to contribute to the different projects and working with someone who ended up being able to
- 4:49send a pull request through to CPython by the end of the day.
- 4:53And I think it was their first one, which is awesome.
- 4:55Yeah, that's super cool.
- 4:56That's got to help adoption and contributions,
- 5:00right?
- 5:00Because even me personally, I think about, okay, well, I'd love to do something,
- 5:04but I really don't even know how to get started, how to build it,
- 5:08what the right rules or expectations are.
- 5:10Like, it's a lot of work.
- 5:12And if somebody can sit down who's done that or is at least knowledgeable about that
- 5:15and walks you through it, like the second time onward is much more likely
- 5:19to be smooth yeah
- 5:20and it was a proper amount of time allocated as well it was i think it's just
- 5:23over four hours on the second day in the afternoon so it's good enough time to actually sit and work
- 5:29on a proper a proper issue um or a proper feature and actually work through it from start to finish
- 5:34yeah you actually got a pr in place not just started or whatever yeah exactly so yeah that's
- 5:39awesome
- 5:39to
- 5:40me it felt like when i walked into the expo hall that the booths were a little bit bigger
- 5:45there were a little bit more people. It just seemed like a little bit,
- 5:49I don't know, there are a little more people, a little more energy, even than last year. And last
- 5:52year was amazing. I don't know. Did you have this feeling?
- 5:53Yeah, I was particularly impressed with
- 5:55the portrait of Guido at the Capital One booth,
- 5:59which you've got to see online if you haven't
- 6:01seen a picture of it already. Yeah, their booth was really artistic. It was pretty cool. Nice.
- 6:05All right. So it's great to be here at PyCon, but let's talk about the future. Let's start with the
- 6:12idea of when is Python 3 .8 going to be out? How precisely didn't we know that? And Lucas,
- 6:18maybe just say a little bit about like, you're mostly in control of this at the moment, right?
- 6:23Like the release schedule and management and whatnot, right?
- 6:25Currently, I'm serving as the release manager of Python 3 .8. And
- 6:30I wrote the schedule for where
- 6:32things are going to go. Traditionally, Python has been released every 18 months, which puts Python
- 6:363 .8 at the end of this year. Like, you know, and in particular, like, you know, give or take,
- 6:42it should be the end of October. The reason why I'm not saying a particular date, even though it
- 6:47is in the PEP, is that those things tend to be a bit fluid. Like in the past three alphas that I
- 6:53released, like we've been a day early or a day late pretty much every time. Yeah, would you
- 6:58be
- 6:58willing to like hold up a release
- 7:00if there's some important feature that's two days away? In fact,
- 7:03like this time, there was a small issue, well, but small in size, but big in significance that
- 7:10I held up Alpha 4 that I had a bit of time for early in the week, which kind of makes me late for my own schedule now.
- 7:18And I have to release Alpha 4 tomorrow at the start of sprints.
- 7:22But those things are more important to get right than to get on time.
- 7:26And this is something.
- 7:28Yeah, especially when it's 18 months.
- 7:29If you were
- 7:29shipping monthly updates, like whatever, just ship what you got, right?
- 7:32But if it's 18 months, that couple of days, that means a big, big deal, right?
- 7:37This is exactly
- 7:38the point.
- 7:38We try to make the consecutive releases, even on the alpha level, consecutively better and not introduce a breakage that is going to be later reverted since every release, including alphas, is being tested by our users.
- 7:52And we're happy to see actually alpha releases being increasingly used by the community to test their own libraries and applications.
- 8:00That used to be our problem, that it was only after the beta releases.
- 8:04And in fact, RCs very often were the first releases that users would see.
- 8:09Nowadays, with like PyPI working better, with CI options being out there for pretty much everybody,
- 8:17we see more adoption of alpha releases, which is great.
- 8:20But that is also a bigger responsibility on the alpha releases because you are no longer free to just make a breaking change and then later revert it.
- 8:27Well, it's alpha anyway.
- 8:28Well, no, it isn't.
- 8:29Didn't you see what it
- 8:29was?
- 8:30It said alpha.
- 8:30Yes, now
- 8:31we would need to have feature toggles that look at the alpha version to see whether a particular bug exists or not.
- 8:37And we don't want that.
- 8:39This might be a slightly political question, but have the releases of Python recently become more stable?
- 8:47It feels to me that people have almost zero trepidation or worry about just adopting 3 .7 when they had 3 .6 or 3 .6 when they had 3 .5 these days.
- 8:58And it seemed like there was more concern about what's going to break when I go to the next, you know, semi -major version.
- 9:03Has that changed or is that like perception?
- 9:05For a number of years, the only version that people used was 2 .7.
- 9:09And that was for a long time.
- 9:11So it created this false perception that like Python is infallible, that every particular update of it like never introduces issues that were not there before.
- 9:21Because
- 9:21they were just minor fixes.
- 9:22Exactly.
- 9:24That was good.
- 9:25You know, at the same time, a blessing and a curse.
- 9:28since every particular version of Python,
- 9:31like including Python 2 .4 to Python 2 .5,
- 9:34Python 2 .5 to Python 2 .6,
- 9:36did introduce internal changes
- 9:39that made large projects actually complex to migrate.
- 9:44The biggest example from the Python 2 world
- 9:46where it was when Python 2 .5 was released.
- 9:50Zope at the time created such a problem for itself
- 9:54that it took them enough time
- 9:56that they migrated to Python 2 .6 directly.
- 9:59So the previous version worked on Python 2 .4,
- 10:03whereas the next one directly on Python 2 .6,
- 10:06they did not migrate in time for 2 .5.
- 10:06Right, it took so long to migrate.
- 10:08They're
- 10:08like, let's just aim for the next one,
- 10:09huh?
- 10:09So this is all just like a long, long introduction
- 10:13to just let you know that in Python 3,
- 10:16there are also changes.
- 10:18Many of those changes are deliberate, right?
- 10:20We are changing how the internal memory representation
- 10:23of objects looks like.
- 10:24We are introducing and removing bytecodes.
- 10:28We can change how modules get initialized.
- 10:31You know, there's multiple things that might break real applications,
- 10:36but breaking them in ways where it is impossible for us
- 10:40to guarantee eternal compatibility with those
- 10:43things.
- 10:43Sure, but this greater adoption of alpha versions and testing and CI
- 10:47probably doesn't hurt, right?
- 10:48Some kind of crashers, right?
- 10:50Downright
- 10:51bugs and whatnot.
- 10:52That I feel like we are doing a better job these days with.
- 10:57Also just because Python 3 finally gets enough adoption that those versions get vetted much better.
- 11:04Right, absolutely.
- 11:05When I started contributing, we were just working on Python 3 .2.
- 11:09So for a number of years, almost none of the things I worked on were actually very heavily used in the industry.
- 11:15Nowadays, the situation is different.
- 11:18So fortunately, the time between a change and actually having real users report on it is way shorter, which makes the QLT just better.
- 11:27Yeah, that's awesome.
- 11:28Anthony, let me ask you what your
- 11:30perception of that's like.
- 11:31You work for a pretty major company that probably has stability in mind and stuff.
- 11:35What's your perspective and what are you seeing at Dimension Data and places like that?
- 11:39It's definitely become easier for people to install newer versions of Python, which is really helping.
- 11:44So in terms of, I guess, moving towards things running as microservices on Docker, for example,
- 11:50there's this, it's not a single system running a specific version that's got to support all
- 11:55these different applications.
- 11:55Right, it's not cross your fingers or upgrading the server.
- 11:58Yeah, we're not running on the mainframe anymore.
- 12:00So I think that that's really helping in terms of there's more automation for systems deployment
- 12:06and there's a lot more tooling being used to automate like the building of new environments.
- 12:12there's this kind of idea of immutable infrastructure now where you basically create
- 12:17infrastructure in the cloud and you build it on a specific version.
- 12:20You don't change it, right, ever.
- 12:22Yeah.
- 12:22So I think that has actually made it easier to move to newer versions because you can
- 12:28just spin up new infrastructure with the new version, test how it works, and you can inspect
- 12:33it properly.
- 12:34Whereas like 10 years ago, you're talking about we need to go and buy a million dollars
- 12:38of hardware to build an identical environment to see if this new version is going to work for us.
- 12:43Right. And maybe
- 12:43you have like downtime the whole weekend, the team stays all night and they do the
- 12:48testing and the rollout. And, you know, these days when I go to websites and I see we're down for
- 12:53maintenance or we have even like we have scheduled maintenance over this like two to four hour window.
- 12:57I'm just like, what are they doing? Like what possibly could take four hours to upgrade? Like
- 13:08four hours, it doesn't take anyway. It just seems pretty wild when you see it. But that used to be
- 13:11common, right? So I guess, yeah. So it doesn't matter as much.
- 13:14Yeah, it still matters for some
- 13:16really big applications. I know some of the biggest software vendors still have four -hour
- 13:20maintenance windows every Saturday. We definitely have to live through some of that pain at the
- 13:24moment. But more and more, I think people are using this sort of automated deployment and
- 13:29automated infrastructure, which is making it a lot easier to upgrade. That's awesome.
- 13:34What about the beta version or the alpha version even of 3 .8?
- 13:38You guys said late October for the main release.
- 13:42For the main release, but we work that back.
- 13:44When will we see stuff that we can start playing with?
- 13:46Can we already?
- 13:47I know, Anthony, you get it in build from source a lot and then play with it,
- 13:51and you guys do as well.
- 13:53But when does the average person who just wants to install a beta
- 13:57or something like that get access to it?
- 13:59Any alpha release
- 14:00is released in both the forum of sources
- 14:03that you can freely build.
- 14:05If you're cloning the repository from GitHub,
- 14:08there's tags that tell you exactly
- 14:10when a particular release was made.
- 14:12But also for alphas, betas,
- 14:14and later release candidates
- 14:16and actual versions that we release,
- 14:18we do have binaries, right?
- 14:19So for both macOS and Windows,
- 14:22we have plenty of binaries
- 14:24that you can use to test out your software.
- 14:26I would advise to do it as early as possible.
- 14:29especially 3
- 14:30.8 was kind of like a shy release.
- 14:34Right, because we had the whole governance thing,
- 14:37all the major changes were sort of put in.
- 14:39Yes, so now
- 14:40we are just four weeks before the first beta,
- 14:44which is the feature freeze for us, right?
- 14:46Since beta 1 to the main 3 .8 .0 release,
- 14:50we are just fixing bugs.
- 14:52In some unlikely cases,
- 14:54maybe even reverting features that we identified
- 14:56are not ready for prime time,
- 14:58unlikely to happen. What is more likely to happen is this is the time where you know that breaking
- 15:04changes are no longer being, new breaking changes are no longer being accepted. So it's a great time
- 15:10to actually start using your CI to test your libraries, your applications on Python 3 .8 as well.
- 15:16Expect problems. There's things that we have not identified, even though we have our other
- 15:21extensive regression suite of tests. But it's great to be able to identify those things early.
- 15:27So by the time the distributors come in and package Python 3 .8,
- 15:31its quality is good and we're transparent.
- 15:33We just can run your application with minimal churn.
- 15:36That's pretty cool.
- 15:37Can you test it with Tox or what's the best way to test on 3 .7 and 3 .8 beta or whatever?
- 15:43There's many possible ways depending on what
- 15:45particular operating system you're using.
- 15:48For open source projects that are already using a CI system like Travis,
- 15:53There are ways to just utilize the latest development version of Python.
- 15:57And at the moment, it's 3 .8.
- 15:59So just by just saying that you would also like to run your tests on the development version
- 16:04of Python, you're going to get beta version like in a month.
- 16:07That currently is going to be a form of alpha.
- 16:10So that is probably easiest because you don't have to actually install anything locally on
- 16:14your computer, which tends to make things complex when you have many interpreter versions with
- 16:19you.
- 16:20So homebrewing, Patrick, likes to default to one Python 3 version, one Python 2 version.
- 16:25So there's PyEnv that you can use to have multiple installations.
- 16:29And obviously, yes, there's Tox.
- 16:31They actually work rather well together.
- 16:33So you can set up your matrix of tests that later are run online,
- 16:37but you can also run them locally, which is what I'm doing.
- 16:40Yeah, okay.
- 16:41That seems pretty easy.
- 16:42All right, Anthony, let's kick off this PEP section
- 16:46and talking about the actual features,
- 16:48which, as we all know, appear as Python enhancement proposals
- 16:51and they go through a lifecycle and whatnot.
- 16:54If people are wondering what peps are out there,
- 16:57what might make it into 3 .8 and so on,
- 16:58where would they go to
- 17:00find that out?
- 17:00So I think on the python .org website,
- 17:02and there's a list of peps.
- 17:03There's also a PEP index on the list of peps.
- 17:06I've also made a small web app called Pep Explorer,
- 17:09where you can go and search and filter
- 17:11and pull specific Python versions
- 17:14and get the status of the peps.
- 17:16So I use Pep Explorer because I spend time looking at peps and reading about them and
- 17:21trying to understand what's coming in future versions.
- 17:24So yeah, if you're just curious, I'd say the Pep Explorer is probably a good way to go.
- 17:27Yeah, the Pep Explorer is pretty awesome.
- 17:29It's just a nice little
- 17:29grid.
- 17:30It's on GitHub pages, right?
- 17:32Yeah.
- 17:33Yeah.
- 17:33And I'll just link to that.
- 17:34And of course, people can go to python .org.
- 17:36But yeah, it's really nice to just keep track of that.
- 17:39And I find that super helpful.
- 17:41All right.
- 17:42So let's kick it off.
- 17:43maybe since you're holding the mic, we'll go with you first.
- 17:47You know, what's like one of the notable things that's coming
- 17:49that you want to talk about, what PEP or feature?
- 17:52So I thought
- 17:52I'd cover off the
- 17:53two ones that changed
- 17:55the language first.
- 17:56Okay.
- 17:57So there's assignment expressions,
- 17:59colloquially known as the walrus operator.
- 18:02The walrus operator.
- 18:04Yeah, so this is PEP572.
- 18:06Yeah, PEP572.
- 18:07So in Python, if you want to assign a value to a variable,
- 18:12you use the equals symbol, that doesn't return anything.
- 18:15So if you just do a equals one in the REPL,
- 18:18then that won't return anything in the REPL.
- 18:21An assignment expression is basically a way of combining
- 18:24the assignment of a value to a variable
- 18:27and returning the variable back again.
- 18:29So the reason you would want to do that is in some statements,
- 18:33for example, within list comprehensions,
- 18:36within while statements, for example, within if statements,
- 18:40The thing in the if statement, the comparison, for example,
- 18:43you can actually do assignments inside the comparison,
- 18:47and it just removes some additional code that you might have to do.
- 18:51And also, there's a few other examples in list and dictionary comprehensions
- 18:55where you can do some fairly smart things inside the comprehension.
- 18:58Yeah, when I first saw this, I thought, interesting.
- 19:01I don't know if it's really needed, but I wasn't super against it or anything.
- 19:05But certainly seeing it in the list comprehension space
- 19:08and seeing it used in other places as well,
- 19:10I think I'm pretty positive on this language change.
- 19:13It's pretty nice.
- 19:14Certainly anytime you need an expression, right?
- 19:17Within like some kind of comprehension, maybe a lambda or something like that.
- 19:21Like this often is the only way to, you know, do it.
- 19:25Like, so if you want to create a variable, but also test it in a list comprehension,
- 19:31and that might be the response of a function.
- 19:33Like you can maybe have to call that twice.
- 19:35Once when you test it and once when you put it into the list,
- 19:38Now you could assign it and then test it, right?
- 19:40So these things get simpler.
- 19:42Yeah, they get simpler.
- 19:42I think looking at the syntax, people's initial responses often, I can't see where I would
- 19:47use that, but it takes a while for these types of pieces of syntax to become common because
- 19:53once you know the patterns in which you would use it and you've memorized them and then you
- 19:57start to use it more and more over time.
- 20:01This portion of Talk Python To Me is brought to you by Microsoft and Azure Pipelines.
- 20:06Azure Pipelines is a CI CD service that supports Windows, Linux, and Mac.
- 20:10It lets you run automatic builds and tests of your Python code on each commit or pull request.
- 20:15It is fully integrated with GitHub, and it lets you define your continuous integration and delivery pipelines with a simple YAML file.
- 20:21Azure Pipelines is free for individuals and small teams.
- 20:24If you're maintaining an open source project, you'll even get unlimited build minutes and 10 concurrent pipelines.
- 20:29Many Python projects are already using Azure Pipelines.
- 20:32So get started for free at talkpython .fm slash Microsoft.
- 20:39And then the second PEP, I guess, changes the language slightly is positional only arguments.
- 20:44And basically this is PEP 570, which has also been accepted and merged into Python 3 .8.
- 20:51It wasn't part of alpha 3, so it'll be in the alpha 4 release, I believe.
- 20:55And basically this one is you add a forward slash in the list of parameters in a function definition so that it says that it's only positional arguments in this function.
- 21:07The reason for that is basically to protect an API to ensure that people only use positional arguments and they don't start to use them as keyword arguments.
- 21:18Yeah, it's pretty interesting.
- 21:20It's like the anti -keyword -only argument one, right?
- 21:24which, so with the keyword argument one,
- 21:26I don't know that many people actually know about it,
- 21:29but it's pretty cool.
- 21:30So if you say, you know, function, parenthesis, star, comma,
- 21:34argument, argument, argument,
- 21:36those all have to be explicitly called as keyword arguments.
- 21:39This is like, I want to make it impossible,
- 21:43at least in this section of the parameters,
- 21:45to call them as keyword arguments, right?
- 21:47Yeah, it's a cool feature.
- 21:48And it's also going to help with
- 21:49a lot of the standard library.
- 21:51That's the other justification.
- 21:52And there's a lot of the Python standard library where the API needs to be protected so that it can be iterated on,
- 21:59where this feature is basically going to help lock that down.
- 22:02And also in 3 .7, there were some improvements to the performance of method calls.
- 22:07That performance improvement doesn't work with keyword arguments.
- 22:10I see.
- 22:10So basically, you could potentially use this as a way of enforcing that performance improvement.
- 22:15Okay, that's interesting.
- 22:16The example that I saw, I think if I remember this correctly, was just like range.
- 22:20Like even just knowing when you see stuff, if you quickly read it, like you could have range and say stop and then start and then step.
- 22:29Or you could have start and then stop and then step.
- 22:31Or you could have step and then start.
- 22:32And just seeing, I mean, even though the words are kind of similar.
- 22:35And it's going, no, I want you to always just say start and then stop and then step or whatever, right?
- 22:41Like just requiring them to not have this sort of almost arbitrariness of the order of the parameters seemed like an interesting idea there as well.
- 22:48Yeah, an additional detail is the fact that, you know, many of the functions that are implemented
- 22:53in C don't implement keyword arguments. So they're effectively positional only by the sheer fact that
- 23:00they are just being implemented in C. And this just enables us to express those same APIs in
- 23:06Python faithfully, so that alternative implementations recreate the API in exactly the same way.
- 23:12Oh, yeah, that's interesting. So you don't want like the leaky abstraction of the C
- 23:16implementation to leak out and maybe break PyPy or something like this? Yeah,
- 23:21so currently,
- 23:21like the issue is actually the opposite, where PyPy does not necessarily care that, you know,
- 23:27some argument is positional only in CPython. So they allow for keyword use of it. And then
- 23:34that piece of code is problematic going back to CPython. So that is just, you know,
- 23:39caring of, you know, making your library code, your application code,
- 23:43sort of exchangeable between runtimes.
- 23:45Yeah, interesting.
- 23:46What about Cython?
- 23:47Cython is its own kind of thing
- 23:49because it's a language that is being compiled
- 23:52or rather transpiled to a bunch of C or C++,
- 23:55which is then compiled to a C module.
- 23:58They are kind of free to do a lot of modifications
- 24:02that Python itself is not free to do
- 24:04because they're compile time modifications.
- 24:06Right, their
- 24:06transpiler can make the adjustment
- 24:09it needs anyway, right?
- 24:09Yes,
- 24:10the source code that you're reading
- 24:11is not the source code that is being executed.
- 24:14interesting all right what's the next PEP that you want to feature you want to talk about let's
- 24:18cover a few of them and in fact like the slew of peps is uh all related to typing uh let me start
- 24:24with something old
- 24:24which is PEP 544 protocols so that PEP should have been accepted a long time ago
- 24:31but it did not because of the governance or situation so
- 24:36protocol is this like kind of like
- 24:37interface inheritance type of thing like what what's going on protocols
- 24:41essentially is a way to
- 24:44introduce duck typing to static typing to type checkers so you can have interfaces well or like
- 24:51protocols they are called protocols across the python documentation too which is why we're using
- 24:55that name too but you can have essentially implicit interfaces that are being implemented
- 25:00by a class by a type and then the type checker is able to act on them when you express a need for a
- 25:07as an argument to a function.
- 25:09For example, if your function accepts anything
- 25:12that has a read method,
- 25:14now you can express that type.
- 25:16That's really
- 25:17cool.
- 25:17I'm super excited about this.
- 25:18Because if you take two things,
- 25:20like maybe a set and a dictionary,
- 25:23but you want to express,
- 25:23I'm going to have those types
- 25:25and I want to work with them.
- 25:25But really all I care about is I can iterate it.
- 25:27Or that's probably not the perfect example.
- 25:29But you know, like it's hard to kind of
- 25:31make the type system express that now.
- 25:33And this just says,
- 25:34well, if it has an add and a pop method,
- 25:37we're good like whatever right that's is that protocols yes
- 25:39so protocols is the answer like
- 25:41to a question that we've received a lot early on when uh PEP 484 came out like the original
- 25:47you know formation of static typing for python that isn't static typing in direct opposition
- 25:54to what we have been telling everybody to do for all those years which is duck typing like if it um
- 26:00if it quacks like a duck and looks like a duck it is a duck we don't care if this instance is
- 26:05working. We just care that the calls find the right methods with the right arguments and everything
- 26:12is fine. So now with protocols, you can actually structurally express this, that all you care about
- 26:18is a given field or a given method.
- 26:20I like it. I know you're a proponent of
- 26:22type hints and mypy and all that kind of stuff. How do you see the state of that these days?
- 26:27Well, we're definitely on the rise
- 26:30there. At my time at Instagram and at Facebook,
- 26:34we've seen a lot of improvements, both in terms of security, you know, a team velocity, and as well,
- 26:41just being able to comprehend the source code when types were introduced to the biggest PHP
- 26:48component of facebook .com. And so since, I guess, 2013, I wanted to see something similar in Python.
- 26:56So like pep484 came out, you know, soon enough, Python 3 started getting adopted more and more. And,
- 27:02And this is when annotations, which are the nice way to express types, have been gaining adoption.
- 27:09And these days, from what I've heard at the conference now, 90 % of functions in the Instagram code base, which is north of 2 million lines of code at the moment, is covered in types, which is amazing.
- 27:23That is a big achievement.
- 27:25So definitely, this trend is on the rise, which I am very happy about.
- 27:30Yeah, that's awesome.
- 27:31Anthony, what are your thoughts on type hints, type annotations?
- 27:34And do you like them?
- 27:35Have they changed your code?
- 27:36Do you use them?
- 27:37I actually use them very rarely.
- 27:39In 3 .7, there's the type annotations, the delayed evaluation type annotations.
- 27:45Yeah, it's gotten a little nicer in that way.
- 27:46In 3 .7, which makes it a bit easier in terms of what you have to import and when.
- 27:51But the only reason I use them seldomly is because I mainly work on libraries which I publish to PyPI,
- 27:58which are used by people who have Python 3 .5, 3 .6, and some 2 .7 as well.
- 28:04So I really have to cover the lowest common denominator when it comes to users
- 28:08because they're mainly utility libraries that I work on,
- 28:11not sort of single deployment applications.
- 28:15Yeah, or something like Black that doesn't really get consumed directly,
- 28:19but it's more executed, right?
- 28:21Like Black or pytest or something.
- 28:22Yeah, interesting.
- 28:23What's the next one?
- 28:24All right, so the next PEP would be PEP 585
- 28:28that I actually wrote.
- 28:30Well, it's still in draft form.
- 28:32So to kind of set the stage for the PEP, what Anthony said is like there's plenty of cases
- 28:37where currently typing that was added rather carefully to the language requires you to
- 28:44import names that you're later using as types.
- 28:47There's some situations where you are introducing names to your global scope just for type aliasing
- 28:53or to introduce type variables.
- 28:56Right.
- 28:56For example, if you've got a function
- 28:58and you want to say its return type is this
- 29:00object,
- 29:00you now have to import at the top.
- 29:02If you had never actually had that part called,
- 29:04maybe it would have never been imported until lazily.
- 29:07There's changes in behavior because of that, right?
- 29:10Yeah, this is often problematic, right?
- 29:12Like what is
- 29:13even more like just cumbersome for the user
- 29:15is that there is plenty of either built -in types
- 29:18or abstract -based classes
- 29:20that have their equivalents in the typing module,
- 29:23meaning if you want to express that some argument is a list of string,
- 29:27you have to import an uppercase list from the typing module
- 29:30and say uppercase list of string.
- 29:33And I always found that clumsy, right?
- 29:35I always found that it is something new that you have to explain
- 29:39to new programmers that are first interacting with typing.
- 29:43And there's not really a great reason for that.
- 29:45We wanted the actual lowercase list to be orthogonal
- 29:50and not know anything about the static typing concept,
- 29:53which is mostly used by an external type checker.
- 29:56It does not have a big runtime component.
- 29:59It does have a little, right?
- 30:00Because you can inherit from generic types.
- 30:02So you can actually create your own data structure
- 30:05where you say that this is, I don't know,
- 30:07a collection of types T, right?
- 30:10So that this is a possibility.
- 30:12But for very many cases,
- 30:14this runtime component is just a hindrance.
- 30:16It's something that you have to remember to import.
- 30:18The names look different
- 30:19because they're uppercase and lowercase.
- 30:22They might look exactly the same in form of set, but they actually mean something else
- 30:26now.
- 30:27Because the point being, so that's the first issue.
- 30:30And the second issue is that this is something that sits in memory, right?
- 30:34This is something that you spend time on when you're starting up your program.
- 30:38So I always felt like this is something that we can maybe live without.
- 30:43Hence PEP 563, which actually postpones evaluation of annotations.
- 30:48That was introduced in Python 3 .7.
- 30:50And stemming from that, you know, having that foot in the door that like now the annotations
- 30:56are not evaluated anymore, we can regain some of the usability that people expect just by
- 31:02the fact that this can be still valid Python syntax, but it doesn't have to be valid at
- 31:06runtime.
- 31:07So we can get away without importing things from typing.
- 31:11You know, the type checker will know exactly what you mean anyway, right?
- 31:14We can come back to using a lowercase list of string instead of uppercase list of string
- 31:20And a few other things.
- 31:22You still do the bracket of string?
- 31:24Yes, yes.
- 31:24But on the lowercase list type?
- 31:25Yeah, so we will never do pointy brackets for that,
- 31:29like in Java or C++,
- 31:32because our LL1 parser is unable to deal with that case.
- 31:37Maybe if we switch to a different one,
- 31:38of which there is discussion,
- 31:40maybe then that would be possible.
- 31:42But at that point, it will still be way too late.
- 31:45Yeah, I think it's
- 31:46fine the way it works.
- 31:47It's different, but it's just totally...
- 31:48It's different, but it's a way of expression.
- 31:50There's nothing that makes the angle brackets in templates or generics necessarily the right way, yeah?
- 31:56Yes, exactly. It's like as long as humans understand what those
- 32:00things mean, the goal has been achieved.
- 32:03So yeah, the rest of the PEP 585 is just an attempt to reform some of the pre -existing constructs in the typing module,
- 32:13like creating new types, casting, aliasing, or type variables
- 32:18into variable annotations so that they are also not evaluated at import time,
- 32:23which enables, again, usage of types that are not imported
- 32:27and some of those tricks with syntax like lowercase list and dict and whatnot.
- 32:31So that's 5 .8 .5.
- 32:34While we're on this performance and type annotations and stuff,
- 32:38what's the story of mypyc?
- 32:40Oh, this is actually a very interesting story.
- 32:42So mypy has traditionally been slow,
- 32:46to the point where running it
- 32:48over the entire Instagram code base
- 32:50was taking over five minutes, right?
- 32:53So this was a thing that you could do
- 32:54in continuous integration,
- 32:56but you could not absolutely run it
- 32:58in an editor or whatnot.
- 32:59We had some hacky workarounds
- 33:01to at least make people in the editors happy.
- 33:04I wrote a silly flake 8 mypy plugin
- 33:06at some point that kind of brought us somewhere
- 33:09it was useful for a while.
- 33:11But all of that was just not very great.
- 33:13So in the meantime, mypy started implementing incremental typing,
- 33:17meaning the graph of your modules, which did not change,
- 33:21can be cached so that with every change,
- 33:24like most of your computation is already pre -done.
- 33:27And that is evolving to this point now.
- 33:30With well -populated cache, that cuts the time to around 40, 50 seconds.
- 33:34So it's like a six, seven times
- 33:37improvement.
- 33:37Yeah, it's a big improvement.
- 33:39So that's good.
- 33:40but still the cold type checking was like rather slowish.
- 33:43In the meantime, Facebook started developing its own type checker for Python.
- 33:47Well, more with the goal of creating a static analysis tooling that just uses types.
- 33:52So the type checker part was only the base of the static analysis that was being performed
- 34:00on that very code with the important use case of doing security checks.
- 34:06And one of the goals of that, you know, new type checker was like, we have to be faster
- 34:11than mypy, right?
- 34:12Yeah.
- 34:12Like, so that created competition and competition is always good.
- 34:15So in the meantime, like, Yuka Lektostalor, like, revived his original idea that, hey,
- 34:20if we have types, we can actually try to compile the Python code in a way that runs it way faster
- 34:28now.
- 34:28What does it compile to?
- 34:29So that's interesting, right?
- 34:31So the mypyc compiler actually creates a C extension.
- 34:36It actually transpiles to C.
- 34:38This sounds weird until you think about the C API that Python provides.
- 34:43And the Python C API is meant to be consumed by C.
- 34:46So it is just natural that you would have a generator that emits valid C for your given use case.
- 34:52And it turns out that with just a few constraints on how your program works,
- 34:57you can achieve 20 to 30 times performance boosts with that.
- 35:02So that's great.
- 35:03And in a real production application like mypy, it's consistently four times faster.
- 35:11This portion of Talk Python is sponsored by Microsoft and Visual Studio Code.
- 35:15Visual Studio Code is a free, open -source, and lightweight code editor that runs on Mac,
- 35:20Linux, and Windows with rich Python support.
- 35:22Download Visual Studio Code and install the Python extension to get coding with support
- 35:26for tools you love like Jupyter, Black Formatting, Pilot, pytest, and more.
- 35:30And just announced this month, you can now work with remote Python code bases using the new Visual Studio Code remote extensions.
- 35:38Use the full power of Visual Studio Code when coding in containers, in Windows subsystem for Linux, and over SSH connections.
- 35:45Yep, that's right. Auto completions, debugging, the terminal, source control, your favorite extensions.
- 35:50Everything works just right in the remote environment.
- 35:53Get started with Visual Studio Code now at talkpython .fm slash Microsoft.
- 35:59Do
- 35:59you see use cases for that outside just mypy, like random person doing data science
- 36:05that needs their Python parts to go faster?
- 36:08Currently, mypyc tries
- 36:10to limit their scope since they perceive the attempts by previous
- 36:15projects that meant to speed up Python.
- 36:18Those attempts failed mostly on trying to be 100 % compatible with every single feature
- 36:24of Python.
- 36:25So they're focusing on a subset.
- 36:27but they're growing that subset as much as they needed.
- 36:31And the big missing piece currently is there is no async await support.
- 36:36And with that support, I could actually have black compiled,
- 36:40which could also
- 36:41significantly speed up the formatter,
- 36:44which is already pretty performance, already does pretty well.
- 36:48But that would just make it so much better for the users.
- 36:50So in fact, I think I managed to get Sully, the core developer of mypyc,
- 36:56rather excited about the prospect of having
- 37:00Black as the next production customer of MyPayC. So we'll
- 37:04see. I have my fingers crossed. Yeah, that's exciting. All right, Anthony, what's the next
- 37:08one on our list of cool features in 3 .8? So
- 37:10this one is actually still in draft. It hasn't actually
- 37:13been decided and potentially might be deferred to a later release if it gets accepted. But when I've
- 37:19talked about features, at least proposed preps, this one gets quite a bit of attention and they're
- 37:24runtime audit hooks. And basically the PEP is a way of setting a callable when certain
- 37:32system methods within the Python standard library get called. For example, opening a network socket
- 37:38or requesting a URL or opening a file or lots of different cases, I guess, of sort of low -level
- 37:45standard library functions or methods. When they get called, then you get notified.
- 37:50That's super cool. So like if for some reason I'm in a lockdown environment, I want to use some package or write some app and it's, we think it's not talking to the network or the file system, but it turns out all of a sudden it's opening sockets or DNS stuff. That might be something to inspect.
- 38:08Yeah. So potentially you could lock down a Python distribution or a Python process to not be able to open certain URLs or open network sockets under certain circumstances.
- 38:19And it's
- 38:20cool. So with the hooks, do I get to say,
- 38:21I
- 38:22saw what you did and okay, or I saw what you did and no, you don't get it. Is it like a place to stop it?
- 38:28Yeah. The
- 38:29default is just as an FYI. But if you wanted to raise a runtime error or something else in line, then it would actually stop the request through to the function.
- 38:40That's pretty awesome. I think this is pretty interesting. I know there's some restricted environments and even like app stores and stuff that maybe it would be cool to package this up and use it. So yeah, definitely nice. Lucas, what do you think about this one?
- 38:51Well, I actually think this
- 38:53is very important. If you ever worked for a break on an organization, very often the audit trail of what actually happened is important, not just for security reasons. Very often, cascading errors that end up with an entire site being down are very hard to foresee.
- 39:09like you know the very easy to make mistakes or like long fix they're all patched like you know
- 39:16there's not a big red switch that if you just press the button you know the site goes down it's
- 39:20very often something that it was hard to you know combine and having the trail of oh this happened
- 39:27first and then another thing happened later like that is very valuable so i see this feature not
- 39:33only as a security feature but as just you know like a post -mortem kind
- 39:37of feature as well that's
- 39:39Anthony, do you envision this might enable a different set of tooling?
- 39:44We have visual debuggers now.
- 39:46Could you maybe have other types of analysis and tooling and whatnot?
- 39:51Yeah, in terms of tooling, I guess there's a lot of things in the standard library that you might want to add hooks in.
- 39:57And also an easy way of putting hooks into additional modules as well.
- 40:01And then having people to catch those and deal with those separately.
- 40:04I can definitely think of a few examples of libraries, deserialization libraries, not naming any specifically, that have …
- 40:13Rhymes with sickle?
- 40:15That have security backdoors, just in terms of the way they work.
- 40:19So unless you explicitly specify to load it with a safe mode, then you can actually run …
- 40:25That was a different one, a different rhyme maybe.
- 40:27Oh, okay.
- 40:27Yeah, XML
- 40:29as well is another one.
- 40:30Yeah, yeah.
- 40:30There are sort of known, I guess, security backdoors in certain libraries,
- 40:35and basically this could be a way of protecting against those.
- 40:37Okay, yeah, that's great,
- 40:38because it should not be doing these operations while loading this file.
- 40:42Yeah, if you're loading a YAML file or an XML file,
- 40:45it shouldn't be opening network sockets.
- 40:48Yeah, probably not, or issuing sub -process commands
- 40:52or any of these not -so -lovely things.
- 40:55All right, Lucas, what's next on our list?
- 40:57I would like to just say that there's quite a few
- 40:59peps
- 41:00are still in draft form and the authors have like an entire four more weeks in which they can decide
- 41:05to finish their PEP and publish it so things might change but the ones that i'm like personally
- 41:09interested in is always of course typing so let me just cover two more like the first one is pep
- 41:16586 so that's literal types and second one is 589 which is typed dict both of them are kind of an
- 41:23example of you know our type system kind of starting uh conservatively and then growing
- 41:29based on need, right?
- 41:30So literal types are very interesting
- 41:32because there are a bunch of calls
- 41:34where the behavior, like the return type
- 41:37or the cascading other arguments
- 41:40that you're going to use in the function
- 41:42depend not on the type of an argument,
- 41:45but on the actual value that you are passing.
- 41:49Like a positive integer, negative integer,
- 41:51something like this, or what?
- 41:52So parametric types are kind of hard,
- 41:54but what we're doing with literal types
- 41:55is something like the open built -in.
- 41:58Like with the open built -in, you have a certain number of modes, right?
- 42:01And depending on whether you're saying RB or R,
- 42:04the resulting IO is either bytes or strings.
- 42:08And currently, there is certain hackery both in mypy and Pyre
- 42:12to just, you know, work around this.
- 42:14But it would be good if the actual type system supported this feature.
- 42:18So literal is all about being able to express those types
- 42:22so that if you pass none here, it's going to behave differently.
- 42:26If you pass on string here, it's going to behave differently if that string is RB or is WB or is R and so on and so on.
- 42:36So that's literal types.
- 42:38There's some very, very interesting edge cases and deep thought in that PEP.
- 42:44It is surprisingly long and complex.
- 42:46I'm not going to go into this now.
- 42:48The other one is though, type dict.
- 42:51Originally, dictionaries have been envisioned in the static typing as, oh, there's this key value store.
- 42:59So there's keys of a certain type and there's values of a certain type.
- 43:03What happens in practice is that a lot of pre -existing Python applications do not use named tuples,
- 43:09do not use attrs or data classes, which are very new.
- 43:13So instead, they use kind of lightweight classes in the form of dictionaries that have keys and values of various types.
- 43:23So there can be name, which is a string, but there can be a birth year, which is going to be an int, right?
- 43:30And based on the actual name of that key, you're going to have different types.
- 43:35So that was very cumbersome to express in the previous form.
- 43:40Almost like a schema, yeah.
- 43:42Yes, it's like very much like schemas.
- 43:44So now like there is a way to describe a type dictionary
- 43:48in the form of like a data class -like type,
- 43:52like where you just express it like, you know, class -like saying,
- 43:55this dictionary is going to have keys that are like this,
- 43:58and this key is going to be a string, this other key is going to be an int.
- 44:03That solves already a lot.
- 44:04But like then the interesting part is when those things start nesting.
- 44:09That actually enables you to construct like rather complex schemas
- 44:13that can be used directly in JSON or, you know, in other forms of serialization.
- 44:18So that PEP alone is also very useful in practice.
- 44:21Even though you could just say like people are doing it wrong,
- 44:23they should be using, you know, name tuples or other forms of typing instead.
- 44:27Well, you kind of have to be pragmatic, you know,
- 44:30like you see pre -existing valid
- 44:32use cases of this
- 44:33and you have
- 44:34to just adhere to those.
- 44:35Yeah, interesting.
- 44:36I guess since you're really into typing and you're on the core dev side of things, what do you think about libraries, especially I'm thinking of like web frameworks that use typing for like serialization and stuff?
- 44:51So like Molten, for example, you can have a class that has fields, but also those fields have types.
- 44:59And then you say this web function takes this class, but it's like really a form submission.
- 45:05and it'll like convert stuff to integers or like validate against the types.
- 45:09Is that in your mind awesome or is that an abuse of the type system?
- 45:13So this is interesting, right?
- 45:14Because obviously as long as
- 45:16the type system is kind of an extension of the type system
- 45:20we're using for type checking, or maybe it's even exactly the same, like that is using a
- 45:24shared vocabulary.
- 45:25That's great.
- 45:26Like, you know, we support that.
- 45:27Like we would wish to see type hints in more places.
- 45:31In fact, in 3 .7, I extended single dispatch so that now you can just use annotations on arguments instead of saying, you know, register off and like you can just say register and using the annotations of the first argument, it'll behave like, you know, as you expect.
- 45:48So you can use type annotations at runtime for whatever you want, as long as the type
- 45:54system is kind of, you know, the same with what we're using it for.
- 45:58Some use cases use annotations, function annotations in incompatible ways.
- 46:03And that creates issues because an increasing amount of tooling like Visual Studio Code,
- 46:08you know, PyCharm and whatnot, like gets confused by seeing something that, you know, is clearly
- 46:13not a type in the place where types are expected.
- 46:16So I kind of, yeah.
- 46:17Yeah, an example of that.
- 46:19So this example I gave you with Moulton seems like it's consistent.
- 46:22The type checker says it takes an int.
- 46:24It's actually an int at runtime.
- 46:26But I can't remember, but some of the other frameworks, maybe REST frameworks,
- 46:30they would say like you could say that this parameter is a header.
- 46:34And what it actually is the string value with that name out of the header.
- 46:39It's like the value comes from the header.
- 46:40But at runtime, it's not a header.
- 46:43It's not a dictionary.
- 46:43Whatever the header is, it's actually a string or an int or something.
- 46:47Yeah, I see.
- 46:47It seemed like it was really cool and clever,
- 46:49but also like incongruent with what Python intended.
- 46:52A certain amount of those things
- 46:54like our valid use cases,
- 46:56like let's say in the case of attrs,
- 46:58adders like
- 46:59create valid classes for you
- 47:02from minimal information that you provide in source code.
- 47:05So this class is being fully functional at runtime.
- 47:09However, the type checker does not know this.
- 47:12It just sees like just some magic decorator
- 47:14and just this minimal set of attributes on it.
- 47:17And it does not know that a certain amount of built -in methods have been created
- 47:23and a certain amount of functionality within it and whatnot has been added.
- 47:27So at least in the case of mypyEmpire,
- 47:30additional functionality had to be implemented in those type checkers
- 47:34to understand that those types actually behave a bit differently from regular classes.
- 47:40But that's just something that users want, something that users need.
- 47:43And so based on that, we're going to be extending that.
- 47:46All right, cool, cool.
- 47:48Anthony, what do you got next on our list here?
- 47:49There's actually everything we have for 3 .8.
- 47:51All right, so ship it,
- 47:52we're good?
- 47:53Yeah, I think we're done now.
- 47:54So actually that PEP in particular, the type dictionary PEP,
- 47:58I've been thinking if anyone's in the JSON schema project,
- 48:01it's really cool.
- 48:02It's basically a way of defining a schema for JSON documents.
- 48:07You can definitely see that if this PEP gets accepted,
- 48:09somebody will build tooling to integrate between the JSON schemas and this new type dict type.
- 48:16Yeah, and it makes perfect sense.
- 48:17I mean, dictionaries are so similar to JSON in a sense,
- 48:21and they both have this sort of dynamicness but mixed types.
- 48:24I mean, they're very, very sort of mappable, yeah?
- 48:27Yeah, so I think it's just a matter of time until someone builds a library
- 48:30where you give it a JSON schema and it will generate a type dict class,
- 48:34and then you use that class.
- 48:35Similar in the same way that you in an ORM, when you would describe like a data class,
- 48:41and then you would deploy it as a database.
- 48:43It's basically like a similar way of reflecting documents.
- 48:46That's cool.
- 48:46I can definitely see it for serialization.
- 48:48Like you say, this function takes a type dict, but what actually it is a form post or a JSON post
- 48:54or like a REST call or something like that.
- 48:56That's cool.
- 48:56So let's see.
- 48:58Did we talk about multiprocessing?
- 49:00Is that coming in 3 .8 or is that beyond?
- 49:02That's in 3 .8.
- 49:03So one particular thing that is not PEP -worthy, but it's still a very interesting new feature
- 49:08is that traditionally multiprocessing, which has been created to solve the gil problem,
- 49:14has solved it partially.
- 49:16What I mean by this is that, yes, there is a master process that creates a bunch of children
- 49:21and then delegates work to it.
- 49:23So you can just call Python functions and those Python functions actually are executed
- 49:28on the other side in the child process.
- 49:30But the way this is achieved was that function call has been pickling the arguments of the function you're calling.
- 49:38That ended up being on the child side.
- 49:41That child unpickled the arguments.
- 49:43It did the computation it needed.
- 49:45And then if there was a return value it wanted, it actually had to pickle that return value again and pass it back to the master process.
- 49:52And the master process unpickled the return value again.
- 49:55And if that's big, it's very slow, for example.
- 49:57Exactly.
- 49:57So like for small things, that was mostly fine.
- 50:00But if you had like a gigantic haystack and you were looking for a needle in it, just, you know, pickling that haystack was taking.
- 50:08And then I'm picking on the other side was taking a lot of time.
- 50:11We were going to run that on all six
- 50:12cores.
- 50:13So here's six copies of our like 10 megabyte, whatever.
- 50:17That is
- 50:17actually annoying because like if you had like a master process that say it gets web requests, right?
- 50:24In the time that you're spending on pickling that haystack, nothing else can be actually done in Python because the gil is still there on that master process.
- 50:35So you are solving the gil problem only partially.
- 50:38So now multiprocessing introduces this new fantastic feature where you can declare a shared memory segment and share that memory between parents and children.
- 50:50What that does is you can actually get away with a lot of serialization and deserialization.
- 50:57So for certain kinds of tasks like search, like filtering, this will decrease the churn just needed to pass data around.
- 51:06Meaning it will bring us way closer to the world we want to see, which is that, yes, there are certain Python processes.
- 51:13They still have the gil, but it does not matter because we can use as many of those processes as we have cores and everything is fine.
- 51:19Yeah, and you don't have the replication of memory and the copying and all that.
- 51:22That's awesome.
- 51:23Yes.
- 51:23So I'm really excited when I saw that come out.
- 51:25I'm like, oh, this is going to be great.
- 51:26So that's in 3 .8?
- 51:27Yes, that is already in.
- 51:28Cool.
- 51:29And what about the subinterpreter 5 .5 .4?
- 51:33That's beyond?
- 51:34Oh, so that's interesting.
- 51:35That is kind
- 51:36of related.
- 51:36Yeah, they're in the same category of things.
- 51:38Yes, however, the multiprocessing feature does have limitations, right?
- 51:42Like the shared memory segment is not right for any arbitrary Python object.
- 51:47There's like, you know, restrictions on what types you can use.
- 51:50That was actually a complex functionality to be added, you know, within particular operating
- 51:55systems, shared memory handling is way different.
- 51:57So you have to understand how those differences work and which process is now responsible for
- 52:03creating that shared memory segment and shutting it down and freeing that memory when everything
- 52:08is, you know, shutting down.
- 52:09So that is all great work by Davin Potts.
- 52:12Like, multiprocessing is one thing, but subinterpreters is what if you had this multiprocessing API and actually just had one process and just used many Python interpreters within it, each with its own gil.
- 52:25To achieve that, many changes in the Python C API have to be added.
- 52:28Like, you know, a much cleanup internally in terms of what constitutes local and what constitutes global state have to be done.
- 52:36Eric Snow is working hard on that.
- 52:38As far as I can tell, this is deferred to Python 3 .9.
- 52:42I'm eagerly awaiting that.
- 52:43I think this is going to be a great improvement.
- 52:45Yeah, it could definitely change the threading story.
- 52:48In multipress processing strong in Python, async await is super cool for IO bound stuff.
- 52:55But threads have always been a kind of, well, sometimes they're helpful, sometimes they're not.
- 52:59It depends.
- 53:00And this could be awesome, right?
- 53:01You could just dedicate a sub -processor, a sub -interpreter, excuse me, to each thread, right?
- 53:06And really get free of that.
- 53:08I agree.
- 53:08Cool.
- 53:08All right. Well, thank you both for sharing what's coming. Pretty excited about 3 .8.
- 53:15Cool. That was a pleasure.
- 53:16Yeah, it's going to be great.
- 53:17Yeah. And on that topic as well, I guess we've got 3 .9. So, some of the PEPs are being deferred
- 53:22to 3 .9. And on the topic of sub -interpreters, the unpacking of the startup sequence,
- 53:27and also the initialization configuration, there's two proposals for that. One is PEP 4 .3 .2,
- 53:33and the other's PEP 587, which are interrelated
- 53:37because if you have sub -interpreters,
- 53:38you want the interpreter startup time to be fast
- 53:41and also the configuration to be flexible.
- 53:43So I think 3 .9 will definitely see
- 53:46some more proposals related to that.
- 53:49Awesome.
- 53:49Which are going to hopefully improve the startup time of Python 3.
- 53:53As we know, it's a little behind where Python 2 was
- 53:56for various reasons, but that'll be a great step forward.
- 53:59Yeah, that'd be really awesome.
- 54:00And then it also might make this sub -interpreter stuff
- 54:03better if those little sub interpreters can get created faster as well. I don't know how related
- 54:07they are, but pretty cool. Pretty cool. All right. One, we used up almost all our time,
- 54:12so I won't keep you guys much longer, but especially Lucas, let me ask you this, like,
- 54:16will there be a Python four and does it matter? I mean, on one hand, like we've got stuff that's
- 54:210 .1, two versions that have been around for 10 years with a hundred releases. We've got Python
- 54:28three. If we don't have like major breaking changes, is there a reason to start calling it
- 54:32four and five and six, or is that just going to like scare people with the history or like,
- 54:37what do you, what's your perspective here?
- 54:38We are at Python 3 .8 now. We're about to release 3 .9
- 54:43later, you know, another 18 months later. Historically, Guido expressed his distaste with
- 54:49numbers after the decimal point that have more than one digit. And so he disliked the notion of
- 54:57having 2 .10, 2 .11, and same with 3 .10, 3 .11. However, we have both philosophical and technical
- 55:05challenges with just releasing a Python 4. Well, the obvious philosophical one is that
- 55:11the transition between Python 2 and Python 3 was very, very challenging, right? It took us a lot
- 55:16of effort. And there's a lot of fatigue,
- 55:18I think, in the
- 55:19community to just not go through that again
- 55:21for a while. Absolutely. Our closets are still full of skeletons. So we are really trying hard
- 55:28not to make that mistake again. It's not only a problem for the users, it was also unpleasant and
- 55:34a problem for the core developers. So we are really careful to make changes in a very incremental
- 55:40manner now and communicate them well and make them gradually so that we are disrupting our users
- 55:46the least, which just means calling something Python 4, well, would probably be just scary on
- 55:53its own, just on the power of that number. But just more practically speaking, because of this
- 55:58Python 2 and 3 transition, there is a ton of code in the wild that does checks exactly for the number
- 56:043 in sys version, version info. And those checks would, you know, become invalid if we introduced
- 56:11python 4 like which is one of the reasons why you know like Linux had problems when it suddenly
- 56:17became Linux 3 and why we have windows 10 now just for that practical reason i do expect that we're
- 56:24gonna see python 3 .10 first at least before we ever decide to call the next release python 4 yeah
- 56:31yeah
- 56:31so 3 .10 is way more likely maybe we should call it python 6 because then it's like two times three
- 56:37Well, I was wondering if there's a proposal to introduce calendar versioning to Python.
- 56:41Oh, yeah.
- 56:41What do you think about calendar versioning?
- 56:43If Python 2 .7 was called 2014 .1, then maybe people would reconsider.
- 56:48Really?
- 56:492014?
- 56:50What's up here?
- 56:50We just upgraded from 2013.
- 56:53It would certainly remind people how old their Python distribution is.
- 56:55So maybe they'll upgrade faster.
- 56:58That's funny.
- 56:58Well, I'm in no power
- 56:59to just make that change.
- 57:02I could be in power to create a PEP about it.
- 57:04but this is probably not a sword I'm willing to fall on.
- 57:08However, let me tell you this,
- 57:10all of my private projects do use calendar versioning.
- 57:13That's the only versioning that I am familiar and comfortable with.
- 57:16There's obviously semantic versioning,
- 57:18but I don't know about others,
- 57:19but at least I don't see myself being as strict
- 57:23and consistent with applying semantic versioning every time.
- 57:26What does it
- 57:26mean to push the major version versus minor version?
- 57:29Yes,
- 57:30so obviously there's rules,
- 57:31but the devil is in the application.
- 57:33Do you apply those rules consistently and every given time?
- 57:37I wrote an auto formatter because I was not able to apply rules of code styling consistently and every time.
- 57:44So I don't trust myself enough to do the same for semantic versioning.
- 57:48And if I'm not doing that, then my users cannot depend on what they expect from semantic versioning.
- 57:53Hence, just using calendar versioning is way easier, adopted by many popular projects like Ubuntu, like Twisted, like others.
- 58:01Yeah, I love the calendar versioning.
- 58:02I don't know that it makes sense for like the main Python.
- 58:05Maybe, maybe it does, maybe it doesn't.
- 58:07It would be effective on showing how old some stuff is.
- 58:10But certainly I feel like semantic versioning requires, like on libraries, it requires some expertise in that library.
- 58:17Like I depend on library A.
- 58:20It depends on library B.
- 58:21I see that when I pip installed it, it's 0 .1 .3.
- 58:26Six months later, is that out of date?
- 58:28I have no idea.
- 58:29Like I don't even know like roughly how old that is.
- 58:32But if I saw the calendar version on all the dependencies or stuff I'm not super familiar with, I'd be like, oh, yeah, this is actually, this is pretty much new or it's old.
- 58:40Like, it just, it makes it easier for newcomers, I think.
- 58:43Yeah.
- 58:44All right, guys.
- 58:44Thank you for being on the show and sharing all this and looking forward to when you actually release 3 .8.
- 58:48I'm looking forward to that, too.
- 58:50Thank you very much.
- 58:50I can imagine.
- 58:51Thanks, Michael.
- 58:51Yeah, bye.
- 58:53This has been another episode of Talk Python To Me.
- 58:56Our guests in this episode have been Lucas Lenga and Anthony Shaw.
- 59:00And it's been brought to you by Microsoft.
- 59:02If you're a Python developer, Microsoft has you covered.
- 59:05From VS Code and their modern editor plugins, to Azure Pipelines for Continuous Integration,
- 59:10and serverless Python functions on Azure.
- 59:13Check them out at talkpython .fm slash Microsoft.
- 59:17Want to level up your Python?
- 59:19If you're just getting started, try my Python Jumpstart by Building 10 Apps course.
- 59:24Or if you're looking for something more advanced, check out our new async course that digs into
- 59:28all the different types of async programming you can do in Python. And of course, if you're
- 59:33interested in more than one of these, be sure to check out our everything bundle. It's like a
- 59:37subscription that never expires. Be sure to subscribe to the show, open your favorite podcatcher
- 59:42and search for Python. We should be right at the top. You can also find the iTunes feed at slash
- 59:47iTunes, the Google Play feed at /play and the direct RSS feed at /rss on talkpython .fm.
- 59:54This is your host, Michael Kennedy. Thanks so much for listening. I really appreciate it.
- 59:58Now get out there and write some Python code.