GitHub Copilot for Python Development

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hi and welcome to a new coding section in which we will see how uh we get assistance for python development for GitHub co-pilot the requirements for this section are that you already have python installed and uh you have at least some basic python knowledge in this section we will see how we can get assistance while building an interesting app in my opinion a password Checker and also we will see how we can generate tests for that application we will do this with GitHub co-pilot we will also have a basic practice session for lists and uh before finishing this intro for this section let's review my own setup for VSS code for python development to make sure that we are on the same line so I will switch to the to my ID I'm currently inside my IDE I have python installed if I will check right here I have python installed right here I also have another python version right here there's no problem but regarding python uh extensions I'm using inside vs code the extension pack for python this is the one right here the python extension also I'm using uh Pi lens and uh as a a linting tool I'm using the black formatter for python this is my Python vs code setup if you want it you can also use it in the same way let's proceed into the next uh lecture and uh see the assistance that we get from GitHub co-pilot for python coding let's start this lecture by creating a simple python file and see how GitHub copilot gives us assistance and as mentioned I will work on a password checker functionality so I will first create a new file I will call this password Checker dop and now we can simply to start to write our implementation but let's let GitHub copilot do the work for us but I will also start with my function name so here I'll say Dev validate password this receives a password and now let's see what we get Let's uh let V GitHub copilot think a little and uh basically I think we are good to go but I really want to uh have my own implementation of this uh function so I will write the first condition myself so here I'll say if the length of our password so here I'll say if length of our password is smaller than eight and the length is bigger than 20 all right this is all right we should return false that's great let's now do a uh uppercase and the lowercase container for this so here I'll say and I want to use iterators for this implementation so maybe adds a new line here I'll say if not any all right it wants to give me the digit uh contains I will simply run this accept this we return false all right right that's great we want to also now check the lowercase and the uppercase implementations and as you can see as soon as I gave some basic context to GitHub copilot it now knows exactly the structure I expecting from my checks and this is great I will accept this implementation all right we are returning false that's great and now we want to also a lower check that's great we are returning false and we finally we will want to also make a special characters check I can say if right here or maybe let me just point GitHub C pilot to do things for me since uh I'm not really know what to do and let me add right here add a special character check all right and uh this looks exactly how I wanted I will accept this and finally if all these checks are done I will simply return true inside this function and uh yes if uh the list of special characters is a little small for you maybe you can simply point out to GitHub copilot you know with more words maybe using the dialogue exactly what you want and then it will give you exactly what you want well this is one implementation of the function let's write another implementation of the function but this time by returning meaningful messages and uh from my experience with GitHub copilot until now I can't just say hey write a new variant or a new version of this function with this alteration and it will not do that I mean it will do that but it will replace my old function I don't want that so I will simply copy this function right here I will create a new uh let's just say a new function def validate password with error messages and I will instruct I will select this and I will instruct GitHub copilot rewrite the function I told you rewrite the function by raising the incorrect reason let's see if understands what I want hopefully it does and even if my spelling wasn't the best it understood what I wanted instead of returning true or false it will simply return or raise meaningful messages you know that contain the the reason for the password not being valid I will accept this and as you can see this looks like a GitHub diff view I will accept this and now we have a new version of this function I will simply not return anything simply we want to validate this password if nothing is uh no error is thrown then our function is all right and as a last exercise inside this uh lecture let's see how how gith up co-pilot helps us with regular expressions and I tell you it is very powerful and even if uh maybe for you you are not so good with regular Expressions this is the case for me I was never a master of regular Expressions I never liked them GitHub copilot is here for us let's write this all this implementation with regular Expressions it will take a while for us just to do it by hand but luckily we have have GitHub copilot so I will simply create a new function first of all I don't want to lose this implementation so I have a new function right here I will call it validate password with error messages regex like this I will save this and I will select this function or maybe only the its name I will start GitHub copilot inline chat right here and I will see I will say I told it rewrite this function using regular Expressions let's see what we get and first of all it imported regular expressions and then if we go downstairs you'll see it will give us a nice implementation with regular expressions like this I will accept this the diff view is still not perfect from vs code as you can see here we have no changes but still we see it in blue no problem I will accept this I will add a space right here but if I will look lower down the line you will see we have this new version of our function this time with regular expressions and uh this is great you know the support for regular Expressions is great in GitHub copilot we saw how we can quickly write three versions of the same function very fast using GitHub copilot let's proceed into the next lecture and see how we can rapidly generate messages or documentation with GitHub copilot in this lecture we will see the assistance that we get from GitHub copilot when we want to generate text or documentation inside our code files and this is as simple as selecting our function right click copilot generate docs like this we will wait wait for a few moments and let's see if understands what uh we need yes in understood what we need so I will accept this implementation this uh documentation we also see it right here vs code will show it as we Hoover over the function name let's proceed into the next section into the next function and see that if we get a meaningful documentation also here since the implementation is slightly different yes this time it uh this function doesn't return true or false it simply raises a value at error if the password doesn't meet any of the above criteria that's great I really like this uh implementation let me just for fun see if for example I'm removing a special character right here let me remove this and see if now the documentation generated will be uh faithful let's say I would call generate docs and yes the documentation will also be faithful it is really that smart if I moved removed that special character it was also removed from the documentation I will accept this and now of course I will also do the same for the other implementation co-pilot generate docks and now we have professional looking docks even if it took a few seconds for us yes this implementation is a little more meaning minimal I guess it has a hard time to really parse what's going on right here I will accept this okay it tells us with specific error messages I'm really happy with this documentation that's great and one other point in which co-pilot really shines even if it's a small thing is by generating meaningful commit messages usually when I'm typing I'm coding a lot I'm really only making meaningful commit messages on bigger commits or important commits but most of the time I will use work in progress or stuff you know something just to commit this if it is in a working state but with GitHub copilot I now have this uh symbol right here this is a symbol for GitHub copilot and I will press this and it will generate a meaningful commit message for me I will wait for a few moments all right and it tell told us as ADD password validation functions all right that's great exactly what I wanted I will commit and push these changes well we saw in a few minutes inside this lecture how GitHub copilot assists us at generating documentation and also meaningful commit messages in this lecture we will see the assistance that we get from GitHub copilot for writing python tests and let's say that I'm new to python testing and I don't know exactly what to use and and uh let me ask GitHub copilot first of all and I will ask it what options do I have for testing python files and a few seconds have passed and uh GitHub copilot returned to me with some uh really nice answers and also with some examples as you can see it tells me that I can use a unit test it also give me a gives me a meaningful starter file like this or with py test or with do test and uh so on from this point it comes to personal preference or you know the tech lead preference I will use unit test for this specific lecture and the the following lectures because it is build in into python so we don't have to import anything and the you know GitHub copilot is kind enough to also give me a simple testing uh starting point so I will copy this or better said I will create my testing file and then I will insert it right there so I will insert I will uh create a new file like this and I will call this testore it's testore password Checker and first of all let's see if my testing setup works so I will move to the chat and right here click this insert at csor like this all right this is my testing setup I need a add function maybe let's see if uh get T copilot will do this for us fix ad is not defined all right please thank you very much no this is not the case so it's not smart enough to do it no problem I will simply yes add a implementation for this add function just to see if my test setup works and now let's see how do I run a p test or a unit test test how do I all right and it gave me the options all right stop all right please okay it gave me the options I can simply run it with python testore Pastor cheer. Pi because I'm calling this unit test main right here let's see if this is working so I will go to my terminal right here I will open it and I will simply insert this into my terminal like this it this will simply copy and paste this command inside my terminal let's see if it works and yes everything is all right I see this okay I don't see any red things this means that my minimal test setup is working let's now go to the next entry and let's see if we can get a minimal testing setup for our password Checker function well first of all I will simply want want to import this into my uh testing file so right here I will use from my password Checker import this password again import this check password is validate password all right let me import all of them all right you know GitHub copilot has this power to always know what you want after you have used it a while all right I have this class so I don't need this testing setup anymore because I have my uh uh I know that my tests are working and I can simply add right here a new definition test password Checker or maybe test validate password like this validate password and uh it is very good for GitHub co-pilot to uh write the first test yourself and this way it will know exactly what you want so here I will say Dev test password length password all right and right here that I want assert validate password yes this looks all right let's see if this is working so again I will run this test yes this test is working just fine so this is great this means that our testing setup works just fine let's proceed into the next lecture and finalize our tests in this lecture we will proceed to writing our tests and from this point it should be okay let's start with this uh password length right here and uh this first check only makes a check for the short value let's see if we getting a suggestion for a longer value value all right I guess this is still wrong let's see let me check this this validate password should be invalid if the password is longer than 20 so maybe I want the this a long string right here so not like this and this should be even longer like this all right let's see if uh the test is still passing yes the test is still passing we now want a uh check for the upper case and the lower case and this will simply appear as we are typing currently it tells us that it wants to give give us a suggestion for the password digit I don't want this I want test for uppercase and lower case so I will write them myself test test password uppercase all right and now it knows like this and yes as you can see the suggestions are still imperfect you know I mean uh this is not the case this validate password won't work with this kind of input because this input doesn't specify the other suggestions or the other requirements of our password this is the reason I really like this exercise with a password Checker you know it really makes you think and as you can see you need to think more than GitHub co-pilot so yes this is wrong I won't use this but the first suggestions suggestion was right let's see if the tests are still passing yes they are passing now I want a uppercase a lowercase check all right like this like this all right this is also okay that's great now let's if we are getting a uh suggestion for the digit or for the number let's say if yes so we are getting a suggestion for the password number like this no digit and it should be all right also we now want a check for the special character yes that's great this also looks all right but I really don't like these suggestions because uh for example this implementation right here this example right here doesn't have an upper case you know an upper case so it might fall because we it doesn't have an upper case you know like here we don't right here we don't have a number or we don't have a special character you know maybe we should also make the test stronger you know in this manner again a limitation of GitHub co-pilot as you can see it's not the answer to everything right here I will also add a digit I will also add an uppercase letter to make sure everything is all right and let's see if we are getting a suggestion for a valid password let's see okay let's see if this is uh working yes this should be okay let's let me run the tests and yes all the tests are running just fine that's great let's now write tests for our other implementations and let's see if uh GitHub copilot is smart enough to understand that this is the structure of our code and let's see if now it will be smart enough to also write meaningful tests now that it knows exactly or it has an idea about what we want let me just simply generate all the tests not uh write everything before for this validate password with error messages let's see so copilot I will call generate tests and this will uh Point me out that uh it will give me a refact or preview and it will go into the test password Checker all right let's see what we get right here we get a new entry inside this uh class right here this is not perfect as you can see it is inserting this somehow into the middle of the of the function like this so so but it's still all right let me add or let me apply this and then I will fix them myself you know this is imperfect but it's still I will cut this because this is not the proper point to be present all right it added this two times and now I will add this new class definition right here and this implementation should be all right yes we have a new class with uh which calls test validate password with error message this one right here and let's see if the generated tests are all right all right we have a failure let me pause the video and uh check it all right so the problem is that this example right here is a little too long I will simply make it a little shorter like this and let's see if this is still working all right right again some problem and finally the tests are okay we had some problems with this generated error code like this or like this I remove the quotes and everything is all right our password Checker also works just fine for this validate password with error messages implementation let's see in this lecture a few ways in which GitHub copilot can give us assistance when right when working with list all right for this I will create a new file I will call this data. piy and let's get started first of all a to have a simple data let's create a class employee with a name a age and a salary and I will instruct GitHub copilot to this please I told it to create a employee class with name age and salary let's see what we get exactly what we wanted that's great so we have now a simple data shape let's say like this now I will create a employee list so here I will say it will be a simple list all right let's now append some data to this list and the GitHub copilot already knows this is what I wanted to do what what other solution would be no I simply want to generate some sample data for me to work with and uh as you can see GitHub co-pilot will do this for me so I won't be in the situation to always think of ways in which to generate some sample data for me to work with so let's accept this suggestion and maybe some more all right enter tab enter tab I want more let's see even more let's see even more one more should be just fine all right and we now we have some sample data for our employee list let's now see if we can write some functions that can work with this sample data for example I want a function that will return me all the names inside this list let's see if we can write it with the assistance of GitHub copilot I will say right here get all I called it get all employees names like this and this should this looks all right let's uh see if uh this is working so here I will say I will call this to see if it it is working and let me execute this yes it looks all right so this means that our basic implementation works let's see if uh we can uh further on write our or more complex implementations maybe I want the maximum salary of this list and here I'll say Dev get all right get maximum salary and vs code and the GitHub copilot already knew knew what I wanted let me check if this is working so here I'll say print get maximum salary all right let me simply execute this and yes it returned me the maximum salary this means that everything is all right let's see if it can do a little more complicated uh operation maybe we want the employees which have a salary bigger than so here I'll say def get employees with salary bigger than and now I want a uh argument right here and basically we are good to go let's see if this is working so here I'll say get employees with salary bigger than this looks okay and close the parenthesis all right again let's simply execute this and things are looking all right so in our case Jeff and Bill have a salary bigger than 100,000 so this was basically a introduction to how GitHub copilot assists us at uh working with lists we can take things to the next level we can even have some algorithms some data structures right here you know the things that python is very popular for as you saw we get a very nice assistance
Info
Channel: Concise Developer
Views: 1,411
Rating: undefined out of 5
Keywords:
Id: wNsiJWewyjU
Channel Id: undefined
Length: 26min 27sec (1587 seconds)
Published: Thu Jan 04 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.