Effective PyCharm Transcripts
Chapter: The Editor
Lecture: Code intentions - light bulb moments
0:00 One of the powerful things that PyCharm does is it creates code for us. It guides us as we're creating new code.
0:08 Even if we don't have that code written yet. We saw that it helps us work with existing packages and other libraries,
0:14 but it also will help us create code in a really quick and efficient way. So for example, we're working with this data access layer.
0:21 It has a find user by email that works great. But maybe we want to, once we find the user change the email now we
0:28 can't just set it on the user object because we want to actually have that user
0:32 saved back to the database or something like that sent over an API So we want to write a function for it. So we just write what we wish existed.
0:41 Data dot change email and we pass in the arguments and we get this light bulb moment. So here you can see PyCharm is telling us,
0:49 hey, hey, hey, this doesn't really exist. And if you run it it's going to crash or if you 'Alt' hit enter, I will actually create that code for you.
0:58 So if we hit enter, we get this dropdown of options, we could ignore certain things. Could suppress this warning for others.
1:05 But what we want in this case is to create the function change email. Not here, but in the 'data.py' module we hit okay boom,
1:14 it takes us right over there and it navigates us through the elements that we've got to fill out, guessing that it's user and new address.
1:21 Super, Super cool there so some of the things we can do with these code intentions is what we just described,
1:27 creating something from a usage like a method or a class. You can do quick fixes as we saw with our service module in our opening demo
1:35 we went to work with it, it existed but it wasn't imported so it wouldn't work.
1:40 So PyCharm was happy to write import service at the top and even went further and
1:45 said we will import and install other way around install and then import requests.
1:51 It also do Micro-refactoring sometimes it sees things that can do slightly better and
1:55 it's like you know, we could say for example remove the unneeded parentheses or change the way that the string formatting looks and so on.
2:03 It will remove dead code like if there's a parameter that's not being used or variable that's not being used, it will help you with that.
2:10 It checks for Pep 8 violations. Sometimes it'll fix it often. Just a reformat code will fix it but not always It'll look for performance issues,
2:20 it'll find Python 2 to 3 mismatches, package maintenance items and so on.
2:24 So keep your eye out for those little lightbulb moments because that's PyCharms saying there's
2:29 something going on that's not quite right and I can make it a lot better with minimal effort for you.