Merken

Inspect (Or Gadget)

Zitierlink des Filmsegments
Embed Code

Automatisierte Medienanalyse

Beta
Erkannte Entitäten
Sprachtranskript
and thank you to go around 1st a quick so they would knows what introspection is about q you just
raise your hand OK was already use it in his own code OK for the Beagle with notes raised their hands
don't worry you are not alone and it was my keys few months ago and the that's why you know we had this idea of and talking about
introspection and 0 did this start for me and we were working with so different people on writing a test for hiring uh the dentist we had already just for all the languages that we have known for a vitamin I and we so that it was important to with such and such a test among the test we wanted to verify that the candidates could write a specific type of of functions to begin I could generate all we wanted also to enforce typically the use of his comprehension by asking to and modified code by changing just a line and the problem is that this test is of course automated and that we wanted to check if the candidate ad indeed followed those conference and all the things we had all the tree lines that you see there so roughly we could import a module called including the function that the candidate at uh developed the then of course all could we do that no ID so who should you asked of course your best friend and was the best friend of use of the engineer StackOverflow and of course uh we found the answer there and the answer is no just used a library called inspect just call gets worse and these generate all and then you with but the procedure to answer to that original question you whatis exactly introspection so let's go back to Wiktionary and asked OK introspection that and true possible meaning 1 in psychology and the other 1 in object-oriented programming OK let's elect the first one um and the first one we did just the ability of a program to examine the start of a trend tying the type all property of an object the ability of a program to examine at trent time the time all the properties of an object or he gets cool that's cool because in Python everything is an object as a function some of like the classes and object ever is an object is and that so you can in fact go and look everywhere in your or in the different element of your code In fact I was already using introspection without effect knowing um you probably recognize a vector the that of code and it's the good which is used to you know the um separated the code for which should be executed so when you're reading your module directly or when your importing it ends up the difference is made the just just by looking at that specific attribute whole name which is the name of the current module or the current namespace so why using that I was in fact using introspection but that's a but no let's look at what the system library can offer and this probability so this is a list of functions that which is part of the stomach elaborate uh which can be considered as being introspection using slight ID to get back the exact identity of the object you are looking at uh deer which is providing the list of attributes and methods type which is applied in the diet and as 2nd you get a tribute relatively explicit is a blast the superclass instance political providing new information about the specific characteristic of your object as well as different functions for accessing valuable depending on the scope and the sum of library provide also a in a lot of attributes and there is a really huge list there was a lot of a full blown by the developers in order to provide a a uniform interface for the objects and if you look at the documentation of the inspect library you have the full list of all the attributes you can call typically if you want to get to the documentation of a module a class or limit of the system or what does that mean in all cases so you have a function stupid function most important the uh what can you get from it you can ask for the course for the time and you get the the type of a function and you can ask for the name now so you could ask what the interest of us in the name of something and providing and well this can happen when you try to find a different names to the function it's important to be able to get back to the original name you can of course get the documentation you can get the model to spot hurriedly to spot from you can ask all the matters an attributed that that specific function and so this is a list the but the salivary provide even more than that provided a dedicated library could inspect uh whose objective is to inspect like objects it's a pretty big library it's around the 60 different functions but providing forming services first one thing checking is it a model was it a ClassAtom it its of it in the source code um get the module get the source file and start no problem to us that inspecting classes and functions what is the signature of a given function with all the different parameters and thank the and examining the interpreter stack well going to discuss about the last 1 is some I used refer you to the presentation of Palace on normally enough on Monday on people by code introspection for this specific point if you want to know more there is of course as usual pretty good and documentation of that of that model this go back for example what does that mean we can do with that with that the library we can get the exact parameter inspect the signature you provide a function and you look at the attribute parameters and then you with another object which contains a different parameters part of the signature and of course you can ask for to complete the source code of the function OK does bring us we've seen a lot of them are function that we could use but in practice where what could be the use of to just and so it's time for a the demo the thanks now we know that there is more what introspection 1 we know how to do basic things we know which function to use for example so whatever it's doing a bit more 3 knowing real things and been a bit more fun and present alone we could say that all the strings in Auckland always date it can be very interesting because I mean you communicate to the you know sigh outside world we see on the condition and 3rd guy will we use your library seal duck and we know now what are those to on call your function with so it's important to have the the condition that's so that in the exact number of Famagusta deviant and what type of model to provide um as when when we be able to get that information from all the training and the we could come and take that and then the value provided as good time are indeed of the right type according to its statement in let's begin In the 1st we have to agree together
about 1 um syntax font extremely because down actually different amounts in that we find in open source libraries that take this 1 and I take on right column there and then an optional take name and then is the name of the parameter and couldn't and followed by an optional description what is relevant for our use case here Use who we able to retrieve the release of the parameters names and so you they have and types the printed on and can here's how we you just get to the condition can assume you're here just might invoke the attribute duck if you have conditions change it's how it looks like we just after a string several origin of string and if you have no documentation and a function you will have treatment the attributes have returned the man the OK um we have to extract them the parliament as there is use a piece of content is not very funny we just have to foster so that I have nothing very interesting to around and on to teach to just create expire syntax if you don't have already library to do this here we extract from I don't know if we'll see phystat but here you added I'm looking for the keyword parameter in the in the condition string here and getting the name of the parameter and here's the option type then I will just pretend positive part of couples and containing the name entity type of each parameters but just let's run it to see if we could goes from and have a high in high density here may for monitoring as expected a B D against the kind that sees is assigned to use a type 1 and 2 norms they providers yeah I didn't none which means there was don't know document title and for there's a line right it just what was written as taking into the conductor nothing very smart to a the and now we have to do it in point and if we do a validation of ones we need to we would the we don't we don't just want to have the name of the type white and if you just want to to use to be tonight which gives you type of an attribute you could check for the representation of data which is the same fits this state name into the condition that if you want to have the number as input and you write the semantic annotation and provide an integer integer is a number but that take name of it of integers and it's not number so I have to load was actually died that was retains the condition and then check if our which is part of inputs and provided fits and so we readers is instance of but you know the HMM state what you it's to imports of things being able to impart a major because he made a consistent made docstring here so that there was a referring to custom type called example type that they was justifying and just about in the current value so I have to be able here to import the company you can use a function we get that just as opposed to load and data from the ground and you're instead of competing for example as the so here I can see that it's has an effectively interstate type summertime again and here and function I I really have to use at some point in time it's this instance to take that revenue for example 3 years pictured in I say don't as before at some let's put what is the pieces together a function that we take the name of the diet and optionally of abduction and that's the name of a meal and I we optionally used the margin and to to load the tape from this module that's if there's that and in the name of the type and have to because you know that if we have that that in the name of then it's a frequent finding I just don't you don't need anything else to to know how much that has been going on with the unit has been defined so just to issue that I I just use of it in used before get that is instance and the importance function from the important and the way can see how it behaves and I'm about to look at the tape from 2 modular main which is a current and you any territory to we wouldn't needs and the type I didn't actually defined in the image name image main and you can see that they have proper your saying that this is a system that have a type the tree just look at the no and it's put again what we just did to get function that we very simply and just extract extract which we i-vector which we are able to extract from the documentation from its name and understand the law and the state from those the names the kids from that extreme and you it's all can be used and it's very similar to what we sold before but this time for each point and name we have an actual type here on type of function and here still non-causally which has no time constraints and you can see that way that has a built-in types and custom types have been talking about without any problem OK so long for the remainder was to to be able to verify that extremism state and according to the signature of the actual picture of the function what's parameters that takes and so now the 2nd thing is to be able to get a signature from the produces invented 3 we have a function that to invent and does that very very easily and it's scope signature and it returns an objective way to
capture the on you should get a representation of such measure the objective suggests signature receding from this is that the parameters that you don't the your function takes and what see what he's found useful among others is upon the so called solitons inside this signature object which is in terrible and so you think it's really and not a mean and it it some and you can for example and get a number of parameters varied intuitively you could still get 2 different values of a specific monotone by its name so it's very easy as we just name and use them on their the bond of objects and attributes Schwartz and here I'm expecting to see ports to because it was a different view of the case 2 with part of the united signature and now is the use of corn but it's going to be afraid of it and just read the documents fair enough and basically we just want to check that if we provide a different value in the signature is has the right to tight if the type is provided in the so we just we just well just taking the extreme consistent when it comes to the types and the different users in the signature the in its quest for 12 actually we just use what we did before getting a brand names and types of things to capture and compare him here I ran with justice and my function my testing function and I the I'm expecting between the raising and this function is supposed to raise enough if the condition is inconsistent so here I can see it's consistent with the news and to for the example of course I provide another function that is and that the recommended and you can see that it's takes only 3 parameters and I just copy-paste and the the docstring of the other function which has a formidable so obviously the this line here which tells us that it takes a moment on did not reference and here when around the function difficult brands and the function it and that on it's wrong cares about signature it's test it's the function just takes the BC and the conditions there's about ABC and in prison the but anyway so that it is this we just achieved office tells going to think it was to to harm hum so I know I can verify that well wherever make maker and I want to take that contain that substrings is posted today homicide note and extremely is that that is assigned to function but also to class or method of things at so you can do that every restaurant to 2nd of the internal actually and the 2nd point is it to be done now I said that it's more at runtime it's more than actual introspection because they're really in need know to know the actual state of mind and good at runtime had to be able to check it against the expected types according to this president mutation so we see here I mean working the function signature provided images inspect so that the new year but now I I'm going on make that happened that object which is what which is contained in versus the bank you just do it for documents you would be calling your function we when you want to just put it in the bank and we tell you on that these that you would be found to the and so on just just presented and here to that other funk as that they provided 1st 1 of the we belong to the parameter space because they use of spider and then an explicit explicitly invoked depend upon it and see which was actually the stuff there and you can see that there's no mistake have collected on the value to Tucson just C and have an instance of exam they provide on so the test in its no magic but it's very easy to have that and that after the and know that have found that again and again we just create a function that and what we did before I am able to get the names and types from the conditions strain I mean and to get a signature and have no I meant I meant that at effect at runtime to combine the values that are given to the function to have and the parameters and parameters to the printer types so with this and again it's not very beginning just have it's a decorator if you don't know what the greater is 1st of year may use case of integrator is I want to add checks the much expected now before doing the rest of my function in behavior I don't don't want to touch what we do my function but they want integrated in order for it to just do a call to a check and then would be for ordering the so this usage is that the 1st time I just did a great to any function that is the in thing just you know my function can do whatever I don't care OK does nothing and I just the right up to 10 and at least may come to my output should be allowed to 1st and that is what do here I'm going to be some function that I was too great and before the function still has the same name and when he got it despite the fact that this function was not doing anything I haven't along because literature I did a step through that which was validation statement in good and had I want to have the a very good information to to work with because I know that I have my mistake when when continuous this function was to provide an integer as me which was expected to be an instance of and that and that its we just off to goes and so that was the OK the and then we promised
to try to answer the question of when should we use introspection and it's a tough question on the general principle is security relatively clear you should the only using it when you don't know the information of combined by well the the principle and I know in practice so we don't pretend that we the truce but we have tried to identify some of good candidates for places were introspection could be used on the 1st 1 is about expiration learning and to begin our it's the idea that an introspection although you to with an in-depth view of what's happening with your object and that's very very nice if you want to learn typically the peak by tenant announced what to but to understand what is happening inside your code the 2nd 1 is related to y you and that's that it is a case when you receive remote sites uh an unknown object and that uh you want with that view your fuel code depending on the specificity of the object on the output side a small boats uh when typically you want to socialize a new objects in all of 2 to look it up story for future use then it is you have to adapt your yours so depending on the specific type of the object the next 1 is when you are missing so much view of body motion promotion I will polymorphism of all the languages all typed languages and so you would like to have a single function and which is processing and whatever type of object that you receive and in that is of course you live with that what is happening inside your code to the specific type and specificities of your object the next 1 is if you are missing also interferes and typically non architecture of regions and you are supposed to use the classes or modules that you don't know and where you would be interested in checking that as well as the data all the meters I need all I'm expecting and the last 1 is used to the 1st part of the exercise of some of you use about with the parameter it's all this things around your code like I would like to check some of convention I would like to check some of the some clearance within like my code and I want to be able to do with the completion when that I at command line and I would like that the type of of things where you can you can also use introspection and just of the tree was overwhelming the first one is about performance of course when you just text access cells and that the of a class that does almost no cost so that's fine but you could have some cases were um introspection is more expensive and that was all aspects of practice and there are some programming don't shake multiple times sensing streets you so check it once so when you receive the object from outside as fast portability depending on the right and implementation some objects could be not inspectable with something to take into account if you when you go to the work of the different and conditions and finally maintainability and depending on the ID you are using it could be you could receive more itself when trained to do refractory because of course person is just just a representation of a string of classes with more putting them that's all for us we would like to thank you for thank you for attending this session and yet by the way creature sirens if you if you are interested in working on a a really big data thank you the few
but if you had a woman questions of missions so evaluation of so when you measure some examples have
enjoyed you don't want to work with using the AC model or some other way
of evaluating staff analysis of just wondering if you combine the 2 approaches all I have for example the following things do you know what Nystrom and
actually we we created they all trying Nowitzki works and how is it easy to create a visitor and 1st is that didn't fit in the it's and uh it was also a very it's other subjects are in theory if you do any is you're not introspective because you are an amazing in the structure of the steps that the structure of the program and in fact when you this it's a interesting place and you have to load the source file you cannot inspecting the actual code that is running you already know our learning something it's even if it's as a current divider along unity and that you are learning something in creating case the energy and and you don't have the memory state of the current execution you don't have state of the data that is going through your functions so it's not introspection action but when it comes to the string yes the 1st example was to check something that trees that it and it was just short here that the way to to to check it um was to use introspection is in this very case because it is very easy with faith and to address volume module and because you just a little bit you have something you are and then you just have a state and you you can use statistical function so you just a way to do this but the 2nd example the language where the change in which is the true and pure theoretical example of introspection of some very few
Intel
Software
COM
Schlüsselverwaltung
Code
Computeranimation
Demo <Programm>
Gewichtete Summe
Information
Gesetz <Physik>
Service provider
Computeranimation
Netzwerktopologie
Deskriptive Statistik
Typentheorie
Gerade
Schnittstelle
Metropolitan area network
Softwaretest
Namensraum
Befehl <Informatik>
Datentyp
Kategorie <Mathematik>
Magnetbandlaufwerk
Gleitendes Mittel
Dichte <Physik>
Divergente Reihe
Dienst <Informatik>
Rechter Winkel
Konditionszahl
Ein-Ausgabe
Ablöseblase
Mailbox
Charakteristisches Polynom
Ordnung <Mathematik>
Programmbibliothek
Instantiierung
Zeichenkette
Fitnessfunktion
Objekt <Kategorie>
Subtraktion
Wellenpaket
Klasse <Mathematik>
Quellcode
Informationsmodellierung
Modul <Datentyp>
Objektorientierte Programmiersprache
Datentyp
Programmbibliothek
Inhalt <Mathematik>
Attributierte Grammatik
Soundverarbeitung
Open Source
Modul
Compiler
Hidden-Markov-Modell
Randverteilung
Bit
Punkt
Formale Sprache
Selbstrepräsentation
Element <Mathematik>
Eins
Einheit <Mathematik>
Font
Nichtunterscheidbarkeit
Umwandlungsenthalpie
Interpretierer
Lineares Funktional
Parametersystem
Prozess <Informatik>
Systemaufruf
Quellcode
Ein-Ausgabe
Elektronische Unterschrift
Algorithmische Programmiersprache
Konfiguration <Informatik>
Arithmetisches Mittel
Twitter <Softwareplattform>
Ganze Zahl
Information
Extreme programming
Aggregatzustand
Nebenbedingung
Ortsoperator
Zahlenbereich
Kombinatorische Gruppentheorie
Code
Elektronische Unterschrift
Inverser Limes
Optimierung
Softwareentwickler
Bildgebendes Verfahren
Validität
Mailing-Liste
Physikalisches System
Vektorraum
Gerade
Objekt <Kategorie>
Last
Mereologie
Parametersystem
Normalvektor
Punkt
Momentenproblem
Formale Sprache
Selbstrepräsentation
Mobiles Endgerät
Soliton
Raum-Zeit
Marketinginformationssystem
Computeranimation
Netzwerktopologie
Typentheorie
Meter
Einflussgröße
Gerade
Funktion <Mathematik>
Inklusion <Mathematik>
Softwaretest
Umwandlungsenthalpie
Lineares Funktional
Parametersystem
Befehl <Informatik>
Vervollständigung <Mathematik>
Sichtenkonzept
Computersicherheit
Güte der Anpassung
Systemaufruf
Vorzeichen <Mathematik>
Programmierumgebung
Optimierung
Elektronische Unterschrift
Dialekt
Softwarewartung
Arithmetisches Mittel
Gefangenendilemma
Funktion <Mathematik>
Rechter Winkel
Ganze Zahl
Konditionszahl
Ein-Ausgabe
Information
Ordnung <Mathematik>
Zeichenkette
Instantiierung
Aggregatzustand
Magnetbandlaufwerk
Schnittstelle
Web Site
Klasse <Mathematik>
Zellularer Automat
Implementierung
Zahlenbereich
Code
Multiplikation
Elektronische Unterschrift
Datentyp
Optimierung
Mobiles Endgerät
Widerspruchsfreiheit
Bildgebendes Verfahren
Implementierung
Meta-Tag
Soundverarbeitung
Distributionenraum
Spider <Programm>
Validität
Rechenzeit
Modul
Office-Paket
Integral
Objekt <Kategorie>
Mereologie
Computerarchitektur
Informationsmodellierung
Leistungsbewertung
Bit
Stab
Gruppenoperation
Adressraum
Mathematisierung
Formale Sprache
Besprechung/Interview
Annulator
Code
Physikalische Theorie
Eins
Netzwerktopologie
Spezifisches Volumen
Optimierung
Datenstruktur
Analysis
Lineares Funktional
Strömungsrichtung
Quellcode
Modul
Teilbarkeit
Festspeicher
Zeichenkette
Aggregatzustand
Fitnessfunktion

Metadaten

Formale Metadaten

Titel Inspect (Or Gadget)
Serientitel EuroPython 2017
Autor Bauvin, Renaud
Lerebours, Hugues
Lizenz CC-Namensnennung - keine kommerzielle Nutzung - Weitergabe unter gleichen Bedingungen 3.0 Unported:
Sie dürfen das Werk bzw. den Inhalt zu jedem legalen und nicht-kommerziellen Zweck nutzen, verändern und in unveränderter oder veränderter Form vervielfältigen, verbreiten und öffentlich zugänglich machen, sofern Sie den Namen des Autors/Rechteinhabers in der von ihm festgelegten Weise nennen und das Werk bzw. diesen Inhalt auch in veränderter Form nur unter den Bedingungen dieser Lizenz weitergeben
DOI 10.5446/33721
Herausgeber EuroPython
Erscheinungsjahr 2017
Sprache Englisch

Inhaltliche Metadaten

Fachgebiet Informatik
Abstract Inspect (Or Gadget) [EuroPython 2017 - Talk - 2017-07-13 - Anfiteatro 2] [Rimini, Italy] Introspection is often seen as a bad coding practice and as such a gadget. Nevertheless, the Python Standard Library provides different tools (among them the 'inspect' library) to easily identify a generator, recover the source code of a function or get a function signature. We propose to spend 1/2 hour to dig into what introspection has to offer to developers, to see what tools are available, what you can get out of them and some useful use cases that we met in our practice at Criteo

Ähnliche Filme

Loading...