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