Add to Watchlist

Decorators demystified


Citation of segment
Embed Code
Purchasing a DVD Cite video

Formal Metadata

Title Decorators demystified
Title of Series EuroPython 2015
Part Number 96
Number of Parts 173
Author Enfedaque, Pablo
License CC Attribution - NonCommercial - ShareAlike 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this license.
DOI 10.5446/20178
Publisher EuroPython
Release Date 2015
Language English
Production Place Bilbao, Euskadi, Spain

Content Metadata

Subject Area Computer Science
Abstract Pablo Enfedaque - Decorators demystified Do you know what happens every time you use the **@** symbol in Python? In this talk we will see the magic behind the syntactic sugar of the decorators. To understand how they internally work we will see in detail Python's **scopes**, **namespaces** and **closures**, and finally we will manually apply our own handcrafted decorator. Level: Intermediate. Attendees must have previous knowledge of Python and should be somehow familiar with the **'@'** notation to decorate a function
Keywords EuroPython Conference
EP 2015
EuroPython 2015
and that's the dismissive the management fun of look for instead you should use it the limitations usage and we look at the list of we so you want and you the only myself or my complaint it's the the great because it is defined and we
will take a little ways that understand what I'm saying what we think that we should that's again and so that actually
limited knowledge of the but I think basis this course if we really want to spend a great because we have to understand the basic skills invite this is youngest and then you will really understand how what according the how many of you have implemented this will allow you understand whether you implement use that the workflow copy-paste name the play something and because the fingers and the arts so let's think about why it works so at the end of the especially when they always on and after the great to begin with will understand all the bases and integrate and then will implement a word on the great innovative simple process you assume that the energy is really simple to understand that before proceeding with which they goal stop that and we still use something that we
used in that the game has played these are really simple support you what a start case and the is the knowledge of the present for the rest of your life because of his addiction we also gives the order in which you are the units that produces the genetic why do I use a bit because they can lead the sites they want to limit the size of this fact this is that's what they want I want to this decide so you can see that I can last falls here it means that by problematic and and most all this the 1st and 2nd idea 1 of the for what is right it's is the spice of the world and they they understand that yes it is
simple but the never use it please never and that's not the way we would like to rule user but for the sake of the example we will use it OK but usually you should use phone calls love and you got sense by company that little of the the other thing but a unified gold so both of actually think it is i've standing in by the full Board of 7 and the 6
use of if you made so for that thing why it was that both of but they have right in all the development then I think it was it way so the full term calls it saddlebags In the case of only 1 because of but in the case of the when actually 2 recursive calls you can understand that you want is way would but the
goal is yet of however there is
nothing lot but did you ever do that without was a possibility of existing back to the how many of you come from each of our if for their uh 512 job all of the matter is that what this exam maybe here love except maybe here but mn declared outside the function is it was not thing 4 lines of Python maybe it's like a and there is no problem but that is something that lets you access that name did you ever of the other what about the
possible that the function call spits you know that you are how this name when you played and a function and then take the value 1 to call myself how they there is a
magic that's another example given report of a woman a ready for class from model and there's no classes went to polls in the same they 1 of the overriding other because they have same name but there are different models and they don't trust it what what's happening here even they have a function with again as 1 of the elements in class of problems here compiling wasn't what but that complaint right it something that by from was using new was this way and you program so we want why is it would was
1 of the ways that have that is that they will move on past visits with 0 have in thank you within mechanism faces is a mapping for named for alleged to objects you you know in Python everything is a point so was appointed is an engineering to the point that the and that's why I
1 let me explain something some examples of these places the beginning functioned acceptance we implement something like that that the X said that systematic another exception whatever I is it working what is an indicator how is it possible that you get in that we have important because innocent space that you can access we'll see how this always works of this axis what state but that the the is that that is the global in in every molecule later got to so that at learning model order dublin you this way because again it's on to consider models a lot of a couldn't of hours Python maybe that missing data because the language isn't only city and of love inside all you fact all your execution but he but that's what happened at is only at the level at the the a model and then only access from being inside them all so that same the little added the all right that's a collection of function of attention because exactly that shows the guys and many of the function is look out their name inside the function what these each side was it was the they've just sort of language is material with this alignment but the thing is when the that it also creates some the blow uh name of accessible for you OK they have be teams but the plan and that the law it allows to let the vision of the the data that we're going with
feminism so there is no correlation between names in different spaces that's where we that have popular model and but know that mothers because they are in different places and that's why they don't fly if you if you use the same name in the same space what will happen is that you what the replacing the point that yeah assigning a new object to than that right I was saying maybe is
that created and at different moments have before left the 2 more examples for instance emitting namespaces kicking the back into the past and it's never really and here you close and that the 1st
that but allowed them all you know the it's created when you're in you know I I it's it's created this way you'll uh they might as it was in the I had a problem that we use of a model this cater for phystat face when you mean for their their the model for also and then he said because Python use if you import dissimilar from different places and then you got your application it's only uh the that led to that the file on the big ones and by this doesn't to the to the memory so that if this is the that the 1st time in the unless you do something like that you you can download forced by solved and that's the way to the state in a space and created the and that's the only way you have to leave otherwise ministries we demand that together with important 1 however
function look on his face is created every time you call the function actually exist but it's field every time you call the function always how was that the that it's field well it's because this helps but the school discovered that
exploration of a problem with namespace is that the x we had so actually disco which stated that when learning a function access only present their model whether to but the scope of the and this scope is that a study guide it means that the 1st time that Python interprets the function that is the code you wrote and that as a I think the was what amoxicillin basis the what is the scope of the function and at the moment on the other 1 Python compute all that stuff accessible from the if you have a nested functions you get function similar functions similar functions a model the end of offenders spaces and all of them on excessive they're using an error however depending on where you are except or what you had to get at that moment you will have a different school it's applied from the school supplies so there different set of my faces of access to at every moment in terms of themselves is how it what you call a function that you have access to their markets last all that long when you go out of the function you have access to the local so the function anymore that the at least fitness that
slopes was next with these ideas excessive to the benomyl Cisco content and local agents as I said when you raise an efficient the this would be the max instead the function then you have enclosing information encompassing when they fled demand that claim not calling if you call function and that function of other function you can access the locus of the coding function such you only access would you declare OK so this only works for method functions remember how we implemented the greater with and the function but that I a string this after the function and all they're all enclosing functions what we have is that good amount of global names could modeled and modeled again but the function is declared not model from where you are calling this is an important function only there wrongly called of inside the model with the function is a clear right yeah and finally we have evidence and that all the most access learning phase I insofar yes yeah
called so now but so the in most of the schools from inside out from the most to the outer most In the example of the function with and I remain called when it is difficult and you get the bottom do we had that local names but given the same model year you have a function we must not have an argument called pass then Python we look in the old namespace and if you want important being always the path then you would get that but where with files python both from the you know the most throughout the most name namespace they forget the name and address of the name then from them section from 1 to the other remember the results of that the axis is the only for their for their own data and assess like can only change the names the new look and in space X and the of if you that and after all you know the quality work and if you like you should come to dinner
tomorrow legislative goal you
are this is a data we have in the most scope for that there are names all the names declare that have an can access when you enter the function of a sum house so you can modify then you have a lot of which is the next in phase and then you probably its what happens when given a sphere you can but access them from the all is a model this is a fight you can access the staff you come online or in any other 5 but so you could say it does that kind of the uppermost built the most is with the names those at the most FIL name may face and then in the late if you have a lot of for every function it is clear the questions so
far the problem the 2nd example let spend 1 minute trying to understand what is that I have a function which that's something for it is something and atoms and that it was designed to actually that is only function the technique that this is NASA and this that function aggression the race so better than the function whether this function this followed by right with X and Y which right there was a with than how it works if I you with and they had this function mechanical after was a function relating X to this nonsense
so where is 1 let's say this there we have been doing that and then the in that we have an intermediate this goal the enclosing function an embryo we have a lost and in the end we would have had a house OK so where this namespace what happened with the we have to worry that the class like why click here in this makes this with a given by for in example sh so the thing is that we have a closed this is called plus do not pleasant treasure planet come on them is playing them got and so you can see that present here this is the enclosing function expertise but only a small portion of enclosing function expertise why because as I said when you declare the formation and by and that there is from computes the school of the function and Python there there use that then look at and they know Morse function will access something from there think that made in the and as you will need that thing that says he will ways by from th this close a kind of template namespace will the name is a story and then name to y letter but it is with the fall exist and domains that while and you're using the function so why that to forward is a function of the functions we have that close to their and as you can see actually the closer is a hidden activities intent on function we have also the lost the funny
thing and example and the fact that as a set next year they also have a different ex also and there's no problem another placing 1 with and we can see here how we
have in that all the text think
again so and that it was clustering is that reference can to lead to the nonlocal variables of the function the and again the simplest this
there and closing this there and closing functions called the class bad so far well it
enables what was this and for
the you know and so women legislators itemized with
my mother play let's elect their functions then the and the 1 actually but the reality is that if I like for 55 3 dates lot dealers utilization 0 g . 7 but fast however 61 acts come on it's almost 7 seconds 1 thousand times slower amazing sex is small friends in the presentation the the
recursive calls for that for you 1 axis of fight and take the number of calls that nearly it's amazing amazing 455 eliminate the whole walls of the whole world
in so in do you remember when yeah you
know what the normalization applies a sensor eg the optimization is a hand cool normalization is is that they need to know stimulus to override quote function that we happen and this way you can think this impressive if you know that the colors of the minister can you William there was embezzled you can use that that's rest of the story was instead of calling the function spending all their execution time of that's normalization so all way it works the changes are the final models amongst the changes that here 1st thing if if it's not the base case I take it had a cats you have a lot of filler items otherwise I do that it was column analysis value the and that setting out we just passed was there of that the 1 thousand domain the we can compute it when the when idea 100 and it takes also nothing was nothing however
and come on what we want to apply for a fight that don't exactly the same thing the afterward it limited flexibility and that's i come on we had the functional working fine and now retains its implementation for taxes do we need to the friend functions 1 if I want to add to 1 if I don't wanna know it was built and my than
my and my system a further dimension the social this very the the function remains intense complete nonsense the same idea my function I so I know that this name if my function because again a function is another class so I have function object somewhere in by from memory with a point that called the 1 X and I take another point they're called yeah component to it and then I just want to this is a question this a which function is called and for the phonetic function don't function believes that it's calling itself and it's what it's of happening what that city with the college and
just in case let's in a somewhat the 1st thing I get a
function this is what happened I have a long name called the 1 I which points to an object function object which has this goal then I can deal with that name or real the which points to the same disappointed just an automatic name to access this amount and then it comes a single call this the the the number that the now I get another the 1 that's what happens when they create a new function called the 1 2 and replaced the name in the low was that why I have a candidate the idea is to consider the now I have to function objects the 2nd 1 go there ultimately the always have them that's a trick the and part of figure is the busy of function that's in hi
summarization of that but let's make it even more usable you don't love let's make it to work with any function kind of any business is a
study because if we only for functions as being 1 item day that's the end but this to make work for any other function and working create a function generator again we see that with the powers with testing of create a function we today a domestic and that was the function but is why because we have to to provide the function to memorize the function to remember to guide the calls and they use that as a thanks because he had the only thing that we know we call that tax within but then demand engage with under the given value we call the function to memorize we study the value on regional any say only the cult of which and Edwards the whole works the the is again yeah know it was for a you actually I was for Victoria band
258 150 common 250 without normalization it would take like
all the conference and finally the last because of what
a the only was talking about that symbol 1
that the education of is here we have 1 the that's the
all only thing that symbol that's compare gold is exactly the same so you can use a great of my money as and the the that the motifs so the Is there something more
without a frequency and the use was still nodes of the and I guess I would give us session with them let me liberalization for instance this party 1 thank you thank you wouldn't
mind and then will say this whether you want to do is use said you would experience itself when your arms and legs and help implement definitively plate was so it really simple integrated with the alkene implemented adequate is that you can use ICT enabled the great we just sort of expatriates so 1 that the what the so we do want the question comments if anybody has questions there's a response I integrate them before you have questions the higher question thanks thanks for to talk for so all of so you show how you can this replace needs and namespaces and so on and is shown in this slide what you have to write and so on I would just like to have a comment from you about using this technique in production codes but this thing which is a dual every time user to not not about the greatest part changing the names replacing the inspectors couple slides used to about
Fibonacci abilities and then we have Fibonacci
under a predefined 18 yeah but notice that it
this is what happens when you use according to the particular takes your function rather I was so we
end and it works because the function is still believes that its funding itself and it's called the excessively only it's really it's really what's happening every time a greater sorry it is in flask and you want to other URIs you're going to see yeah OK maybe which was to be conciliators fund it look like but that's really great you can you're you have taken the function that placing interrupting with something you could even implement equated with does not cause that function that would be maybe OK yeah get my question was not about using the productions with 2 was on it this is an example and applications called and thank you for the talk we you know talk about the decorators parameters on Urich right yeah there was the with the aid this is where the simplest according to them with the more about it now the front of with and was set so the 1st part of their training is doing the kind of these yourself and this is about these doing more declarators different types of the great was implemented to maybe keep at this stage inside the weight of order customize it way be here for instance this is going here is that the when the world was to my mine the size of the cats and uh and we will have to for constraints the analysis and you of it was just 1 more while I ran with economic plastic radius of the tutorial what we covered plastic craters and the tutorial you I don't think we have time but the you should use meta-classifier language glasses with that of the grating classes personality but we will see how to implement the Quakers using class that's what see but we want see I don't you would have time to see how the correct class the so I have a question involves using multiple the greatest sporting function like but that is hard to see is the tradeoff between the complexity of life and all that sort of something that something that lady admission but most of the and that was it would I like for sure but the thing is if you have for the greatest in function it means that the physical the cost according to which cause and according which calls in is according to weights at the end of the function so that the expenses so don't make that presenting you lose superfast there's center is because you're going in for also for set and sometimes you so they can with its it's maybe the just part of a greater that it's so we the play a great them with the with that that euphoria that actually have a function call another function can before calling use the something that like actually order like blogging or whatever you're doing and that takes time at the end you have to call 1 of the glass old of execution code of each of the functions words correct inventor and do have should for example which is ever legacy code that uses all the greatest function halted faster and faster maybe you could if you are always use the latest of MIT has this funny once only 1 the end is maybe it's not some of the great is that it's made a lot more than I think if you i was saying that the view of nothing to do with the greatest of place calling something the meaning of the function lots of thanks that precise sense so we view I always doing that 3 the fact that if if lines of functions the same toward lobbying and whatever maybe you could have seen no for everything to register with the same and you have a single at the greater for doing the stuff after that if you always lead to he does anybody else have questions
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation


  428 ms - page object


AV-Portal 3.8.0 (dec2fe8b0ce2e718d55d6f23ab68f0b2424a1f3f)