What's New In Python 3.12

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
how's it going guys in this video I want to go over what's new in Python 3.12 and I'm quite excited to try these new features even if we won't be using them immediately in production code since it takes so long to actually get to the latest version and a lot of people have to migrate from one version to another we still have a lot of time before we start using python 3.12 in a lot of projects but it's still cool to see what we can use in the near future and I'm not going to be covering every single detail but I will be reading the release highlights so at the moment we have some new grammar features we have an interpreter Improvement we have new typing features and some important deprecations anyway the First new feature we have are some improved error messages for example in case you forget to type in a module it will tell you okay did you forget to import this module so that's one of them another one is in case you forget to add something such as self tier class because sometimes you might refer to something that belongs to the instance but you will forget the self keyword and that's an honest mistake to make as you can see down here we have the name error name black is not defined that you mean self.black which is a great hint to what you did wrong in your class and they also added a syntax error for the Imports and this is something I thought that was always interesting because I always found it more readable to say import blah from blah but of course that's wrong in Python you need to type in from Bla import blah so those error messages have also been improved next we have one that's actually quite interesting and this is the syntactic formalization of f strings and first of all we can finally start reusing quotes inside an F string which is quite cool because we don't have to jump around from single quotes to double quote to single quotes to make an F string anymore we can just now directly use them inside the F string which should help simplify Our Lives when we are working with strings and because of this we can now Nest these F strings without having to perform any crazy gymnastics such as using triple quotes and then triple single quotes and then a single quote and a double quote just to Nest these F strings and you can actually copy this and paste this in your code editor and it will work I've never had to do this I've never nested an F string in another F string but it's nice to know that you can do it now just by using normal quotation marks you can also Define app strings that span over multiple lines now which makes it easier to document in case you want to document your F strings honestly I don't know why you would do that I haven't tried that yet but it's something you can now do and finally we can now use backslashes so if we want to pass in let's say a black heart suit we can do that now with f strings this was not possible previously because backslash could not be part of expression components of app strings in earlier versions of python and personally I've never used this but it's cool to see that we can finally use it in case we want to anyway there's also a positive side effect of all this new syntax and that is that the error messages for fstrings are now much more precise moving on for Pep 709 we have something called comprehension inlining and to sum this up it's just going to speed up our list our dictionary and our set comprehensions because they are now inlined so now it doesn't have to create a new single use function object for each execution of the comprehension and they State here that this will speed up the execution by up to two times the original speed then we're going to cover this in a future video but they're now also making the buffer protocol accessible in Python so pep 688 introduces a new way to use the buffer protocol and they didn't provide any examples here but we will cover that in a future video as soon as python 3.12 actually comes out and something that I find a lot more interesting that I hope to cover as soon as python 3.13 comes out is Pep 684 a per interpreter Gil because now we can create sub interpreters with a unique Gil per interpreter so there's no talk in this article regarding removing the Gil but you will have some more flexibility with being able to create sub interpreters and in Python 3.12 we're only being exposed to the C API so I'm going to wait until 3.13 when they have the python API available because that will be much easier for python programmers to actually use next we have some new features related to type hints and if you've been following along with the content on my channel you will know that type hints are absolutely my favorite subject to cover in Python so starting with pep 692 we can now use typed dict for more precise keyword arguments typing which means instead of just saying okay our function takes these keyword arguments we can now specify what the keyword arguments should actually look like next in pep 698 we're also getting an override decorator for static typing so if we have some sort of Base Class and we want that Base Class to override a method such as getcola we can annotate it with the override decorator and since getcola does override the original get cola this is going to work just fine but if we go to the second example of this class where we override something that uses the British spelling we're going to get a type Checker error that this does not override the getcolor method because obviously we did not spell the correct name which means we're not overriding anything we actually created a new method that just does its own thing in pep 695 we're getting some type parameter syntax so now there's a new more Compact and explicit way to create generic classes and functions and something I found quite interesting was the new type Alias syntax because recently I've been covering a lot about type aliases but now they're introducing some new functionality that allows us to create types in an easier to read way just by using the type keyword and what's cool about this is that we do not need to import anything because type is already part of Python's syntax and just by using the type statement we're going to create an instance of type Alias type so I'm quite excited to try this new syntax as soon as python 3.12 comes out there are still a couple of months to go I believe it's coming out in October or at least the stable releases coming out in October 2023 so I'm actually really excited to learn these features and bring them to you as soon as they come out but until they come out I'm not really going to be looking into them or creating any videos about them and I will be leaving a link to this article in the description box down below because there will be some other changes and improvements that you might want to read up on as you can see there's a section called other language changes I'm not going to go into that I just wanted to cover the major updates or the highlights so feel free to read up on this I'm going to read up on it more so I'll be quite prepared by the time it actually comes out but that's actually all I wanted to cover in today's video do let me know what you think about python 3.12 whether you're excited for the new features whether there's another feature inside all of this text that I missed that you're actually looking forward to I would love to hear about it in the comment section down below but with all that being said as always thanks for watching and I'll see you in the next video
Info
Channel: Indently
Views: 82,959
Rating: undefined out of 5
Keywords: pyton, pyhton, pythn
Id: 1bLlmKzIx0A
Channel Id: undefined
Length: 7min 31sec (451 seconds)
Published: Wed Aug 09 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.