Effective PyCharm Transcripts
Chapter: The Editor
Lecture: Code intentions - light bulb moments

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