 Govorim, da so se darjali. In da so俗 professionals, na tem, da se oprejšli koliko bi je dobilo 3.11. Ko je začel, je dobro, vsačo, bilo zelo, materijali. Sebej, da je meni, nekaj bo se počučila 3.12, nekaj je 3.11. biti biti biti občastno. Python je moj prišličnji ljub. V 2007. Vsem zelo vse progrom, ali održavljali od vrstvena začel sem održavljala v mene, vse ljub je zelo se posponil. Vse je C++. Zelo sem vsej vsej vsej vsej vsej vsej vsej. Peter Science. Protočno z Google Engineering. Moje vsej vsej vsej vsej džargo, data science, machine learning in AI, like everybody else in Biden, almost everybody touches and tests machine learning or AI with Biden. Okay, what we are going to talk about today. The type dicts, the self type, improve their own messages, as in AI, Tom will read only supporting SD lib, improve type variables and speed improvements. I will start first with the typed dict and what is it, what is required and the types of inheritance we can use with the type dicts. First of all, I would like to ask you, do you know what type dict is and have you ever used it? Okay, okay, okay. Okay, actually type dict was specified in PEP 589 and introduced in Biden 3.8. On all our versions of Python actually, versions before 3.11, you can install it from typing extensions or in other words, this is PIP install typing extensions. In Python 3.11, it's directly imported from typing. So we can just use typing library. Type dict or just a dict. It's a question asked all over the web in the forums and in general when it comes to the newest version of Python. Actually the dict key and variable type lets you declare uniform dictionary types where every variable has non-defined type and arbitrary keys are supported but the type dict allows you to describe a structured dictionary where the type of dictionary variable depends on the key. The interesting stuff is that like if we have this example here and I will try the laser now, okay. If we have this class and the method and if you decide to, for example, call it and if you change the values here like for example, instead of a string we have let's say an integer. The ID you use, it will warn you that something is wrong and a string actually is expected to be seen here. I think I prepared some examples here for you guys where we can see something interesting like for example, let's go here and we have the string, we have the integer but let's say if I change this one here to this one. Sorry. And you will see that I was warned that it is expected integer to be put here instead of a string. So, let's continue. This is the first example, of course. So we have here integer, a string and a list of integers and of course this is expected to be to have the same types of values here. This is the second example we saw so we will go to the inheritance now where there is an important rule of thumb here when you use type dict and it is that type dict cannot inherit from both the type dict type and the norm type dict base class. So we have, I think something pretty simple here where we have a class of songs, a class of band name where we have strings and this is a way to call the type dict. It's an interesting way, interesting syntax actually and we have a multiple inheritance here where we have one class A, one class B and if you see here we have a regular way to define a class but if we want to combine them into multiple inheritance here this is not possible and even the interpreter will warn you for this. I can show you this example here. Let me turn this and you will see that we have an arisen error, which is here, yeah. Let's continue. Same happens actually here but there is also an interesting thing that you have three types of classes here, actually three type dicts and in the result song you can even combine them, like for example you have the song info first and you have the band, look at that this is just the band not band info, band info and you have the lead singer so they can be even combined or when you call them. There is also another way or this is also called the nested type dict example where we have of course the type dicts and we can nest them in that form of the syntax. I know it looks a little bit complicated for reading here but this is the syntax, of course you can make them multivire. Required and not required. This is another thing introduced into Python 3.11 where we can use from typing important along with the type dict we can also import the not required, not required thing. So we have the attributes of the type dict like here we have the name, we have the age and about the person we can ask if it's merit or not but if we will define not required in this form of course you have to define the data type. This is not required actually so if you test it like this like for example PyCharm will not ask you to add it here but if it's required, like for example, I prepared a small example here for you, again, if you make it required then it will be expected to be seen. Let me see if I have it here, think so, not sure. Oh, it's here. Yes, so here it's not required but see what happens if I remove not required. This was highlighted because if I go with my mouse here it will tell you that the type dict user has missing key merit. This is a very convenient thing for us, the developers, because if we miss something the idea will remind us that something is not, something is not okay or we skipped something. This is another example here where we have, this is actually what I showed you but there is another thing, another interesting thing here is that instead of not required you can import required but then you have to add the parameter total equals to false and then you can choose what is required and what's not required. In this situation these two will be required and the third one will not be required. So the result will be almost the same, just the syntax is a little bit different. You can also control what is required and not required with the unary operators, the plus, minus and I don't know how to pronounce this sign actually. So if you have the plus this means this is required. If you have minus this means of course it is not required. This special sign actually means the opposite of the normal totality key. So this is another interesting way and it is the shorter way actually to be done because in the other, in the previous two examples you have to write a little bit more so it's all up to you. I've seen in GitHub in different examples and different applications and code, pieces of code, both of the ways for defining the attributes. The self type, the class method becomes self in 3.11. Previously if you had to define a class method that return an object of the class itself it would look something like this one here. So we have the type var here and this returns no but we have the class method and it will return the t and after that you have the regular stuff for the class method and to be able to say that the method returns the same type as the class itself you have to define the type var and say that the method returns the same type t as the current class itself. But here is what happened with the self type. So first we have to import it actually. We have a class language here with the init and the change version and of course this is where the self is returned and also another interesting example where we have one class and another class and when both of them return self you can use the methods of both of them and you can even combine them and of course I will show the examples now. You will see that they work. So this is the first one and you will see here that the version of the language is changed because we use the methods here to change version but if we go here and if you will see that this will work now because both of them this is normal to be returned both of them actually return self. Here is what happens if I change for example this one and I set it to brand. And boom, we have an error. So both of them when you use self both of them should return self, okay? Another thing we have in Python 3.11 and this is actually one of the most slovaht things in the community. Python is that we have improved exceptions. And I will show you some examples. What these improved exceptions actually include are better error messages, exception nodes and exception groups. So in the better error messages first you know where your error is or Python is able to highlight the exact place the exact spot on your lines of code where you have errors, could be more than one. Hopefully we don't have any errors. But this is almost impossible. Exception nodes leave yourself a note in your custom exception. Yes, we can already leave exception nodes. It's relatively simple to be done. And exception groups. This is where we can define exceptions, we can group them and we can use them. When it's appropriate to be used. Until now in the trace back, the only information you got about where an exception got was the line. Yes, until now we got just the line. But now if you see this example here there is an error and you will see it in the next slide where Python already shows us the line and also shows us the reason for the error. In this situation we have unsupported operant type of S4. This is for dividing here and we cannot divide a known type in an integer. So we have three elements here. Actually we have the line, which is something we have previously. Then we have the line two and the exact error and we have the type error. I think this is pretty cool. The exception nodes actually, this is something that is really new and it's coming in the PB678. And inside your except causes you can call the add node function and you can pass a custom message when you rise an error. I will show in a second what can be done. So you have a video here, we have an add node and this is a small piece of code where we import math and we try to square the minus one but we will get this message here where we added the node negative value best, please try again and we will raise it. I know that the syntax is a little bit exotic, I would say, compared to what we used to write this code but this is what the new thing is. And of course I think it's very convenient because we can write almost everything meaningful to us instead of just rising the regular errors of Python but this is up to the developer, I think. But I find it really convenient. And another way to add exception nodes actually is if you define class, if you use these non-normated nodes and this is a custom error, have a look that you define your message into a list and when you try this, this is a more, I would say, more clean way to write the code because you try to square the number and you have the exception to just write your class defined in the form of exception and you can see on the right side of the slide that this is actually does the same thing but you see also that this is a custom error along with the regular errors of Python. Exception groups is something that is also very interesting. One way to think about the exception groups is actually that they are regular exceptions wrapping several other regular exceptions. This is why they are called groups, of course. However, while exception groups behave like regular exceptions in many aspects, they also support special syntax that helps to handle each of the wrapped exceptions effectively. In Python 3.11, we group exceptions with exception group. I mean, this exception group method. So if we use this, you can also, you can add a message here and then you add all of the types of exceptions you want to be raised in the list and you have to be careful with the order because they will appear in the same order when they are raised. This is how they look like and you will see that they, if we get back, we have the final not found so we have here the final not found, our first message we defined is also here, then we had a value error, the value error is also here and zero division error where the zero division error is here. You can even call them one by one. It's a little bit complicated, of course, because the syntax is again a little bit exotic, but it is, we have tried something and we have the except with this asterisk here, final not found as FNV and we can print them so we can see the, actually we can see here the actual types of the errors and the messages just like, like over winds of let's say strings, for example. I think I owe is something that is one important thing that is improved here, actually created, is the task groups where if you have this example here, the newest thing is that you can make a task of groups and the groups of tasks actually, sorry, and they will be executed here. Oops, something happened. Okay, so there will be, there will be, you can also do here loops, conditions and so on, so tasks here will be, there will be executed, of course, and this is how they, how you can actually groups all these tasks into one function, compared to what we have here, where things are kind of a little bit, kind of a little bit more complicated. Or you know, this was created for more clean and more readable code. Tomo support or Python has the ability to read Tomo files for a very first time. It is a Thompson vise minimal language, configuration file format that's gotten popular over the last decade. The Python community actually embraces the Tomo as a form of trust in specifying metadata for packages and projects. I seen this in different projects actually, and I think that it's been widely used already. It's been also designed to be easy for humans to read and easy for computers to pass. And the Tomo has been here for years and used by many different tools, but unfortunately, Python hasn't had built-in Tomo support, which changes now in Python 3.1, when Tomo link is added to the standard library. Yes, it's included directly. This new model is built on top of the popular Tomo third-party library and it wants to pass Tomo files. I think you know how Tomo file would work like. This is an example. Actually, with the new Tomo library, this brings support for parsing. We can parse them, but we cannot write to them. Still, we cannot do them. When using this, we can use the load function so you can pass in the file object that must be opened in binary mode and we can specify the mode to be RB. There are two main functions in the Tomo library. Actually, the load that bides from a file and the load is from string. And you can see here some examples how this is done pretty much the same how we open files in Python actually. Okay, improve time variables. We have here the arbitrary literal string type, data plus transforms, negative zero formatting, improve time variables and variadic generics. In interesting thing here is that when we have the arbitrary literal string type and if you have defined a literal here, actually if we add another type of string, Python will warn us that it expects to see something different instead of what we define. But to under this limitation, Python 3.1 introduces a new general type, literal string. So we have a literal string, which allows the users to enter any string literals like below. So if we have instead of just literal, if we use literal string and we can type any kind of, any string actually here, so this will be accepted. This is also applicable when constructing literal SQL query strings and you can refer to the official PB 675 to read more about this. Variety generics is something that's also very interesting. So if we have this generics here, you can, when you define classes, you can start in here it, here this generics into the classes and you can even combine them. Like here, it's dim 1, 2 and 3, 3 of 3 are here. And also as shown for three dimensions, we will have to define these three types and their respective classes, which is not cleaned and it presents a high level of repetition. Yes, we have this high level, so that we should be cautious about. And in Python 3.11 introduces the type var, the type var tuple. This type var tuple actually allows us to create generics using multiple types. Like, for example, if we have this generic type var tuple, we can assign it to a variable and we call it here, then we make a class and this is pretty much likely how we impact the arcs and how we impact the arcs, for example. Negative zero formatting is fixed here. So, like, for example, normally there is only one zero and it's neither positive or negative. And we definitely had this error previously. I've tried it several times just because I was curious and one will conceive that you might run into when doing calculations with voting point, especially the voting point. Previously, we can say that Python will return us minus zero. Now this is already fixed and we don't have such a problem anymore. Data class transform is something that is a little bit more advanced here. I don't know, have you ever guys used this, raise your hands, the data class transforms? Oh, okay. Okay. We know the data classes since Python 3.7. It's a meta class that helps you deal with data-oriented classes and using data class decorator like init, hash, qq, and all the other methods can be generated. This is how the data classes are. This is the syntax, actually, the general syntax and an example how they can be used. On the second code, on the next file, we add it to the class, among other things, and init. So, if we will see here that we will, this will also generate an init. So, we have the attributes here, but we also have init instance with quarks. It's a little bit comprehensive, more detailed, and requires a little bit more writing of code, but we have the data class transform here, and the as-model method, what this is for, this is just for testing purposes, of course, to see what we print, but this one here is very important, because this actually will generate our init without actually defining it here and using these attributes. So, the function will take them and it will automatically create init for us. So, this is what is usually called, this, what is usually called, what usually means the transformation. And only the example is a bit more complicated, but it is one of the best for understanding how actually this conception works. Of course, we have some speed improvements. Some people believe very hard that the speed is really improved, some other people don't believe it that much. So, something happened here in my heading, but this is actually, many people say that this is the first significant change in the data scientist. It is a speed improvement, and actually data came here, and they didn't test, and they found out that, during the standard benchmark suit, that runs about 25% faster compared to 3.10. Of course, the comments, they claim that it will be up to 60% faster. Actually, what data came did is, they compared to docker installations, and they were with full with functions, so we have the Monte Carval, transforming numbers into floats, some work with rejects, and you can see the differences here. In milliseconds, of course, I don't know how accurate this test is, but it is one of the most popular around the web, so I decided to include it into my presentation. There were also other people claiming that there are differences, really big differences between Python 3.10 and 3.11, where they made some tests with algorithms, different kind of algorithms, or processing big list dictionaries and so on, so they see really good improvement, but we will see in the future, I think, what happens. And let's talk a little bit about Python 3.12, because it's coming, it's planning to be released during the autumn, so let's see that they claim that we will have even better error messages. We will also have errors about missing modules, so if something is missing, the IDE will be able to give us some warnings that we miss something without being generated on error. We will have a support for the Linux per profile, better protocols, protocol genders, run in a profile, or attach in the bugger to a Python problem, gives you the visibility, and insight into what the problem is doing. This is something that is mentioned to be revolutional, but we will see what will happen, because I think it's revolutional today, but actually they are not so significant after that. In Python 3.12, you can use the type dicts as a source of types to hink keyword arguments used in a function. So we will have, when it comes to the type dicts, we will have even better idea of what kind of arguments we missed, or we have to use, or what is the type of the value we have to return, and so on. So this is expected to be created for us, to be developed for us. Better garbage collection is promised, I don't know if this is what will happen in the future, but we will see better parallelism from what I saw the community is actively working on this one. Immortal objects, it's another, it's new in another interesting conception, where every object in Python has a reference counter tracks, how many times other objects refer to it, it could be built in objects like no. So this will make them immortal actually. Comprehensions and syntax, syntax that lets you quickly construct lists, dictionaries and sets, they could be constructed now in one, rather than by a way of temporary objects. I don't know how this will help us, because at least in my, what I imagine this might be a little bit complicated compared to what we have, but we will see maybe the syntax will be more simple. And of course they also promised, still not worthy performance improvement. We will see actually, what will happen in the future, thank you. Awesome, we have plenty of time for questions. I think I've learned a lot in this talk, then like new things here. So let your curiosity go wild and you can queue here for questions. Thanks for the presentation. Thank you. Maybe I don't know very well generics and stuff like that. Could you re-explain a bit, please? What does it mean, the variadic generics and what it is used for with the dim example? It's actually a conception for, as I said, a cleaner code, where we will have the chance to combine the generics actually. They will be kind of packed. So as I show in the example here, I can get back in so you can see them. Here it is. Look at the second example here, where instead of these lines, we have this line here and after that during the class, we can use them here as an argument to the class. So this is what the variadic generics conception is in 3.11 if it's answered your question. Hello, so my question is regarding the type dict. Can it be configured in a way to give also runtime errors rather than static time errors because the users in the runtime they may, I mean, since Python is very dynamic, they can still make a mistake there. Is there some way of also... Yes, I think I read somewhere on the web that this is more planned for the next version, the 3.12. We will have it there, but it's still a rumor, we don't know yet. We will see it in the next months, actually in the next few months, because from what I understood, the 3.12 is planned to be released in November. So in the next month, we will understand about this, but this is a good question, yeah. And there are a lot of rumors all around the web, around your questions, so yeah. Thank you for the question, really good one. Thanks. Hi, I have a question about rising exceptions of that new syntax. Currently we could rise an exception by just passing it into the brackets when you rise the exception. And now we have that new syntax with that nodes, a bit cryptic one, as I wanted to ask if it's the same thing, actually, or it's different in any way than just rising it. I think it's similar, I think it's similar. Actually, this one was created just to be easy for us, exceptually the groups, because we can combine, as I said, everything at one place, and when it's rise, you know that we have a value, we have a zero division, we have a final node fund, so it is up to you what will be defined here. Okay, thank you. I've got a question on the self type. Is it only meant to be used as a return type for methods, or can it also be used on the self type? Or can it also be used on the self parameter, where methods take the self parameter? For now I've seen two types of utilization, actually. Let me get back. So you can use it in two forms as a return self, and when you use to return the type of the data. So this is the two utilizations, two types of uses you can implement for now. At least this is what I've seen already on the official documentation and what people talk about. Okay, thanks. Nobody tested anything else, or at least I don't know to be made any other test. We will see in the future, maybe in 3-12, we will see more about the self, because it will be extended there for more than now. Okay. Any more questions? Don't feel shy. Cool. If not, the leon would be available offline to chat. Please have another round of applause for the leon.