Effective PyCharm (2021 edition) Transcripts
Chapter: The Editor
0:00 One of the things that always delights me about PyCharm.
0:03 Is it auto complete. Now many editors you use,
0:06 it looks like they have auto complete you type of word.
0:09 A little bit of something comes up and it's going to complete it.
0:11 But so often what it's just doing is looking at the keywords or maybe if you're
0:15 lucky, the symbols in a particular file and then trying to complete that for example
0:20 open up VS code, create,
0:22 just start typing text and you'll see the text is starting to get completed but it
0:26 has no meaning it has no understanding of what that is.
0:29 PyCharm on the other hand,
0:30 works deeply with your project and your structure and other information to help you get exactly
0:36 the right information most of the time and when it doesn't,
0:39 we'll see in just a moment how to make it better.
0:41 So here we have a class which is a wizard creating a hero an object,
0:45 an instance of that wizard. The wizard derives from creature,
0:49 the wizard class drive from the creature class and some of the behaviors come from the
0:54 creature and some from the wizard.
0:55 So here we say hero dot and notice we get a completion of the entire type
1:00 hierarchy And over here on the side you can actually see what elements come from the
1:05 creature class and what elements come from the wizard class as well as the base object
1:09 class itself. Now, sometimes it's not as glorious as that.
1:14 Sometimes PyCharm doesn't really know what is happening and what is being returned for sure
1:18 So it's not going to give you any help.
1:21 So here we say data dot findings or by email we pass an email and we
1:24 expect imagine surprise, surprise a user object or something like that back.
1:29 Right. But we say user dot and we get a meaningless list of python keywords
1:34 Right. It doesn't even make sense to say user not or user while,
1:38 but well there it is. Anyway,
1:40 so what do we do? The problem is that we're doing some SQLalchemy query
1:45 here and the steps in the SQLalchemy query are too complicated for PyCharm to
1:50 understand. Well if I go to the user thing,
1:53 the user type and I do an object query and then I say first that's going
1:57 to be an optional user. Just,
1:59 it could know that, but it doesn't,
2:01 we want to give it a little bit of help.
2:02 We want to encourage it to do better.
2:05 So now if we go over here and we augment our find user by email and
2:09 we add this optional user, which is what's actually being returned.
2:13 If we just write that for PyCharm boom,
2:16 all of a sudden it lights up that we've got name and email and all kinds
2:20 of stuff that comes from the user.
2:22 So when the auto complete doesn't work exactly as you like.
2:26 It probably because PyCharm doesn't know and usually adding a small sprinkling of type-ins
2:31 throughout your code will really make it work much much better.