Effective PyCharm Transcripts
Chapter: The Editor
Lecture: Working with the editor demo: Types
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
Things were going. So so well our app is coming along remember on the first part I told you how we didn't have to go to the documentation,
0:08
we could just come in here and say 'cmd+p'. And it gives us information about what's supposed to go into this section and we get
0:15
all the support. But I feel a little bit let down here. For example that is not the things on the episode. And even over here it's this episode id.
0:25
But is that like a UUID Is that an integer? Is it a string? What's that supposed to be?
0:31
So what you'll see is that if we use type annotations type hence in Python
0:36
PyCharm will leverage that information and flow it through the rest of our applications.
0:41
So let's go down here and let's say that this is going to return what's it going to return? I want to turn an episode.
0:51
Not quite right. We're going to come back to it but let's go over here and just do this again. Now this we're not declaring as an episode which we
0:58
could we could do that and then go import this over here but we don't have
1:03
to because this function returns an episode PyCharm is certain that that's an episode. So now let's go and hit dot yes look at that title id.
1:12
Date link all the things that it needs to be an episode. So that's really fantastic. How is it?
1:22
Not quite right technically we could ask for an episode that doesn't exist in which case
1:28
this would be none. The type system in Python says it can't be none unless you explicitly say it's none. So the way we do that in Python,
1:37
as we say optional from typing of this. So that's the more accurate thing. But still you'll see the exact same behaviors.
1:47
Okay down here this is going to return an int not really using it but let's go out and just be complete here.
1:59
This we go to the episodes like for example if I go episodes zero dot nothing let's make that better. This we can say is a dictionary a dict of an int
2:16
and then an episode the key is an integer. The thing is an episode. Now if I go to hear and say dot look at that Fantastic. I'll say id
2:25
Equals one something like that. If I were good in him put zero it says whoa, whoa, whoa you're trying to pass a string even though it's number like
2:36
it's not a number, you're trying to pass a string using the wrong type of key. So it's not just that it gives us better.
2:42
Auto complete. It gives us checking and validation as well. So this doesn't take a return anything.
2:48
I think we've done our type information and now that we do of course we get all kinds of good stuff here we go down to the end and say dot you'll
2:56
see integer integer integer it knows what it is. So whenever it makes sense. Whenever you can add this type information to your program
3:05
because it's going to make working with your code much better. PyCharm will help you write new code by giving you better auto complete and it
3:12
will help you catch errors by checking that the types match. But again, you don't have to write it everywhere through your code.
3:19
Just put it on the sort of service boundary, data, access boundary pieces and then often that information flows through like automatically to there
3:26
And to here, I'm a super big fan of using types like this to make your editor make PyCharm, better think about doing it for yourself.