Latest / Talk Python To Me / #180: What's new in Python 3.7 and beyond
Transcript
- 0:00The Python core developers recently released Python 3.7 and are now busy planning what's coming in 3.8.
- 0:05That makes right now a great time to dig into what's included in Python 3.7
- 0:09and see what's on deck for this next great release of CPython.
- 0:13On this episode, we have Anthony Shaw back on the podcast to tell us all about it.
- 0:18This is Talk Python To Me, episode 180, recorded October 1st, 2018.
- 0:22Welcome to Talk Python To Me, a weekly podcast on Python, the language, the libraries, the ecosystem, and the personalities.
- 0:42This is your host, Michael Kennedy. Follow me on Twitter where I'm @mkennedy.
- 0:46Keep up with the show and listen to past episodes at talkpython.fm.
- 0:50And follow the show on Twitter via at Talk Python.
- 0:53Hey everyone, Michael here.
- 0:55Just a couple of things to share before we get to our chat with Anthony.
- 0:58First, you might notice I sound slightly different this week.
- 1:01I've been experimenting with a new audio setup.
- 1:03Your feedback on whether this is actually an improvement is welcome.
- 1:06Just send me a mention on Twitter via at mkennedy or at Talk Python.
- 1:10Second, I recently released a new course and this is one I've wanted to create for a long time.
- 1:15It's called Asynchronous Techniques and Examples in Python.
- 1:18This is the definitive course on asynchronous programming in Python.
- 1:22It starts out right away digging into the asyncio and the magical async and await keywords.
- 1:27We also discussed the time-tested techniques such as threading and multiprocessing.
- 1:31But we don't stop there.
- 1:33Once you're using threads, you need thread safety.
- 1:35Covered.
- 1:36Want to write some async web apps with Flask using async and await.
- 1:39Covered.
- 1:40We even discussed some ways to combine these techniques for when you have some mixed CPU-based work and some IO-based work.
- 1:46We round out the course with leveraging Cython to make our threaded code go truly fast.
- 1:52If you're interested in this course, just visit talkpython.fm/async.
- 1:56And if you act quickly enough, you can still grab the early bird discount.
- 1:59Now, let's talk Python present and future with Anthony Shaw.
- 2:02Anthony, welcome back to Talk Python.
- 2:05Hi, Michael.
- 2:06It's great to be back.
- 2:06Yeah, it's super to have you here.
- 2:08It's great to have you on as a regular.
- 2:10You're doing so many cool things.
- 2:11Thanks.
- 2:11Yeah.
- 2:12So just to let people know, you were on way back in episode 155 for Practical Steps Moving
- 2:17to Python 3 and also in 168 for 10 Security Holes in Python.
- 2:22Those were both fun episodes.
- 2:23But we're kind of not just upgrading to Python 3.
- 2:26We're cutting edge at this point, right?
- 2:28Yeah, we're going all the way up to 11.
- 2:31This one goes to 11.
- 2:32Awesome.
- 2:32Well, I'm definitely looking forward to doing that.
- 2:35But before we get into all the details of Python 3.7 and 3.8 and the speculation around there,
- 2:40let's just talk really quickly about what you do day to day so people know where you're coming from.
- 2:45Great.
- 2:45Yeah, sure.
- 2:46I work at Dimension Data.
- 2:48It's a big IT company.
- 2:50And I actually work in HR, which might surprise a few people.
- 2:53As I came from an R&D background and a couple of years ago, I made a big career change.
- 2:58So I focus on learning now.
- 3:00Similar to you, I guess.
- 3:02And skills development within the organization.
- 3:05Yeah.
- 3:05And just so people know, that's not like a team of 10, right?
- 3:08There's more than 10 people, I think, that take some of these programs you put together and stuff.
- 3:12Yeah.
- 3:12So we're about 31,000 employees.
- 3:14And I've been running a whole bunch of learning programs and stuff like that,
- 3:19trying to teach people Python, for example.
- 3:21About 4,000 people are learning Python that work for us across the world, which has been fantastic.
- 3:27And running a whole bunch of other programs as well.
- 3:29We're basically trying to make sure that the skills of the people who work at the company
- 3:33are up to date with all the latest technologies.
- 3:35Wow, that's really cool.
- 3:36And you've done some good write-ups.
- 3:37Maybe I'll even link to them in the show notes.
- 3:39So that's your day-to-day.
- 3:41But then when maybe you're on an airplane or you're traveling,
- 3:44you decide to break out some massive open source contribution, something like that?
- 3:48Yes.
- 3:48So I have to travel quite a lot for my job, which means I spend a lot of time on the planes,
- 3:55really quite bored.
- 3:56And there's only really so many Marvel movies you can watch.
- 3:59So really, I kind of feel some time working on open source projects involved in quite a few at the moment.
- 4:06So all of them are Python.
- 4:08They were a range of different languages a few years ago, but now I'm 100% Python contributions only.
- 4:14So that's been excellent.
- 4:15And the Apache Software Foundation just got named as a PSF fellow a couple of months ago, which was awesome.
- 4:23Yeah, congratulations on that.
- 4:24That's really awesome.
- 4:25Only five people per quarter get that honor.
- 4:28And so that's a big deal.
- 4:29That's cool.
- 4:29Yeah, I don't really know what I did to get that.
- 4:31But it was really great to be among the amazing list of names of people who are on the list.
- 4:36Yeah, that's awesome.
- 4:37Cool.
- 4:38Well, our topic for today is Python current and beyond, right?
- 4:44At least the time of this recording, people go back far enough in time.
- 4:47Maybe they'll hit 3.7 or something in the past.
- 4:49But we're going to start by talking about what is cool in Python 3.7 people should pay attention to, they should learn about.
- 4:56And then we're going to talk about what's coming in the next version of Python 3.8.
- 5:00So let's start with Python 3.7.
- 5:02Like, is it a big change?
- 5:03What do you think?
- 5:04I guess you kind of have to bring in the whole history of, well, not the whole history of Python 3.
- 5:09But you have to kind of take a bigger lens to this because Python 3 has been out for 11 years now.
- 5:15Is it 10 years, 11 years?
- 5:17Since 2008, I believe.
- 5:19It was just 3,000 days, like a year ago or something like that.
- 5:23So yeah, it's been about 10 years.
- 5:27But no offense to the developers who worked on it.
- 5:30But the first few releases weren't really production ready.
- 5:33So 3.0 to 3.3 were really where they introduced a lot of the major changes in Python 3.
- 5:40And there were a lot of stability issues.
- 5:42And there were memory leaks and stuff like that that needed to be fixed.
- 5:46Also performance, right?
- 5:47Like a lot of people said, well, I need to do this thing.
- 5:49And this thing is like 50% slower in Python 3.
- 5:52So I'm not doing it.
- 5:53Definitely.
- 5:53There's some major changes in Python 3 which made things significantly slower in some of the earlier releases.
- 6:00But really, the focus was, let's not just spend 10 years and then ta-da, we've come out with something that's production ready.
- 6:07They wanted to get something out there and get the feedback earlier on.
- 6:10So even though Python 3 has been out for a decade, I guess the stable releases have only been out for the last four years, five years now.
- 6:18So 3.4 was pretty stable.
- 6:21But 3.5, definitely, that's where you sort of get picked up by some of the major Linux distributions.
- 6:26For example, it starts to get packaged with operating systems and stuff like that.
- 6:30Yeah, that's a great point because I feel like 3.5 is really where it was clearly the right choice.
- 6:36Like 3.4, there was a debate at that time.
- 6:38It was like, well, maybe, maybe not.
- 6:39At 3.5, it was like, what are you talking about?
- 6:41Come on, let's go.
- 6:42Yeah, exactly.
- 6:43And then 3.6 comes out.
- 6:44So 3.5 included the async await, a lot more functions with asynchronous programming.
- 6:51And also 3.6 came out with more async await features, like the generators, for example, async with statements.
- 7:01So context managers, basically.
- 7:03And the f strings came out in 3.6, which is yet another way of formatting strings in Python, which is pretty cool.
- 7:09Because I don't know what, five wasn't enough or I don't know if they were.
- 7:12And once you get to use it, actually, it's definitely my favorite way to format strings now.
- 7:17I'm with you.
- 7:18You know, the problem I run into with f strings is I'm like halfway through a string and I decide, oh, yeah, now I want to put this variable here.
- 7:25I'm going to go back to the beginning and put the f and then go back and do it.
- 7:28And, you know, I don't know.
- 7:31That's something I just got to train myself to put the f at the front more often.
- 7:34Yeah, so 3.7 came out.
- 7:36And, yeah, I guess really they're an opportunity now where they can start adding some good new features.
- 7:41For people, it's not just bug fixes and performance improvements.
- 7:44So, yeah, it's been a pretty significant change.
- 7:47Yeah, that's right.
- 7:48Because Python 3 is really either as close to, you know, same as Python 2 or faster, right?
- 7:54There's a lot of performance improvements where the argument used to be, well, I can't switch to Python 3 because it's too slow.
- 8:00Now it's, well, if I don't, I'm going to be behind, right?
- 8:03Yeah.
- 8:04So 3.7 was the first release of 3 that basically across all the benchmarks was quicker than Python 2.7.
- 8:11With one exception, which is the startup time.
- 8:14But that's still been an ongoing issue.
- 8:18Yeah, and it really depends on what kind of apps you're building, whether that matters.
- 8:21If you're building, like, a background thing that runs in a queue or a web app, like, who cares about startup time?
- 8:26If you're building a little command line app, that might matter, right?
- 8:29Yeah.
- 8:29But it's still milliseconds.
- 8:30It's not.
- 8:33It's not .NET or something, right?
- 8:35Yeah.
- 8:35Not WPF.
- 8:36I just want to, like, while we're on this little micro subject of Python 2 to 3, I just want to put it out there one more time.
- 8:42Let's all call Python 2 Legacy Python.
- 8:45And I think that's going to start to make a little dent with the managers.
- 8:48Yeah, we're still using the Legacy Python.
- 8:50Can we stop doing that?
- 8:51Yeah, it came out in June, which is winter for us.
- 8:54So I'm on the other side of the world.
- 8:56Yeah.
- 8:56So, yeah, it came out in June this year, so 2018.
- 8:59The first sort of beta versions came out earlier in the year, sort of February time.
- 9:03And there's a couple of alphas out very early on in the new year, this 2018.
- 9:09So, yeah, it's been out for, what are we, six months now, nearly.
- 9:12So that's, yeah, it's kind of had the chance to pick up speed.
- 9:15Obviously, it's not been included with any of the major distributions yet.
- 9:20So you have to go out of your way to download and install or upgrade to Python 3.7.
- 9:25So I'd say it's not as widely used as 3.6 or 3.5 yet.
- 9:29But it's definitely a major step forward.
- 9:31Yeah, it definitely is.
- 9:32And, you know, if I log into my Ubuntu machines, it's Python 3.6.6, I think, which is already
- 9:38really awesome, right?
- 9:39That's way better than, too.
- 9:40Like, that ships with the operating system.
- 9:42So that's really cool.
- 9:42But 3.7 has a bunch of great features.
- 9:45Now, the reason that I thought, hey, I should have Anthony on the show is because you wrote
- 9:50a pretty sweet course on specifically what's new in Python 3.7.
- 9:56And it's really quite consumable.
- 9:58It's like an hour, right?
- 9:59Do you want to just tell us quickly about your course?
- 10:01And we'll get into the details of the stuff.
- 10:02Yeah, sure.
- 10:03So the course is on Pluralsight.
- 10:04And it's called What's New in Python 3.7.
- 10:08And basically, I go through all of the new features and functions and show you how to
- 10:13use them, show you any gotchas and stuff like that.
- 10:15It's only about an hour.
- 10:16So it's not going to take much of your time to watch.
- 10:19But yeah, it's been fun to put it together because, you know, with each alpha and beta
- 10:25release, I was running all the upgrades or pretty much just running on a copy of the master
- 10:30branch on CPython development for a few months.
- 10:34Now that it's on GitHub, right?
- 10:35Yeah, it's finally on GitHub.
- 10:36Yeah, yeah.
- 10:37So it's good to kind of keep on the bleeding edge and also to read all the peps and get
- 10:42all the background and details and stuff.
- 10:44So I put the course together to condense all of that information down into a way that's
- 10:49a bit easier for people to just watch, get a gist of and get going with all the cool new
- 10:54stuff.
- 10:54Yeah, sweet.
- 10:55So we'll link to that in the show notes as well.
- 10:57I guess it's worth pointing out, like this came out in June and Python right now is on
- 11:03an 18-month shipping schedule.
- 11:07not next June, but next Christmas, December or something like that.
- 11:11It should be Python 3.8.
- 11:13Right.
- 11:13So that's the current schedule anyway.
- 11:15Yeah.
- 11:15So about in around August, maybe September, there is actually a Python 3.8 release schedule
- 11:21already.
- 11:22I think in about September 2019, we're going to start to see some beta releases of 3.8.
- 11:28You can actually test some of the new features already if you go and download from the source.
- 11:33If you live at the tip of the master branch.
- 11:36Yeah, exactly.
- 11:38There was a Python meetup in London last month.
- 11:42And I gave a quick lightning talk showing some new 3.8 features.
- 11:45And it basically segfaulted halfway through the demo.
- 11:49Don't do this in production, Jess.
- 11:52Don't run it in production.
- 11:53Maybe hold off a little bit.
- 11:54It's not even alpha ready yet.
- 11:55It's very, very, very early.
- 11:57Yeah, that's pretty cool though.
- 11:58There's some really great stuff in there.
- 12:00But let's start with 3.7.
- 12:01We'll talk about 3.8 in a little bit.
- 12:02So I guess probably the big star of the show for 3.7 is data classes, right?
- 12:08That's the thing that is totally new and pretty obvious that most everyone could use, right?
- 12:14Yeah, so Python has always come batteries included, which is in the form of the standard library.
- 12:19And in the standard library, there's a whole load of things you can do.
- 12:23You can talk to HTTP endpoints.
- 12:26You can work with the file system.
- 12:28You can even manipulate audio files, like all from the standard library.
- 12:33There's all this great functionality built in.
- 12:35And really, there's been a bit of a gap in terms of working with data structures, like APIs, for example,
- 12:43or working with document databases.
- 12:45The gap's been filled by a couple of third-party packages.
- 12:50Django, for example, has its kind of built-in ORM, which helps you basically create a class called a Django model.
- 12:58And you can have attributes on the class.
- 13:01And then when you save that to a database, it automatically creates all the fields and stuff for you.
- 13:06So Django is not the only one to do that.
- 13:08There's lots of other ways of doing it.
- 13:09There's also packages like attrs, A-T-T-R-S.
- 13:13which is great, which does a very similar thing.
- 13:17But the concept is that you have a class in Python.
- 13:20You put some fields on it.
- 13:23And basically, you can use that to represent data that's in some other system.
- 13:28So that could be an API you're talking to or a database or it could be a memory store, for example.
- 13:34So it's a whole bunch of border plate code you have to create.
- 13:37If you do this from hand, you have to create all the Dunder methods that you want to use.
- 13:42So __init__(), for example, the Dunder EQ, Dunder Reper, Dunder STR, etc.
- 13:48Right.
- 13:48So it seems like you're kind of done when you've done the __init__() and you put your fields in there.
- 13:53But if you're going to, say, try to hash those things or compare them or sort them or you want them read only,
- 14:00all of those things require a pretty good understanding of the Python data model and the magic methods and all that kind of stuff.
- 14:07And data classes are just, you know, frozen equals true type thing.
- 14:11Yeah.
- 14:11So there's some great features in data classes.
- 14:13So really what you have to do is you create a new class and that implements a data class.
- 14:20And within that, then you basically have attributes on the class.
- 14:25So these are class level attributes.
- 14:27You have to give them type annotations.
- 14:30Otherwise, they .gitignored.
- 14:31If you're not aware what type annotations are, it's a colon after the variable name.
- 14:36And then the type you want to use.
- 14:38But there's another change in type annotations in 3.7 as well, which we'll come back to maybe later.
- 14:45And basically, you put the fields on there and then you're done.
- 14:48And then you can basically call that class.
- 14:51You can call the initializer or the constructor on the class and pass it all the fields that you've assigned.
- 14:56And then there's a whole bunch of really cool features you can use.
- 15:00For example, you can set default values.
- 15:02You can have default factory values.
- 15:04You can have it implements done the EQ for you, done the rep, done the STR.
- 15:09So basically, it just gets rid of a lot of boilerplate of having a class which basically just stores data and represents some of that kind of data structure.
- 15:17Yeah, it's really sweet.
- 15:18And that initializer, it writes that for you, right?
- 15:22Yeah, it writes everything for you.
- 15:23So all you need to do is declare the class and sign the fields and then you're done.
- 15:28That's cool.
- 15:29Can you inherit them?
- 15:30Can you create like a hierarchy of data classes?
- 15:31You can.
- 15:34I'm not saying you should.
- 15:35I'm not saying you should.
- 15:35I'm just wondering if you can.
- 15:36You definitely can.
- 15:37And there's a lot of reasons why you want to do that.
- 15:40Now, if you want to inherit from a base class, it's important to note that within data classes, you can have fields with default values and fields with basically require a value.
- 15:53So if you mix those things together, so if you have a base class that has both non-default and default fields and then you have a inherited class, you can't mix them in the inherited class.
- 16:05This is probably one of the bigger limitations of the data classes package is to do with the way that it builds the done the init method.
- 16:12But it's, yeah, that's pretty, I guess, a bit of an edge case, but it's something to watch out for.
- 16:17Yeah, that's cool.
- 16:18And so if I want to have some kind of check in my initializer, like this number has to be between 0 and 10, but it's written that for me, like where does that happen?
- 16:29Yeah, so you can do it in a couple of places.
- 16:31One would be a post init method.
- 16:33So after the auto-generated __init__() has been called, you can have your own method which does extra stuff at the end.
- 16:41So that could be a value check, for example.
- 16:44It doesn't do type checking.
- 16:46So even though it uses type annotations, I guess the Pythonic way of doing it is that they're just a friendly reminder of the type and they're not guarded in any way.
- 16:56They're meant for linting and like build time checks, not run time checks, right?
- 17:01Yeah, exactly.
- 17:02Another great feature is that you can use, basically you can create immutable types.
- 17:07So by default, they're mutable, which means you can change the values.
- 17:11You can also create immutable types by setting frozen equals true when you basically instantiate them.
- 17:18The frozen basically means that they're immutable, you can't change their values.
- 17:24And also they'll implement a dunder hash method as well.
- 17:28So they're hashable.
- 17:28So you can use them in things like sets.
- 17:31Also, you can use them as dictionary keys, which is pretty cool.
- 17:34Yeah, that's really cool because you shouldn't be able to put a thing into the dictionary and then change the value of it and then make it no longer have the same key.
- 17:41That would definitely drive you insane, which is what it effectively means if the hash value changes, right?
- 17:48Yeah, so it's a really cool way of creating more complex dictionary keys, I guess.
- 17:53And also moving away from just representing everything in dictionaries all the time.
- 17:59I think when you're working with APIs and stuff like that and you're passing data around, it's convenient to just stick with dictionaries because you don't have to worry about what field you have and what types they are, etc.
- 18:11But it's definitely nicer and it's also a lot more testable to introduce a bit more concreteness, I guess, to the types.
- 18:19Yeah, it's cool.
- 18:19And data classes kind of makes that less effort to do so correctly.
- 18:23Yeah, really easy.
- 18:24This portion of Talk By The Dermade is brought to you by Tidelift.
- 18:30Open source software is everywhere.
- 18:32How can we as a community ensure that the open source software we rely upon continues to get even more awesome and more dependable?
- 18:40Tidelift believes the solution is hiding in plain sight.
- 18:43Pay the maintainers.
- 18:44They're dedicated to creating an effective way to do just that.
- 18:48And today, they're excited to share that they've reached over $1 million in committed payments for maintainers available via the Tidelift platform.
- 18:56And yes, that includes Python maintainers.
- 18:58Income for a project grows based on usage, not the number of hours spent on the project.
- 19:03So you can build significant income around your open source projects.
- 19:07Tidelift is offering a guaranteed minimum $10,000 payout over the next 24 months to select projects in the Python ecosystem.
- 19:15If you maintain a Python project, visit talkpython.fm/Tidelift to find out if your project is included.
- 19:21That's talkpython.fm/Tidelift.
- 19:26The next one doesn't actually sound very exciting to me, but I'm sure it's super important, is that the locales and UTF-8 got a little bit of a change, right?
- 19:34What's the story around that?
- 19:35How much do we need to worry about it?
- 19:37I think we won't spend too much time on this because it's really confusing.
- 19:42Any form of encoding is confusing.
- 19:44It's super confusing.
- 19:45Yeah.
- 19:45So a local means it's, I guess, the settings on your operating system, which describe what country you're from, for example, and the way you like things to be represented.
- 19:56So, you know, in...
- 19:57Like, digit grouping or the order of month, date, year when you print out a date, things like that?
- 20:02Yeah.
- 20:03So, like, in mainland Europe, most countries would represent the number 1,000 with 1.000, whereas in the UK and the US, there would be 1,000.
- 20:14So that's one change, I guess, and that would be in the locale.
- 20:18Other ones would be the encoding type, which is where UTF-8 comes in, the keyboard mapping, and there's a whole bunch of other things.
- 20:25So, basically, there's a default, which is the sort of NCC locale, which was default like 20 years ago, maybe.
- 20:35But, you know, since computing has moved on a bit and we've had to support more countries than just the US.
- 20:41So I would like to think that this is like the world going, let's just, let's accept everybody and let's support all of those languages.
- 20:48But how much of this has to do with emojis?
- 20:50It definitely helps with emojis.
- 20:55And hopefully that's not the main...
- 20:56My thumbs up is a square, come on.
- 20:58Hopefully that's not the main driver.
- 21:00But yeah, there's quite a few reasons.
- 21:03Now, I guess Python 2 doesn't really, or say legacy Python, this problem is a bit more invisible because they use byte strings by default, whereas in Python 3, we use unicode strings by default.
- 21:17So I guess the thing is, if you're reading from a shell pipe, for example, so you want to pipe the output of one command into your Python script, then Python will look at the locale.
- 21:30So look at the operating system to see, you know, what settings you've got locally.
- 21:35Now, the problem is that not everyone configures their operating system correctly.
- 21:40There's also other scenarios like people creating Docker containers and not bothering to set the locale.
- 21:47Exactly.
- 21:48Like all the cloud stuff, right?
- 21:49Yeah.
- 21:50All the cloud stuff.
- 21:51You just fire it up and you're like, oh, look, it works.
- 21:53But I passed in my data file, which was in one locale, and I tried to read it in another, and there it went.
- 21:59Exactly.
- 21:59So if you just had that set to the, I guess, the most basic one, which would be the NCC, then that would not be with UTF-8.
- 22:07So Unicode would not work by default.
- 22:10So basically, in Python 3.7, they've made more assumptions about people misconfiguring their operating system to make it more friendly for Unicode.
- 22:21Nice.
- 22:22So the next one that you have on your list, I think, is really interesting.
- 22:26And it's interesting because I'm like, oh, this is super.
- 22:30This is not like, why would I ever use it?
- 22:32I would never use this.
- 22:32What is this about?
- 22:33And then at the end, I'm like, oh, no, this is really useful.
- 22:36And I feel like I really learned something.
- 22:37And I always love it when that happens.
- 22:39So the next one is breakpoint, right?
- 22:41We used to import PDB, and we'd do a set trace thing.
- 22:44Or we would fire up PyCharm or Visual Studio Code or something and just click in the side.
- 22:49So why does Python need a breakpoint?
- 22:51Is it just like an alias for PDB set trace?
- 22:55Yes and no.
- 22:56So Python 3.7 introduces a new built-in function called breakpoint.
- 23:02So if you just write breakpoint, open, close, parentheses, anywhere in your code, when that line executes, it will jump into a debugger.
- 23:11By default, that will be the one that comes in the standard library called PDB.
- 23:16So anyone who's done debugging in Python today, I guess, would have learned that to jump into a debugger, you basically type import PDB semicolon.
- 23:28Wait, wait, wait.
- 23:29What did you say?
- 23:29Semi-colon.
- 23:32Oh my gosh.
- 23:33All right.
- 23:33Yeah.
- 23:34So you can put it on one line and comment it out really easily, right?
- 23:36Yeah.
- 23:37So basically, to insert a breakpoint in Python requires two separate statements.
- 23:43And having two lines of code to do a breakpoint kind of is confusing because then you've basically just changed your code in the way that you didn't really need to.
- 23:52It's also, I guess, not super intuitive for people coming from other languages, people who are just used to working in an IDE and clicking on the red circle on the left-hand side.
- 24:02You know, how do you do that in Python?
- 24:03How do you step into a breakpoint and work in a debugging console within Python?
- 24:09So what they've introduced is this new built-in function.
- 24:13By default, it will just call import PDB, PDB.setTrace.
- 24:17So it behaves the same way that you would expect.
- 24:21But you don't have to write a semicolon.
- 24:22That's better.
- 24:23Yeah, exactly.
- 24:24And it doesn't cause the linter to throw up its arms in anger that you've dared to include a semicolon in your code.
- 24:31And so if that's all it was, I don't think actually it has that much value.
- 24:35I'm not against having the language, but it's not that huge of a thing.
- 24:38But then what if I don't want to use PDB?
- 24:41Like, I don't like it.
- 24:42There's other, even in the terminal, there's other nice sort of semi-graphical debuggers that are pretty cool, right?
- 24:48Yeah, so what it actually does is it will eventually call breakpoint hook, which is a global variable within the sys module.
- 24:57And like I said, by default, that's set to PDB.setTrace.
- 25:02But you can change it to something else.
- 25:04So there are loads of other debuggers of Python, which are a lot more friendly to use.
- 25:09Also, there's browser-based ones like WebPDB, for example.
- 25:13So WebPDB, when you hit that instead of as your breakpoint, it'll actually pause the code and it'll actually start up a little web server.
- 25:22And you can open up your browser and you can navigate to it.
- 25:26And it's just a lot easier to see and explore through the local scope and the global scope in a browser with a whole tree and everything than it is to do it in a little text console.
- 25:35Yeah, that's awesome.
- 25:36And basically, the breakpoint lets you customize what debugger gets called when you type breakpoint open close parentheses.
- 25:43Yeah, so you can do it either in code.
- 25:44So in Python, you can change the value of sys.breakpoint hook.
- 25:49Or alternatively, you can set it using an environment variable, which is also pretty cool.
- 25:54So if, for example, if you wanted to have breakpoints in a certain part of your code because you wanted to debug something that was running across multiple machines,
- 26:06and one of the debuggers would be a local one and one of them might be a remote one, then you could have an environment variable set to basically change which debugger you want to use whenever breakpoint gets called.
- 26:18Yeah, that's pretty awesome.
- 26:19So even remote debugging.
- 26:20I love it.
- 26:21Yeah, it's great.
- 26:21I think it's a great feature.
- 26:22Yeah.
- 26:22The next one is pretty cool.
- 26:24So time seems pretty accurate in Python already.
- 26:29So even like if I subtract two date times and I get a time delta, there's a lot of accuracy to like dt.total seconds or whatever it is.
- 26:37But in Python 3.7, there's more seconds or more parts of seconds.
- 26:42Yeah, this one really confused me when I was doing the research.
- 26:44I think anyone who's worked with time accuracy, this would totally make sense.
- 26:49But if you have put it in the I don't really care, I just want the time and it sounds pretty accurate, camp, which is where I was definitely from.
- 26:59Then when the announcement came that they were introducing these nanosecond resolution time functions, it's like, okay, great.
- 27:06Why do I need that much accuracy in my application?
- 27:11So basically what they've changed in 3.7 is they've introduced some new functions into the time standard library module.
- 27:20And they have the append xdunda underscore ns for nanoseconds.
- 27:27And basically you've got a lot more accurate representation of time.
- 27:31Right.
- 27:31So it's not like time now returns better numbers.
- 27:35You have to call time underscore ns, right?
- 27:38Yeah.
- 27:38So it's a separate function.
- 27:40The different functions.
- 27:41And for whatever reason, the old functions that would give you the time epoch.
- 27:46So the time epoch was the 1st of January 1970.
- 27:50Apparently nothing happened before then.
- 27:53But that's basically the beginning of time.
- 27:55In Python, it'll give you a floating point number back.
- 28:00And anyone who's worked with floating points before will know there can be all sorts of inaccuracies.
- 28:05So the number of seconds since the 1st of January 1970 is the major number.
- 28:11And then the actual floating point itself is the parts after that.
- 28:16So it's, you know, the milliseconds, for example.
- 28:18Now, the problem is that you get all sorts of rounding issues.
- 28:22And also they're not particularly accurate.
- 28:24So it's not necessarily in milliseconds.
- 28:27It's almost like the closest number that it could find depending on the operating system and the CPU that you're using.
- 28:33So there can be these gaps and issues with accuracy in Python.
- 28:38Anyone who's used Python before to try and measure time very accurately will probably know about these limitations.
- 28:44So in 3.7, they've introduced a new nanosecond function, which is awesome.
- 28:48And it will give you that in basically a long, long integer, which is the Python integer.
- 28:53Nice. Well, I know that in that there's a time NS.
- 28:56What else are there other underscore NS functions I can use?
- 28:59It says get time NS.
- 29:01There's set time NS, which you can only use in certain situations.
- 29:04And there was a couple of others as well.
- 29:06But those were the major ones.
- 29:07Yeah, nice.
- 29:08For this next one, what do you think, before we get into the details of what's new, let's just talk about type annotations.
- 29:13You hinted at this in the data classes bit because it's very interesting that it's even required, although not checked at runtime.
- 29:19How do you feel about type annotations?
- 29:21So I haven't really used them very much up until 3.7 for exactly the reason that we'll talk about this next feature, actually.
- 29:30So in 3.6, they're kind of a bit clunky to use.
- 29:35If you want to represent anything remotely complicated, other than just a string or an int, you might have extra code you have to add to your Python modules.
- 29:43I think it's just cumbersome.
- 29:45And I haven't got a huge amount of value out of it so far.
- 29:48So I think...
- 29:48Right.
- 29:49If you want to say a list, you'd have to say import list from typing like capital L list, not lowercase l list, things like that, right?
- 29:56Yeah, because a lot of my code that I would write would return a tuple, for example, and the first entry would be an integer and the second one would be a dictionary.
- 30:06And in the dictionary, then there'd be a certain structure.
- 30:09And by the time you've had to describe all of that, it's just such a pain.
- 30:13And it adds so much code to your...
- 30:15And the type annotations themselves, the way to represent complex types is not particularly intuitive.
- 30:22And if you're not familiar with type annotations either, then it's quite a bit of a blocker.
- 30:27Yeah.
- 30:27You know, my take on them is I really like them, but I don't think they belong everywhere.
- 30:32But I really love type annotations on the boundaries.
- 30:35So if I have like a data access layer and I've got some functions you call, like those functions you call, I love to put like annotations on, well, you get a list of these things back.
- 30:44Or this one could be an optional user because they might not exist in the database.
- 30:48And then that kind of flows enough through the editors for me that like everything else kind of picks it up.
- 30:53But I don't turn it into like C# and put, you know, types on everything that exists, right?
- 30:58Yeah.
- 30:59One of the other big limitations is that if you're, you know, the type is actually a class that you've declared somewhere, then you have to import that in order to add it as an annotation.
- 31:11Yes.
- 31:12Yeah.
- 31:12And that's partly what drove the changes for 3.7, right?
- 31:15Like, so the place that made me the most crazy was it cannot be solved in the most straightforward way is that I have like, say, some kind of method on a class, like a class method on a class that returns an instance of that class.
- 31:29I cannot say in the type system, it returns that class because it's not yet defined.
- 31:35I mean, you could use like the string sort of cheating style, but you can't, you have to go realize there's this other way to like talk about it when it's not important and it's not as well as enforced and so on.
- 31:45Yeah.
- 31:46So the example I use in the course is, is sort of fictional, but you know, you could have a theater class, for example, and then in the theater, it has a number of seats and you have a seat class, which is in a separate file.
- 31:57So in a separate submodule, and then you've got an attribute on the seat, which says which theater it belongs to, or you've got an attribute in the theater, which says how many seats there are.
- 32:07And you can reference the seats.
- 32:08Now, in order to do that as a type annotation, you need to import either one from each other, which creates a circular import, which Python is pretty good at handling.
- 32:16It's not, it's not as bad as it was in C, but what it's kind of led to is kind of similar to what you see in Java and C#, which is the first, you know, 30 lines of every file is just import statements.
- 32:30Which is a bit of a limitation really, because you're not using them for anything other than to add a type hint to the method in terms of what it returns or what it expects as parameters.
- 32:42You're not doing anything with it.
- 32:43And the imports obviously, you know, add quite a bit of time as well.
- 32:47It slows the application down.
- 32:49It's not a compile time thing.
- 32:51It's a runtime thing.
- 32:52So when you import all those things to just declare, here is the return type, that actually slows down the startup of that program, because now it's doing more stuff just to get to that one function.
- 33:04Yeah.
- 33:04Yeah, exactly.
- 33:05All right.
- 33:06So what's 3.7 add for us?
- 33:08Like, how does it change this or make it better?
- 33:09So what they've introduced is delayed evaluation type annotations, which is a very fancy way of saying that.
- 33:19Basically, what happens is when your code gets parsed.
- 33:24So in Python, to create the, I guess, the executable code, the Python files, the text files, or the code that you've given it needs to be parsed first, and then it needs to be compiled.
- 33:36So at the parser stage, if you've imported from Dunder future annotations, and it will enable these delayed evaluations, then what it does is it goes and looks at all your type hints.
- 33:48And if you'd imagine, let's say you've got a method, and you want to set the return type.
- 33:54So you do a colon, and then the type hint, the type that you want to return.
- 33:59Basically, what the parser will do is equivalent to just putting double quotes either side of that name.
- 34:05So it's basically a string literal as a type hint instead of the actual reference to the type.
- 34:12Right, which already works in the previous version.
- 34:14Like, you can do that, sort of put it in a quote, and that actually works for, say, like, the class self-reference thing I talked about.
- 34:21But then you don't get, like, say, refactoring help and things like that, right?
- 34:24Yeah, so it causes issues with IDEs and other things like that.
- 34:28So basically what this does is it supports a lot of stuff you get in IDE.
- 34:32So the IDE would know, or should know, how to import those and reference them.
- 34:37But it doesn't slow down your application at runtime.
- 34:40And it's a lot easier to use because you don't have to worry about all the imports and things like that.
- 34:45Yeah, very interesting.
- 34:46The IDEs and the linters, they know how to still check for those things, even though Python at execution time doesn't necessarily do the imports, right?
- 34:56Yeah, it basically pushes the problem down the path a bit, though.
- 35:00Okay.
- 35:00Because if you actually want to use the type annotations to find the concrete types, then you need to call a special new function called get type hints.
- 35:12And you need to pass it the local and global scope.
- 35:16And when you call that function, the thing, the type hints that you, if they'd referenced a class, for example, then you would have need to imported that class by that point.
- 35:27Otherwise, that function won't work.
- 35:29So you still have to import stuff if you want to use the type hints.
- 35:33But it basically assumes that most people just want to use them as general annotations.
- 35:38They don't want to use them to actually reference concrete types.
- 35:42Right.
- 35:42Yeah, very interesting.
- 35:43So while we're on this type annotations thing, there's some very interesting stuff happening around type annotations in the later versions of Python.
- 35:51And they all seem to be about trying to make Python faster, actually.
- 35:55I mean, obviously, it was introduced to make it more understandable and help the tooling and stuff.
- 35:59But so Cython has recently started adopting, if you have regular Python 3 type annotations, it'll use those instead of its funky way of declaring variables.
- 36:10So it can actually take just annotated code and compile it to see better, which is pretty cool.
- 36:16That's awesome.
- 36:16I didn't know that.
- 36:17Yeah, I know.
- 36:18I just learned it as well.
- 36:19And do you know about mypy, which is like the type verifiers, like a linter, but like deeply for typing?
- 36:25Yeah, it's like an introspection tool, isn't it?
- 36:28Yeah.
- 36:29So that's pretty interesting.
- 36:30And there's some tools to like generate the type annotations based on like runtime stuff and various interesting things.
- 36:36But what also is interesting is Dropbox is releasing this thing called mypyc, which is a compiler that takes annotated statically typed Python code and compiles them to C extensions.
- 36:48Wow.
- 36:48Okay.
- 36:49That's really cool.
- 36:50So these are both kind of interesting things that people are playing with.
- 36:54So anyway, those are worth maybe looking at.
- 36:56Yeah.
- 36:56And the important thing with this feature is that in the pep, it says that it will be the default behavior in Python 4.
- 37:03That's pretty awesome.
- 37:04There's going to be a Python 4 pretty soon.
- 37:05Well, we don't know how long, but.
- 37:08Yeah, well, a couple of 18 month iterations.
- 37:10There's actually talk Łukasz Langa is overseeing the release for Python 3.7, 3.8, I believe.
- 37:18Definitely for 3.8, maybe 3.8, 3.9.
- 37:21I don't want to give me the wrong numbers.
- 37:22Yeah, thank you.
- 37:23And he's trying to get the release cycle down to yearly, but that's kind of on hold for a little bit.
- 37:28Okay.
- 37:29So maybe it'll be quicker than it otherwise would have been by, you know, six month segments.
- 37:34All right, so we opened this section, the whole podcast a little bit by talking about performance in Python 2 and 3.
- 37:41So 3.7 brings some interesting new performance benefits, right?
- 37:45Yeah, so I guess calling methods or calling functions in Python definitely has an overhead or an associated cost.
- 37:53I got to say, when I first learned Python, I was blown away at how slow a function call was compared to if I inlined it effectively.
- 38:00Right, yeah.
- 38:01And I think it's a big deal.
- 38:02And this leads to people writing code in certain funky ways, copying and pasting things a bit more once they learn about this quirk of Python.
- 38:11Especially if you're using some of the frameworks because the number of, I guess, turtles deep or the number of layers that it has to go through function scrolling functions, it can really kind of slow down the application.
- 38:21Yeah, yeah.
- 38:22I know in SQLAlchemy that Mike Bayer very carefully worked on the architecture to minimize the function call depth, actually, for performance reasons.
- 38:30Like, there's a lot.
- 38:32So in 3.7 calling functions gets somewhat faster.
- 38:35Not quite like inline assembly fast, but faster, right?
- 38:38Yeah.
- 38:38So basically, they've introduced some new opcodes.
- 38:42And there's a different implementation for calling.
- 38:45And it's quite specific, actually.
- 38:47It's not just functions and methods in general.
- 38:49It has to be on a bound method, which means if you've got a class and you've got a method on the class, you've instantiated it.
- 38:57When you call it, if that class doesn't have any keyword arguments, then it will be faster than before.
- 39:04So like I said, it's quite specific, but that probably covers quite a lot of cases.
- 39:08But that's a really common case, right?
- 39:10There's a lot of times when you have some kind of object and it has a function and you want to call it.
- 39:14Like, if objects don't have functions, why would you create them, right?
- 39:18Just put them in a data structure or something, right?
- 39:20So it's obviously nice that those are there.
- 39:23And I wouldn't say the majority of functions have keyword arguments.
- 39:26So it's a good improvement.
- 39:28Yeah.
- 39:28No, I think it's a good step forward.
- 39:30So it's 10% to 15% faster.
- 39:31And in benchmarks, there's basically a speed boost because of that knock-on effect.
- 39:37Yeah.
- 39:37That's really cool.
- 39:38So maybe that might even affect like what you've pip installed, right?
- 39:42Even if you have no classes, you might be interacting with like some turtle at layer 3 that uses classes, right?
- 39:49Yeah.
- 39:49So even just by moving to Python 3.7, you can actually see a speed improvement on a lot of applications.
- 39:56I've upped 10% to 15%.
- 39:57Yeah, that's really sweet.
- 39:58So after going through all this, doing all this research, if somebody's on 3.6, is it worth upgrading to 3.7, you think?
- 40:05I'd definitely be worth upgrading to 3.7.1.
- 40:09Point anything other than 0?
- 40:11Yeah.
- 40:12I would never upgrade to a .0 release in a production environment.
- 40:16But definitely, I think data classes are really cool.
- 40:19I'd been using the Attrs module for a few projects and really liked it.
- 40:23But obviously, adding yet another dependency to your application is not always desirable.
- 40:27So it's nice to have that in the standard library.
- 40:30The speed improvements are always welcome.
- 40:32I think anything that can make Python faster is great.
- 40:36The type annotations change, I think, actually makes it a lot more appealing to me because you don't have to worry so much about the import statements and things like that if you're not actually going to use them in that way.
- 40:47So, yeah, there's some big changes.
- 40:48I think the one that I've actually used the most is Breakpoint.
- 40:51Just since I've switched to 3.7, just got so used to just writing Breakpoint instead of the import PDB.
- 40:58And also worked with the pytest team to get Breakpoint supported in pytest, which was pretty fun.
- 41:05So I got to kind of dig into some of the details.
- 41:09Although somebody, Anthony Sotile, the other Anthony who works on pytest, there's quite a few of us actually,
- 41:15but he raised a pull request basically saying that he proved that my pull request basically did nothing.
- 41:21So I was a bit disheartened.
- 41:22Oh, dear.
- 41:25But it has a lot of test coverage.
- 41:27That's good.
- 41:27I hear you with the .0 release in production.
- 41:31Right now, what I'm doing is I'm still using 3.6, 6, whatever the latest on Ubuntu is, right?
- 41:36I keep that up to date as it ships with there.
- 41:38But I'm doing 3.7 in dev and just making sure that I don't use any of the features yet that are going to cause trouble when I ship it.
- 41:46So I've definitely taken my site down by accidentally using an F string in a utility function that was never called in the web app,
- 41:54but was actually parsed by 3.5.
- 41:57And they wouldn't start the web app.
- 41:58So it can sneak in there.
- 42:01But maybe you could start testing in dev or Q&A or some sort of staging environment and then someday switch pretty soon.
- 42:09Yeah.
- 42:09And then someday move to 3.8.
- 42:11Yeah.
- 42:11You could move to 3.8.
- 42:13Although the segfault thing you're talking about, maybe not yet, maybe wait a little bit.
- 42:17But yeah, let's do a quick preview of what's coming in 3.8.
- 42:21Yeah, sure.
- 42:22So there's a couple of quick, easy ones.
- 42:24So for example, AsyncIO on Windows gets a different event loop, a proactor event loop.
- 42:31I actually have no idea what that is.
- 42:32I now want to go research it and see what that is.
- 42:35But that's pretty cool that AsyncIO has these configurable, extendable event loops like uvloop and so on.
- 42:40There's a few simple language things like a continue statement used to be illegal in a final clause, but now it's not.
- 42:49But then there's a few other major ones.
- 42:52You want to maybe touch on the big ones and we can hit a few small ones after that.
- 42:56Yeah, there's been, well, there's, I guess, for every major release of Python, there's all the proposals for new features in the form of these documents called PEPs.
- 43:06So I've been reading, I guess, some of the proposed PEPs in detail and trying to understand what they do.
- 43:12There's a couple that have been accepted already.
- 43:15The big controversial one, I guess, was PEP 572, which is something called assignment expressions.
- 43:22The easiest way to understand it is that if you just do in a REPL, X equals one, enter, and then X, enter, it will return one.
- 43:32And assignment expressions basically introduce a new syntax, which is X colon equals one, which will return one.
- 43:39So it basically squashes those two statements together into one.
- 43:43All right.
- 43:43A lot of time you might be thinking, well, I would never use that.
- 43:46Like, what is the value of this?
- 43:48But if you're doing, well, expressions, right?
- 43:50If I'm doing like a list comprehension and I want to do both a test and a creation of a variable or things like that, you know,
- 43:58like there's a few interesting use cases where it does simplify the language a bit.
- 44:02Yeah.
- 44:03And that syntax is in other languages.
- 44:05So people might be used to it in other places.
- 44:07JavaScript is an example.
- 44:09And Perl would be another one.
- 44:12So I guess people, some people are more familiar with using that kind of syntax.
- 44:17And yeah, if you're doing statements, like if statements, this comprehensions while statements, for example, then yeah, you can introduce this new syntax and you can basically get the value back and then use it for other things.
- 44:30All right.
- 44:30Maybe like a lambda expression where you've got to squeeze it into one line, possibly.
- 44:35I don't know.
- 44:36Yeah.
- 44:36Yeah.
- 44:37It's basically because you can, yeah, you can't write return statements inside where something should be a statement itself.
- 44:44Yeah.
- 44:45Even with semicolons, right?
- 44:46Even with semicolons, you can't do that now.
- 44:49Right.
- 44:50So this was controversial partly because let's say close to half of the community really you thought like this just does not need to be added to the language.
- 45:01We don't do this.
- 45:01And there was like maybe a minority.
- 45:03I'm not sure.
- 45:04But another part of the community that really did want it.
- 45:07And so there was actually quite a bit of a disagreement about whether it should have been accepted.
- 45:12And the fallout of that is sort of the straw that caused Gita Van Rossum to step down as BDFL.
- 45:20Yeah.
- 45:21I think that some of the comments got a bit nasty, to be honest, and some of the pushback.
- 45:25But I don't know.
- 45:27I've seen places where it could be used.
- 45:29And I think, yeah, that could be useful.
- 45:30But I don't think I'd use it every day.
- 45:32Like this is a once every now and again, you'd use it kind of thing.
- 45:36Yeah.
- 45:36That's kind of how I feel about it.
- 45:37Like it's not a huge deal, but I'm not like looking forward to doing amazing stuff with it yet.
- 45:42Yeah.
- 45:42Like an async context manager.
- 45:44Like, you know, that's kind of cool.
- 45:46But it's not something you do use in everyday code.
- 45:48Yeah, for sure.
- 45:48So the one that's coming that I'm really positive about is the none aware or null aware operators.
- 45:56Tell us about that.
- 45:56Yeah.
- 45:57So this one has been proposed, but not accepted.
- 45:59I think it's in draft state at the moment.
- 46:02So it's basically, again, a new syntax.
- 46:05So anyone who works with Python a lot will know the sort of famous error that X is not an attribute of none type or something along those lines.
- 46:14So like, I think it's one of the most common exceptions is that attribute error.
- 46:19Something is not an attribute of none type.
- 46:22Yeah.
- 46:22So it's basically like it's the equivalent of a null pointer or a null reference exception in Java or C# or C++.
- 46:31It's the Python equivalent of that.
- 46:34So none, I guess, is our special type to represent nothing instead of null.
- 46:39But it doesn't technically have a value similar to null.
- 46:43It's actually a special type in itself, which means that in this PEP and their proposal, what they're proposing is basically a special set of syntax based around the question mark to allow you to basically follow branches depending on whether something is null or not.
- 47:00So, for example, if you had a data class, if you had a data class with some fields and one of the values of the fields was null, you could reference it.
- 47:10And then if that field itself, you wanted to call a method on it.
- 47:14Like, I don't know, let's assume it was a string.
- 47:16You wanted to run the upper on it.
- 47:18If it was none, then you'd get upper as not a property of none type.
- 47:23But basically, instead, you could do question mark dot as the method accessor.
- 47:28Right.
- 47:29Right.
- 47:29Instead of object dot like field dot upper, you'd say object dot field question mark dot question mark upper.
- 47:38Yes.
- 47:38It also introduces something called a ternary operator, which is a double question mark.
- 47:44But that already exists in Python, but it's pretty long form.
- 47:49You have to say something equals something if the thing is that else, not this.
- 47:55Yeah.
- 47:56And it is a little bit longer.
- 47:57The sort of double question mark null class none class operator thing does not excite me very much.
- 48:02But this fluent style of these chaining function calls that at any step may be none is super exciting to me because you might have to check.
- 48:12First, is the original object none?
- 48:14OK.
- 48:14Then if that's not the case, now is its name, you know, maybe it contains like a rich object.
- 48:20You know, is that like an address?
- 48:21Like, is the address none?
- 48:23OK.
- 48:23The address is not none.
- 48:24So is the street not none?
- 48:26OK, now we can call to upper on it.
- 48:28That's like one line, right?
- 48:29Object question mark dot address question mark dot street question mark dot upper.
- 48:35And boom, you get either none or you get an uppercase street name.
- 48:38I love it.
- 48:38Yeah.
- 48:38So if anyone works with like highly nested types, I guess, then and you have to write all these.
- 48:44If that's not none, do this.
- 48:45If that's not none, do this.
- 48:46Then, yeah, this is super helpful.
- 48:48Could be if it gets accepted.
- 48:51Yeah, it could be.
- 48:52It's one possible branch of the future.
- 48:55This will be very helpful.
- 48:55Yeah, I just one thing that I dislike a lot in my code is like sort of seesaw nested jaggedy code.
- 49:03And this can like turn that into just like a one liner, which I think is great.
- 49:06You also have called out runtime audit hooks.
- 49:09What might that be useful for?
- 49:11This is probably a security feature mainly.
- 49:14But again, it's a proposal.
- 49:15It's not been accepted yet.
- 49:17But the idea is that for any built in functions.
- 49:20Or as things in the sys module or some of the low level functions within Python standard library,
- 49:27whenever they got called by either your code or somebody else's code, you've got the option to set like a audit hook.
- 49:36So you might write a special application like a profiler, for example, if you're writing a profiler and you want to see every time somebody tries to open a network socket or calls a URL or something.
- 49:49Or if you wanted to develop security application that checked anyone who is, you know, opening file handles in the operating system or...
- 49:57Right.
- 49:57You could build a really cool package that you can just import into your app at the beginning.
- 50:02And it says, these operations are allowed.
- 50:04These are not like no network access, no file access.
- 50:07And with this, maybe you could just stop that globally in the runtime, right?
- 50:11Yeah.
- 50:12So kind of similar to what you can do with SE Linux, if anyone's familiar with SE Linux.
- 50:17You can kind of lock down the kernel effectively for certain users and certain method calls can't be run.
- 50:23So this would be similar.
- 50:25So you could basically have a Python interpreter.
- 50:28And when certain things are done inside Python, then your method gets called as part of an audit.
- 50:34You could watch for the eval function.
- 50:36Yeah, exactly.
- 50:37It is a little bit light on the details.
- 50:41The implementation is not finished either.
- 50:43But I know that Steve Dower is working on this PEP.
- 50:48And he has said if anyone wants to help contribute to the implementation or do some testing, then the door is open.
- 50:54Nice to get in touch with Steve Dower.
- 50:56Perfect.
- 50:57So maybe I'll just throw out a few real quick ones also that are like more minor.
- 51:00So for virtual environments, it now has an ability to activate this through PowerShell on Windows, which if you use PowerShell on Windows, that's pretty awesome.
- 51:09Yeah, that's awesome.
- 51:10I don't know why you wouldn't use PowerShell if you're using Windows anymore.
- 51:14If you want to use MS-DOS, that's fine.
- 51:16Yeah.
- 51:16It's not the greatest shell.
- 51:18Yeah, yeah.
- 51:19I like Commander.
- 51:20C-M-D-E-R.
- 51:22I think it's commander.net on Windows.
- 51:26So optimizations around file copies.
- 51:28That's been improved on the Unix-based systems, right?
- 51:32Yeah.
- 51:32I don't think that makes a pretty big difference, actually.
- 51:35Yeah.
- 51:35There's some built-in, like, sysplatform-specific fast copy.
- 51:38Like, I wonder if it uses the new Apple file system sort of replication stuff, which would be a lot faster.
- 51:45It'd be very cool.
- 51:46They also removed pyvnv, the script.
- 51:49So the expected way that you create a virtual environment is python3-m spacevnv, right?
- 51:55Yes.
- 51:55Nice.
- 51:56I don't really use that, but...
- 51:57Nice.
- 51:57Well, that's what they tell you in 3.8.
- 52:01Other minor changes.
- 52:03And I guess one thing that's interesting is python3.8 is temporarily...
- 52:07Like, it's pretty far out, so this might not be a problem forever.
- 52:12But right now, with Guido stepping down and the governance decision, like, the choice of how Python governs its decision-making is not decided.
- 52:21No new features are going into 3.8 until they can decide how to decide on those new features.
- 52:27Yeah.
- 52:27That's a bit of a weird catch-22 thing there.
- 52:29I bump into one of the core developers last month, and they said that it's likely that there'll be fewer features in 3.8 than there have been in previous releases, unless...
- 52:38Well, until they can work this thing out, and then even then, having, I guess, faster, sort of mainly bug fix and performance improvement releases is a lot more likely to be the way forward.
- 52:51Yeah.
- 52:51I suspect it's going to take a little while before this gets dialed in and it becomes a smooth process again, but I'm sure they'll figure it out.
- 52:58Yeah.
- 52:58Well, there's a few major things that kind of need to happen in future releases.
- 53:04I guess one thing is the startup time is still slower than legacy Python.
- 53:09I think there's ways for them to optimize that in terms of what it loads at import at startup and how it does all the importing and caching and stuff.
- 53:18Hopefully, that'll be quicker in newer releases.
- 53:21And then there's a C API, which has, over time, got a little bit messy.
- 53:25So I think there's a few proposals for Python 4 for that to have a bit of a revamp.
- 53:30Yeah, that'll be interesting.
- 53:31That's a little far out, but definitely be interesting.
- 53:33Maybe it'll be rewritten in Rust.
- 53:35Yeah, maybe.
- 53:36Yeah, I don't know about that.
- 53:38Anyway, that's a ways out, but definitely something to look forward to.
- 53:41Well, I think that's probably a good place to leave it.
- 53:44We're probably low on time, kept you long enough.
- 53:47But before you go, I know I've asked you this at least back in episode 155, but that was a while ago.
- 53:53I'll ask you again.
- 53:54If you're going to write some Python code, maybe your answer has changed.
- 53:56What editor do you use?
- 53:57It's still Visual Studio Code.
- 53:59Right, with the Python plugin.
- 54:01Yeah, it's definitely a nice thing.
- 54:03And it's like, I don't know how many times, millions, like 5, 10 million.
- 54:08I don't know how many millions there are downloads of that Python extension for Visual Studio Code, but it's pretty remarkable.
- 54:13Yeah, it's great.
- 54:14Although I'm using Windows at the moment with Windows subsystem Linux, which is causing me problems because Linux creates different virtual environments to Windows.
- 54:24So the IDE is using a different virtual environment to my actual application, which is causing me a source of pain.
- 54:30There's all sorts of process isolation and system isolation between the Windows subsystem for Linux and Windows itself, right?
- 54:37Yeah.
- 54:38So that's causing me.
- 54:39You're going to be an expert pretty soon.
- 54:40That'd be awesome.
- 54:41You'll be able to help people who are also doing this.
- 54:44Nice.
- 54:45All right.
- 54:46So notable PyPI package?
- 54:48Yeah, I'd recommend people check out Black if they haven't already as a code formatter.
- 54:52It's basically, if you ever check in code and then if the build fails because you've, you know, put an extra space at the end of a line or something, and you've had that frustration, then you can use this basically as a tool to go through your code and format it for you so that it passes most code linters and style checkers and stuff like that.
- 55:13And it's basically no options, no configuration.
- 55:15You just run the command, give it a directory, and it will just go through and change your code for you.
- 55:20I absolutely love that.
- 55:21I think the code it produces is really nice, really easy to read, and it's just really easy to get set up with.
- 55:27Yeah, most linters, they just complain to you, you should get rid of that space at the end or whatever.
- 55:31This one just goes, yeah, I'll fix that.
- 55:33Yeah, it just fixes it up for you and you check it in.
- 55:35Right on.
- 55:36All right, final call to action.
- 55:37People are excited about 3.7.
- 55:39What do they do?
- 55:40They need to download it first, install it, test it out, run their applications on it, see how they're improved, and then check out some of the new features.
- 55:49Yeah, maybe check out your course.
- 55:50Yeah, and absolutely check out my course.
- 55:52Yeah, like I said, it'll take less than an hour of your time.
- 55:55It's 57 minutes.
- 55:56And you can find out all the details on Python 3.7.
- 56:00Yeah, awesome.
- 56:01I definitely agree.
- 56:01People should check it out.
- 56:02There's some great features.
- 56:03And Anthony, thanks for being on the show to share them with everyone.
- 56:06Thanks, Michael.
- 56:07It's been great to be back.
- 56:08Yep.
- 56:08Bye.
- 56:08Bye.
- 56:09This has been another episode of Talk Python To Me.
- 56:12Our guest on this episode was Anthony Shaw, and it was brought to you by Tidelift.
- 56:17If you run an open source project, Tidelift wants to help you get paid for keeping it going strong.
- 56:23Just visit talkpython.fm/Tidelift, search for your package, and get started today.
- 56:28Want to level up your Python?
- 56:30If you're just getting started, try my Python jumpstart by building 10 apps, or our brand
- 56:35new 100 days of code in Python.
- 56:37And if you're interested in more than one course, be sure to check out the Everything Bundle.
- 56:40It's like a subscription that never expires.
- 56:43Be sure to subscribe to the show.
- 56:45Open your favorite podcatcher and search for Python.
- 56:47We should be right at the top.
- 56:48You can also find the iTunes feed at /itunes, Google Play feed at /play, and direct
- 56:54RSS feed at /rss on talkpython.fm.
- 56:58This is your host, Michael Kennedy.
- 57:00Thanks so much for listening.
- 57:01I really appreciate it.
- 57:02Now, get out there and write some Python code.
- 57:04Thank you.
- 57:24Thank you.