Transcription
This version of Python will simply eliminate most of the problems you had before. I have thoroughly studied the release of Python 3.12 and found some cool improvements related to speed, ease of writing code, generics, and many other technologies. Throughout the video, I will cover absolutely all the features and capabilities that will make your code better. I will also answer the question of why Python is turning into C++ and how it relates to ZIL and all the technologies mentioned in the video. I have gathered all the information about the release, so I recommend watching until the very end, as there is important information throughout the video.
Most of the features will shock you. For example, how about this? This is Python, by the way. Let's start with the fact that the current version, Python 3.12, was released for testing on August 6. Since that moment, all features and changes will not be edited. On October 2, 2023, this version will be officially launched. This means it will pass all performance tests, and developers will fix bugs, and so on.
But what are the main focuses of the current version, and why can it change a lot? The Python developers have likely noticed the constant complaints from the community that Python is an incredibly slow language, and they have been working on improving performance. With each new version, Python becomes faster and faster.
Later, I will explain what they decided to do with the Global Interpreter Lock (GIL), and you will be shocked. For those who are not aware, the GIL prevented us from using threads in parallel. The problem with current threads is that they weigh much more than they should. If you perform operations that require CPU computation, running 100 threads will result in a speed that is twice as slow as if you didn't use them at all.
But will this now be fixed? We will get powerful threads like in C++. The team is starting to work on GIL, making optimizations and improvements. They are transitioning from a single interpreter lock to a lock for each thread separately.
Imagine you have 100 customers and one seller. Each person must wait their turn to approach the seller to complete their task. The seller can only serve one customer at a time. If you remove the GIL, it would be like a store without sellers, where 100 customers just walk in and do what they need completely in parallel, without a filter in the form of a seller.
What does this new approach give us? We haven't completely eliminated the GIL, but the effects of the new implementation will still be incredibly cool. If we take the previous example, instead of one seller, we will have, say, five sellers serving customers. This means that our threads, which we run under interpreters, are now created with a unique GIL for each interpreter separately.
This means we can now use threads that will utilize multiple CPU cores and work in parallel. I think this is fantastic news! Be sure to leave a comment about what you think of this and whether you want such threads that will work in this way.
When the implementation of this technology is also done in C, we can finally discard all our old workarounds with threads and use clean Python code. But how will all this look? Will we be able to create a new interpreter object just by executing bytecode?
So here is the page, PEP 554, where this technology is described. It starts with several signatures, then the example shows how to create a new interpreter object through code and execute code just like in exec. But how do we apply this in threads? It creates a function, and this function is then passed to the thread. As a result, the thread is launched, and inside the thread, sub-interpreters are created, and the code is called.
But I think this is still a huge workaround. It can be improved later. If you need many lines of code, you write it like this, which is very bad and also unsafe. It currently works just like regular threading. There are all these moments with channels, threads, and so on, but it is still a bit raw. I hope it will be more refined before the release.
Now you will be shocked because you probably never thought this would happen in Python. They decided to add generics, and in Python 3.12, it will be more convenient to substitute types and make them dynamic. We will also be able to declare a specified type using this construction, directly using Type.
There is still little information about this technology, but later I will prepare a video for the private channel where I will show a real example of usage. I will also dig deeper. On the private channel, I publish separate material besides YouTube and gather the best content. From time to time, I find top features that are not discussed anywhere, such as various libraries, tools, and ways to improve your projects.
For example, I plan to add the same features from Python 3.12 and show the best ways to apply them. The first link in the description leads to my course, which includes access to that private channel. This course stands out from all other courses on this topic. It is not just a course that covers the basics; I have gathered a lot of tips and recommendations from my own research and put all of this into one course.
When people complete the course, they leave feedback, and absolutely everyone notes that this course contains a lot of unique content and features that are not discussed anywhere else. What can I say? In a recent update, I added over 100 new features and research that significantly improve the approach to development.
Since the course and the private channel are constantly updated, imagine how much top-notch content will be available in the future. Both beginners and advanced developers will benefit from this. Everyone can find top content for themselves and gain immense value. Access to all these resources is granted forever. You can take the courses anytime and ask me questions personally at any time.
I have cut out all the fluff from the videos, so by watching a short 4-minute clip, you will understand the same technology that many study in the documentation for several days. Moreover, there is a guarantee: if you don't like something, you can get your money back.
Currently, I plan to enroll only 20 people so I can manage the flow of people, so leave an application through the first link in the description. The application form is still active, which means you can easily sign up for the course and get access to the private channels and chats right now.
The third change is directly related to strings. What has been improved here? I don't know about you, but I was personally annoyed by the fact that when using strings, you constantly had to use different quotes. If you created a string with double quotes, the content inside had to be single quotes. If you put double quotes somewhere in the text, it would close the string and cause an error.
There were situations where these strings had to be changed often, and constant editing of quotes was just infuriating. But now you can save your sanity and use any quotes inside strings. If you used nested strings, which I personally never did, you had to create terrible workarounds. But now it looks clearer and overall has become more convenient to work with.
So here is the page. Here we have regular strings. Initially, the string starts with a single quote, and we also have content with a single quote. As a result, in Python 3.11, we get an error, but in Python 3.12, if we do this, everything will be fine.
Previously, we used escaping, and we didn't have comments. Now we can add comments inside strings. Also, the problem with the previous version was that it created additional costs for analysis. But now we have a string with double quotes, and the content inside is also with double quotes, and everything works. These are nested strings, and nothing breaks.
This is much better than just the previous version of nested strings. This is our new version. But how does all this work? We have new tokens. As I understood from other documents, there were many tokens for strings that were responsible for the beginning and end of the string itself. If we start with a double quote, the end must also be with a double quote. This is how it understood that the string ends.
Now we have a different token that ignores the quotes. There is another way to determine whether the string has ended or not. Here is the example of how the analysis goes. You can pause this and study it. I will also publish various examples on my Telegram channel, so I recommend subscribing to not miss anything.
The fourth change is that the Python team clearly did not watch my video on how to distribute a project into components and create a modular structure. The previous implementation of the virtual machine contained 8,000 lines of code, and all of them were in one file. I mentioned in my video that such an approach complicates both understanding the code and its further maintenance.
So, the Python developers rewrote the virtual machine using a new DSL. In Python 3.11, there were also bytecodes that could be replaced with a more optimized version, and now the focus is on this. But what are these bytecodes? For example, when returning a value from a function, two bytecodes are called for loading and returning values. But there is a possibility to replace this with one bytecode that will perform this action.
Old variants will be replaced with more optimized ones, which will speed up the entire execution process.
The fifth change is that Python has become even simpler, as new types of errors have been added. In previous versions, errors were not very intuitive, but now they directly state what needs to be done for the program to work. If you forgot to import a library, misspelled its name, or violated Python syntax, the error will tell you how to fix it.
More understandable errors have also been added in strings. For example, we use `sys` but forgot to import it. The error will directly say that you might have forgotten to import it. Similarly, with classes, if we use `self` but do not apply a variable from the instance, it will say you might have meant this.
It can even analyze whether a given function or class is included in the package or library. These are the errors from strings, which simply state that you might have forgotten a comma here.
The sixth change that you will really like is that list, dict, and set comprehensions have been built into the language and now do not create new objects. What does this mean? It means that such constructions will now execute twice as fast. Variable operations remain isolated through stack manipulation, and as a result, they do not overwrite variables in the outer scope.
Thanks to all this, we get faster execution. Next, there are some changes that have significantly impacted Python 3.12, and we will continue to look at the top features of the release.
So, what important changes have been made? Object slices are now hashable, allowing them to be used as dictionary keys. The function itself has started using new algorithms to improve calculation accuracy. Unit tests have also added a new argument that shows the slowest test cases. This is a very cool feature that will be useful to many.
The `isinstance` function has been significantly changed; it now works on a different algorithm, improving performance. Compared to Python 3.11, the speed was at least twice as fast, and in some cases, up to 20 times faster.
Changes have also been made to asynchronous functions; some have become twice as fast, while others are 5 to 6 times faster than in 3.11. Next, there is a series of optimizations that also speed up some components by two or three times. Functions due to regular expressions have been accelerated, and tokenization has also been sped up.
The sixth change added in 3.12 is new type hints for overrides, which I plan to discuss in the course update linked in the description.
So, in conclusion, these are the new type hints. We create a class inheriting from `TypeDict`, then we have attributes, and then a function that takes a type. Here, this is the type; we understand that this is unpacking from the `Movie` type, meaning from this class.
My override is a very cool thing. We have a base class with a method `getColor`. This method needs to be inherited and overridden. Here, everything is fine, but here is an error in the name. It understands that this method does not correspond to this class, and as a result, we get such an error.
What technology do you think deserves attention, and what did you like the most? I would also like to hear your thoughts on the generics feature and whether you personally liked it. I think this is a pretty cool solution, and I will definitely use this technology.
Don't forget to like the video, as the more likes we get, the more motivated I am to create top-notch content for the channel. If you watched the video until the very end, add your comment with the number 7 so others can see and not understand what it's about.