Modern APIs with FastAPI and Python Transcripts
Chapter: Course conclusion and review
Lecture: Review: Type hints

Login or purchase this course to watch this video and the rest of the course contents.
0:00 One of my favorite features of modern Python is type hints, the ability to put type
0:05 information right into our Python code that is somewhat like the static languages that have very
0:12 rigid structure, but not quite so picky.
0:15 So here we had this simple example of, remember our menu ordering app that would tell
0:20 us how much we spent on different meals?
0:22 Well, it had a running max for the maximum order of any of our meals,
0:27 instead of just saying that was none,
0:28 which gave us no information at all about it,
0:31 as well as the editors, that this is an optional integer and optional means it can
0:36 either be an integer or none.
0:38 And then we had a function that's going to work with that running max,
0:41 and it's going to take some items, these are out of our menu and each one
0:44 of those was an item named tuple.
0:46 So here we have an iterable of item coming in,
0:49 and then the return value is an integer. Now in many places in Python,
0:53 this is here to help the editors and other linter tools that will go through our
0:57 code and tell us if things are alright,
0:58 but runtime it doesn't matter.
1:00 We saw that, actually, in things like pydantic and FastAPI, this type hints,
1:05 type information is taken farther to actually do things like type conversions and checking for required
1:11 values, whether or not they're optional or they're non-optional and so on.
1:15 So this is a really important concept in general,
1:17 and it is especially important in the FastAPI world.