Discovering Descriptors
This is a modal window.
The media could not be loaded, either because the server or network failed or because the format is not supported.
Formal Metadata
Title |
| |
Title of Series | ||
Number of Parts | 160 | |
Author | ||
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 | |
Identifiers | 10.5446/33754 (DOI) | |
Publisher | ||
Release Date | ||
Language |
Content Metadata
Subject Area | ||
Genre | ||
Abstract |
|
00:00
SoftwareUniqueness quantificationVideo gameForm (programming)Computer configurationObject (grammar)Orientation (vector space)Formal languageProgramming languageMereologyExpert systemObject-oriented programmingAttribute grammarSoftware developerInstance (computer science)Computer animation
00:43
Control flowCodeSocial classGame controllerComputer configurationDifferent (Kate Ryan album)Object (grammar)CodeComputer animation
01:13
Control flowCore dumpOperations researchAttribute grammarInstance (computer science)Level (video gaming)Formal languageCore dumpObject (grammar)Operator (mathematics)Communications protocolAttribute grammar
01:39
Instance (computer science)PhysicalismFamilyPresentation of a groupFormal languageCASE <Informatik>Communications protocolComputer animation
02:01
Type theoryInstance (computer science)Attribute grammarImplementationSweep line algorithmCore dumpStaff (military)Type theoryMereologyOcean currentRevision controlDifferent (Kate Ryan album)
02:26
Type theoryAttribute grammarInstance (computer science)ImplementationTerm (mathematics)Data dictionaryState of matterImplementationObject (grammar)Different (Kate Ryan album)Computer animation
02:47
SummierbarkeitAttribute grammarSocial classFile formatSweep line algorithmObject (grammar)Attribute grammarCategory of beingSocial classMultiplication signNeuroinformatikEuler anglesLecture/ConferenceMeeting/InterviewComputer animation
03:22
File formatInstance (computer science)Object (grammar)System callMultiplication signSocial classParameter (computer programming)String (computer science)File formatRepresentation (politics)Communications protocolEuler anglesInstance (computer science)Event horizonCartesian coordinate systemParticle systemComputer animation
04:07
Social classVirtual realityStatisticsPhysical systemSocial classMatching (graph theory)Endliche ModelltheorieComputer fileUniqueness quantification40 (number)Physical systemObject (grammar)TrailComputer animation
04:31
Physical systemStatisticsVirtual realityEuler anglesInstance (computer science)String (computer science)Social classAttribute grammarCommunications protocolLevel (video gaming)LogicComputer animation
04:59
StatisticsPhysical systemVirtual realityComputer configurationMultiplication signComputer fileString (computer science)Object (grammar)Instance (computer science)Library (computing)Representation (politics)
05:28
Image resolutionOrder (biology)Statement (computer science)Representation (politics)Order (biology)MereologySocial classMultiplication signObject (grammar)Data dictionaryString (computer science)Parameter (computer programming)Key (cryptography)Attribute grammarComputer animation
06:10
Computer fileStatisticsState of matterMappingMultiplication signKey (cryptography)Category of beingSocial classString (computer science)Instance (computer science)Object (grammar)
06:29
Statement (computer science)Computer fileStatisticsObject (grammar)ResultantBoundary value problemString (computer science)FamilyCASE <Informatik>SurfaceParameter (computer programming)Game controllerSocial classLecture/ConferenceComputer animation
07:01
StatisticsComputer fileInstance (computer science)Social classCASE <Informatik>LogicMultiplication signComputer configurationScripting languageSocial classDisk read-and-write headObject (grammar)Pattern languageParameter (computer programming)Observational studyCartesian coordinate systemInstance (computer science)NeuroinformatikEntire functionComputer animation
07:38
Instance (computer science)StatisticsComputer fileSocial classResultantCategory of beingInstance (computer science)Computer configurationObject (grammar)NeuroinformatikSocial classSimilarity (geometry)Attribute grammarEuler anglesComputer animation
08:04
Virtual realityStatisticsPhysical systemLogicCategory of beingString (computer science)Virtual machineScripting languageAttribute grammarComputer animation
08:29
Physical systemVirtual realityStatisticsConfiguration spaceSocial classMeta elementAttribute grammarRevision controlSocial classObject (grammar)Attribute grammarParameter (computer programming)Multiplication signEuler anglesImplementationMappingComputer configurationComputer animation
09:32
Partition (number theory)Attribute grammarPerspective (visual)Attribute grammarMultiplication signObject (grammar)Category of beingSign (mathematics)Physical lawComputer animation
10:08
MultiplicationStrategy gameMultiplication signCategory of beingWebsiteAttribute grammarSlide ruleComputer animation
10:39
Instance (computer science)CountingAttribute grammarSet (mathematics)Group actionMultiplication signCountingLine (geometry)Category of beingData storage device2 (number)CASE <Informatik>Video gameComputer animation
11:05
Instance (computer science)Attribute grammarCountingCountingMereologyCategory of beingCorrespondence (mathematics)Object (grammar)Multiplication signCASE <Informatik>MathematicsOrder (biology)Computer animation
12:02
Smith chartObject (grammar)Different (Kate Ryan album)Instance (computer science)Perspective (visual)Category of beingTracing (software)LogicSocial classAttribute grammarScripting languageRepresentation (politics)DemosceneLecture/ConferenceComputer animation
12:44
Smith chartComputer configurationResultantGame controllerRepresentation (politics)Set (mathematics)Social classObject (grammar)Scripting languageParameter (computer programming)SurfaceComputer animation
13:11
Attribute grammarInstance (computer science)Parameter (computer programming)Default (computer science)Validity (statistics)Point (geometry)Object (grammar)Game controllerLogicoutputView (database)Performance appraisalDecision theoryMilitary baseComputer animation
13:40
Instance (computer science)Attribute grammarEuler anglesPredictabilityException handlingCartesian coordinate systemObject (grammar)Computer animation
14:01
Smith chartException handlingAttribute grammarSocial classSet (mathematics)Euler anglesRegular graphDifferent (Kate Ryan album)Computer animation
14:20
Scripting languageObject (grammar)Formal languageGoodness of fitComputer animationLecture/Conference
14:46
ConsistencyFormal languageCategory of beingFunction (mathematics)Formal languageMereologyStatuteCategory of beingSimilarity (geometry)Cellular automatonOrder (biology)Computer animation
15:15
Category of beingFormal languageFunction (mathematics)Sweep line algorithmElectronic mailing listObject (grammar)Category of beingEntire functionSocial classCommunications protocolCASE <Informatik>
15:39
Formal languageCategory of beingFunction (mathematics)Instance (computer science)Social classParameter (computer programming)HypermediaFunctional (mathematics)Object (grammar)Cartesian coordinate systemInstance (computer science)Meeting/InterviewComputer animation
16:28
Instance (computer science)Function (mathematics)Social classType theoryMereologyObject (grammar)Functional (mathematics)Computer configurationData dictionarySocial classComputer animationLecture/Conference
16:48
Social classFunction (mathematics)Type theoryObject (grammar)Video gameSocial classRight angleFunctional (mathematics)Attribute grammarInstance (computer science)Level (video gaming)InformationComputer animation
17:14
Instance (computer science)Social classSystem callObject (grammar)Instance (computer science)Social classFunctional (mathematics)MereologyConstructor (object-oriented programming)Keyboard shortcutMultiplication signScripting language
17:36
Social classInstance (computer science)System callObject (grammar)Functional (mathematics)Constructor (object-oriented programming)Social classParameter (computer programming)MereologyFundamental theorem of algebraComputer configurationScripting languageComputer animation
18:08
Electronic signatureCASE <Informatik>Game controllerProteinCodeComputer animation
18:34
Electronic signatureFunction (mathematics)CodeElectronic signatureFunctional (mathematics)CodeOrder (biology)Transformation (genetics)System callResolvent formalismLecture/ConferenceMeeting/InterviewComputer animation
18:55
InformationContext awarenessProcess (computing)RootResolvent formalismDomain nameLogicObject (grammar)Parameter (computer programming)Cycle (graph theory)View (database)Software frameworkWeb 2.0Electronic signatureMaizeFunctional (mathematics)MathematicsTrigonometric functionsComputer animation
19:31
Context awarenessInformationRootLogicFunctional (mathematics)Parameter (computer programming)Object (grammar)Computer animation
19:56
InformationContext awarenessRootDependent and independent variablesProcess (computing)Social classRight angleMultiplication signCodeComputer animation
20:16
Context awarenessParameter (computer programming)InformationRootData typeError messageParameter (computer programming)State of matterInstance (computer science)Object (grammar)Frame problemOnline helpShift operatorMultiplication signCodeComputer animation
20:50
InformationParameter (computer programming)RootContext awarenessInstance (computer science)Scripting languageLine (geometry)MathematicsSystem callMultiplication signFunctional (mathematics)Equaliser (mathematics)CodeCartesian coordinate systemComputer animation
21:39
Computer configurationObject (grammar)Functional (mathematics)Similarity (geometry)Video gameSystem callLogicComputer animationLecture/Conference
22:14
Interface (computing)Maxima and minimaImplementationRun time (program lifecycle phase)Computer configurationCommunications protocolImplementationLibrary (computing)Entire functionSoftware frameworkPoint (geometry)Partial derivativeShared memoryMatching (graph theory)
23:01
Scripting languageLibrary (computing)AnalogyCategory of beingSoftware frameworkLogicEndliche ModelltheorieDifferent (Kate Ryan album)Computer animation
23:31
Lecture/ConferenceComputer animation
23:53
Pattern languageSet (mathematics)Category of beingGastropod shellComputer animationLecture/Conference
24:35
Latent heatCodeImplementationRevision controlMultiplication sign
Transcript: English(auto-generated)
00:05
Hello everybody, thank you for being here. Let's talk about this unique feature of Python First let me start by saying that I'm not the only one who is very fond of descriptors. You'll find like many Experts developers in Python who will also tell you how the descriptors are The reason being that not only they're a powerful feature, but they're a fundamental part of the language itself
00:25
So I understand the descriptors will become more proficient in Python because it's an important tool to have in our tool set And you will understand the language better and as a result of that you will become more expert So let's start with the basics something that applies to all mainstream programming languages that have support for object orientation
00:42
We have objects in the form of instances of some class and in there we hold data based on attributes So when we can set that values to them and when we try to request The value we obtain what what we expect which is pretty much what we said previously But what if I told you that when you run something like this when you request the value of an up tribute
01:03
We're gonna actually run arbitrary code controlled by us and that going on is going to be managed by another object of a completely different class Well, basically that's the idea behind descriptors The scriptures are a powerful feature of Python by which we can control What happens at the very low level over the basic core operations of the language?
01:23
It means that we can control what happens when we try to get set or delete attributes on given objects that have this Protocol of descriptors, so Descriptors are achieved by this protocol which in Python is Entailed by these magic methods as always in Python
01:42
Special behavior is achieved by magic methods in this case these four methods Comply with a descriptor protocol basically under get set and delete and the last one was added in Python 3.6, which was an interesting enhancement to the language So the rest of the presentation will follow Python 3.6 as a reference because there has been some improvements
02:04
So the talk is not only discovering descriptors, but perhaps also rediscovering descriptors So even if you were familiar with them, it's also interesting to see that there are new stuff in the current version of Python So let's go by parts first. Let's classify descriptors. There are two types Basically, what we have to know is that there are subtle subtle differences between them
02:24
We can classify them in data descriptors or non data descriptors In terms of implementation the difference is where or not they implement another set if they implement under set They're also called overriding descriptors and they will take precedence always Instead of the dictionary of the object whereas if there are non data descriptors
02:41
We can actually override them because the dictionary of the object will take precedence and will be run first So let's start with something simple with a non data descriptor For this the problem that I have is that I have an object that has some attributes And I want to automatically run some computations on those attributes and
03:00
Kind of like a property but it turns out there are many attributes So if I want to use a property I will have to repeat the goal many times So I will use descriptors and this means that I will have to create at least two classes one for the descriptor itself And the other one which is the so-called manage class Which is a class that I originally intended to have in the first place But now it's going to be managed by a descriptor object. So
03:22
First let's inspect the descriptor. I'm going to create an object like this, which I'm going to call date formatter What it's going to do is it's going to format a date time into a string. So this has a name Well, we'll see that why the descriptors need a name shortly But the important thing here is that they have it has it under get method because this is what defines this class to be
03:45
a script or because it implements one of the methods or the descriptor protocol and under get Takes two parameters the instance Which is the object being accessed at that time and the owner which is a reference to the class And what I do in that method is I will try to get the attitude with
04:00
Holding for that object and I will return a string representation of that daytime So now we can take a look at the manage class how this is used for the original class I intended to have for this if I logical had this which represent a file start which basically models File like object in a Unix
04:22
like system This object is defined by a file name. I'm interested in tracking also the date it was created updated and remove that and These three attributes are going to be instances of daytime But I have some other attributes which are going to be called a class attributes
04:42
Which are basically the same but with the prefix str Str created at and they're going to be instances of the descriptor and this is important This is an important detail for the descriptor protocol to work. They have to be defined at the class level So they had to be class attributes or the otherwise the descriptor will not work So basically the logic is like I created a very simple naming convention by which str created at will be managing the attribute name created
05:05
At so, let's see now. We have two things Individually, let's see this how they work all together So basically I created my object my file start with a file name and I'm going to pass a date for the creation and updation and Once again, these are instances of daytime from the start library. And now I request
05:26
Str created at for that object and I get the string representation of created at So in order to see how this happened is important to understand in which order and Python resolve things So let's go by parts first
05:40
I created the object and I passed all the parameters to the initializer and then I requested this attribute Which is str created at so the first thing it will happen is Python will look this into dictionary of the object And it's going to try to fetch a key with the name str created at and as it happens It's not there because the object has created that not str created at so that search fails
06:03
Okay, it's not a problem Then it's going to continue and the next search is going to be in the dictionary of the class and This time the key is there because remember that in the manage class I define is created at to be an instance of the dictionary So the class has str created at and it's a mapping a key is mapping a key with the value
06:23
So you think you might think okay It's going to return the value for that object as it happens with all properties Well, actually no because this is a descriptor So Python is smart enough to tell that this object has an aggregate method So what is going to happen is that instead is going to call the aggregate method of that object and that's the result I am obtaining so in the end what happened is that when I created this like str created at
06:46
Python will call the class dot the descriptor which in this case is str created at dot under get And it will pass the object as a first parameter and the class as a second parameter and inside a method again We're in full control of what we're doing so we can
07:02
Run any logic that we want in this case the logic for formatting the the datum according to our requirements There's another case when you call the under get when you're trying to delete something that is a descriptor But you call it from the class not from an object in that case instance which is the first parameter of under get is going to be none and the most common pattern or idiom to
07:26
Having the situation is to just return self which is a descriptor so basically the idea is that if you have a descriptor and you're accessing through an object you return the computation that Was defining under get whereas if you try to get it from the class you get the entire descriptor object
07:41
Pretty much like a property like when you define a property in an object if you call it from an instance you get The result of the computation being decorated by the property, but if you call the property from the class you get the property object This is kind of similar So Let's see how the descriptor got its name because so far we assume that the scripter was able to retrieve the attribute and just
08:02
Transform it in the way we wanted to but actually I had to explicitly pass the name to the scripter I was they in the need I made a scripter to able to store the name internally so basically for example Str updated at I had to pass a string updated at to tell the scripter you're going to imagine The Property of the attribute under the name updated art, but this is somehow repetitive, and I don't want to have this logic
08:27
I want something like in the last example just create a descriptor and to make it able to automatically configure itself So if you wanted to achieve this in previous version of Python how to resort to some complicated stuff for example One way of doing so was like having a class decorator and the class decorator
08:45
You want to find the mapping of each name to the scripter and Inside of the corridor you were setting the name when you created a scripter or another implementations I have seen are with meta classes that again and when created the object you try to set at creation time by overriding the new
09:02
But those things in my opinion are way too complicated for something that should be like plain simple So luckily there were some enhancements in Python 3.6 and this method was added to the class creations Which is said name and it receives the class when the owner which is a class as a first parameter And the name which is the name as the attitude appears defined in the class as a second parameter
09:23
And this is going to be called automatically once the class is being created So taking advantage of this we can just use that Method to automatically store in self dot name and made the scripter know the name of the attribute that is going to be managing Which makes things more simpler at least from the user perspective because the user doesn't have to know
09:41
Or remember to configure the scripter So, okay now we have the basic data scripter and we know how the scripter gets their name of the property that they're going to Be modifying. Let's move to something slightly More complex with a data scripter this time. We're going to implement than they're set and The problem to illustrate this is just an example by which I have an object can be any object that has some attributes
10:06
And what I want is to automatically Count how many times those attributes change their value over time And if I try to think strategies to achieve this again Python as always offer offers multiple solutions So I can do that with a property for maybe with setter and in the set there
10:23
I can have an internal counter that gets updated all the time But if I have many properties, it will be repetitive I could also do that with set attribute but overriding this magic method or we can use a scripters Which I think is much more simple and convenient as we'll see in the next slide. So
10:41
For a scripter first, I need the name and we know we now know how the scripter gets its name by the under said method Under said name. So in this case, it's going to store the name as always and in the second line It's going to store count name Which what it means is it counts how many times a property under the name change their value over time
11:01
Just for simplicity and for the sake of example I'm going to assume that in this case Everything that it starts with count underscore corresponds to something that is the count of another property and not a property itself So now we can move to the under said method and see the interesting part So basically under said receives the object being modified at that time and the value that we're trying to set to that
11:24
Descriptor in in that time. So basically what I'm going to do here is I'm going to try to request The property from the object by inspecting the dictionary with a name that we know that the scripter has If it's not there I'm going to set the counter to zero because it means that it never changes value is the first time we're assigning something
11:43
If it is there in the near the end We're seeing that if the value is different than the one it has it means there is a change So I'm going to increment the counter by one and in any case no matter what I want to actually Set the the new value there. I'm car that user is currently assigning So in order to exercise this this imagine that I have this object which is a traveler, but again, it can be any object
12:05
I'm I'm interested in seeing how many different cities and country that person has visit So I'm going to find city and country to be both instances of class attribute Instances of the the script I just created so it's a trace property. I'm basically what happens here Is that first I said something to the object and we see our counters are set to zero
12:25
Then when the tourist moves from one city to another we see that the counters are Incremented and so on and so forth you can get the rest of the examples But the important thing is that if you look at this, this is from the user perspective. This is completely transparent The user is only modifying values or attributes in the object
12:43
And what's happening is that behind the scenes a descriptor which is so is taking place and updating the internal representation of the object So this is completely transparent to the user I enable us full control over what's happening when we try to set something to the value So again similar to in the first example This is all syntax sure because when we try to set something to a descriptor that has done their set define
13:05
What's going to happen is that it's going to call the class the descriptor dot set and it's going to pass The object as a first parameter and the value we're trying to assign as a second parameter And again in that method we're in full control of the logic We can use this to create validators default values input sanitization etc at this point
13:26
Maybe it's becoming clear or you might already guess what then that delete might be doing basically is the method Yes, as you might have guess what it's going to be called when you try to delete something That is a descriptor and has this method define so
13:40
For example imagine that I want to protect some attributes against deletion where if they read or accidental one way of doing So will be to create a descriptor that implements the under the lead and raise an exception saying that you can delete this Attribute for this object so for example in my application if I want to protect a username and it's deletion one possible way of doing so will be
14:02
To actually create it as a class attribute. I use this descriptor And now we see that if I create this user and I try to delete it You will raise an exception selling me exactly what I want Whereas if I try to delete anything else it will let me because there are just regular attributes nothing particular about it So that's the difference between something that has a descriptor and something that it doesn't have a scripter
14:24
So, okay. Now we know the basics of all descriptors We have seen the basic methods on roughly how to implement it I'm basically basically hopefully with some examples you can actually take that advantage But how do we know that we're making sense out of the scripter like we're actually using it properly
14:42
Basically a descriptor is any is like any other good Python object So probably a good scripter is one that makes sense with Python itself that is consistent with the language So it's Pythonic as we call it So in order to say that probably a good idea is to take a look at how the scripters are used internally by CPython
15:00
Because as it happens, they are deployed in the language infrastructure They are a fundamental part of the language itself as I announced at the beginning of the talk For example properties are descriptors If you recall the first example I gave I mentioned that there were some suspicious similarity between descriptors and properties and I said that when you get the property from a class you get the entire property object and when you get the
15:23
Descriptor from the class is expected to have the entire descriptor object That is because in the end properties are a particular case of descriptors They actually implement the full descriptor protocol and what happens is that when you decorate something with the property Python is using that decorator to store the method internally and place it under Set get or delete respectively also class methods are descriptors that what they do is they allow you to
15:47
Have the class as a first parameter already provide That's why you can call the class method and you have to explicitly pass the class because there's a scripter going on Applying the decorator that automatically does that and the same happens with static methods that make sure that you can call that function
16:02
Both from an object or from a class or from an instance and it's going to work Probably one of the most interesting Applications of descriptors are methods because this is the way methods work in Python because in the end methods are just functions, so let's take a look at that and
16:23
Also functions are descriptors. They have a get method What they do in that in get method is they return the function applied to an object, which is Basically saying that the function is converted to a method when it's applied to an object so Basically, let's see this white part first. Let's try to prove that methods are just function
16:43
So I define a class like this and I create what we call a method And if I inspect the dictionary of the class we see that internally method is a class attribute which is an instance of a function, right and Remember from the first example what happens when you have something defined at the class level there that has a get method
17:02
Python doesn't return that object just yet instead It calls the get method and returns that result so now With this information in mind we can know that when you when you call a method Imagine that I create an object and I call the method We're not actually calling that directly because that's a descriptor. So what's happening is that it's calling the class
17:24
the descriptor then get method passing the instance Which is the object and the class and that part along up to the first cluster of parentheses that will return a method which is basically the construction of that function for the object and then it's a callable that accesses
17:42
We can access with the rest of the parameters So in the end this happens that the script of having their all along there are fundamental part of Python and maybe they are invisible that we were using them probably without even noticing and This is this is an elegant solution by which Python is able to actually transform the same option Which is a function to a method in a class and they work the same way in a completely and the user doesn't even know
18:06
about that So, okay now we have seen How Python uses descriptors to their bandage, but how can we use descriptors to our case to our advantage? I'm probably the best thing that descriptors have is not only that they're so powerful and there
18:24
They allow us to have total control and do a lot of things but probably that they can fix or Solutions in in the code. For example, we can write better decorators by using descriptors In particular for those decorators that change the signature of the function So for example, imagine that now I have a decorator that was going to transform functions
18:45
And it's going to change their signature in order to make it more convenient for the user and avoid repeated code so for example I have this Resolver that takes some arguments and with those arguments I construct an object of my domain and the rest of logic only uses my domain. This is so I
19:04
Made up example, but something like this happens in many web frameworks when you actually define your views to receive a request But you apply a decorator to it So basically what happened is that the decorator is changing the signature of the function and it provides you with the with a descriptor Etc already, but that changes the original signature because I have a decorator like this one that basically
19:25
Exposes the same all four parameters as before It creates the object that I need to and then it calls the wrap function with that object So now I can change my function to actually only receive the the object that I need to work with and nothing else But we have to keep in mind that the original function the one that is
19:44
And that being created after the decorator is applied it still takes the original four arguments But this example works and if I have many functions like this I can reuse this this logic and apply it and this will work and I think that this is fine, right?
20:01
but I keep Looking at the code and I find that now I have the same situation but this time in a method of a class and I try to apply the decorator to that method and Hoping that it will work But actually the way is defined so far It will not work because remember that methods take one extra parameter, which is self
20:23
Which is the instance of the object being created. So basically what's happening here is that there's a parameter mismatch And everything is like shift one place to the left So if you want to try to fix this decorator might be time to find or resort to like complicated solutions like inspecting the code or
20:42
Inspecting the trace or the frames etc But actually after seeing how Python makes functions be able to work as methods We can get inspiration from that idea and use the same technique or the same trick to our advantage So basically without any in mind, the only thing we have to do is just implement under it
21:00
I'll make that the decorator also a Scripter and what I do here is I'm only I'm going to delegate the problem to Python because get method is going to call the get method of the function being wrapped which Automatically does that and converts that to a method and then I'm going to retrigger the scripter But this time with the method instead of a function and now with this simple change with these two lines of code. I fix
21:26
The problem or something that would have been otherwise quite difficult, so this is another cool application of the scripters and How they are there they are used So basically to try to to wrap up we have seen first the methods of the scripters how they work
21:47
Basically each method what it does we have seen that there is like a composition that one object goes to our object Automatically we can apply all logic then we have seen How Python uses descriptors?
22:01
internally In particular to use to call functions methods and then based on that idea How we can use descriptors in a similar way as Python does for their methods, so With these all I like to just share some final vices Which are basically that in general is a good idea to implement as few methods as possible
22:24
So from the entire descriptor protocol we have seen has a for magic methods partial implementation is not only possible is desirable because the option will be Much more generic and it will run faster because it has to do less checks in runtime etc and
22:42
Another important point is that we should like Reserve these for general purpose solution like to using descriptors when you actually know That you're creating a solution that is abstract enough because this is a feature Mostly using frameworks on libraries for example SQL alchemy uses descriptors
23:03
For example, the models are descriptors and all the logic is there. So this is something more Targeted to towards libraries or frameworks or yeah something where you will have an API So if you can get away with just a property or something that is it will work once I encourage you to do so and reserve descriptors when you actually need to have something that you know
23:26
Many people will apply in different ways. So that's all thank you very much for listening and I would like to To hear your question So do we have any questions, okay
23:43
Everything was clear. Thank you again. Oh, I'm sorry Thank you. That was a great talk. And thank you can you recommend or suggest any patterns where you would actually use especially like the 3.6 feature the
24:04
set name They said name want to use said name Yeah, any like patterns like what would be a typical example when you want to use it no, I think in general Like always because the scripter always knows always have to know the name of the property that is going to be modifying
24:22
So said name is like I would say that in Python three look sees should always be there It's not like you will have it once or so if available I would recommend to always use it because it's more convenient our solutions So my answer if I understood your question correctly will be like always implement another setting
24:41
Thank you. Any more questions? Yeah, hi. Thanks for the talk You had a slide and you've been talking I guess about C Python this whole time You said this is how descriptors work in C Python. Does that imply that they work differently in other Python versions? Actually, I
25:00
Don't I will expect they work the same way but for the talk I use C Python as reference so I took a look at the code as as its implement in C Python and the documentation So the reason why I mentioned C Python specifically is because it's a reference I use I Don't know if it or I will guess the yeah, because our implementations like pi pi will would do the same
25:20
So my guess will be yeah, they're the same Thank you Any more questions? Okay. Thank you again