Modern APIs with FastAPI and Python Transcripts
Chapter: Course conclusion and review
Lecture: Review: Type hints
0:00 One of my favorite features of modern Python is type hints, the ability to put type
0:06 information right into our Python code that is somewhat like the static languages that have very rigid structure, but not quite so picky.
0:16 So here we had this simple example of, remember our menu ordering app that would tell us how much we spent on different meals?
0:23 Well, it had a running max for the maximum order of any of our meals, instead of just saying that was none,
0:29 which gave us no information at all about it, as well as the editors, that this is an optional integer and optional means it can
0:37 either be an integer or none. And then we had a function that's going to work with that running max,
0:42 and it's going to take some items, these are out of our menu and each one of those was an item named tuple.
0:47 So here we have an iterable of item coming in, and then the return value is an integer. Now in many places in Python,
0:54 this is here to help the editors and other linter tools that will go through our code and tell us if things are alright, but runtime it doesn't matter.
1:01 We saw that, actually, in things like pydantic and FastAPI, this type hints,
1:06 type information is taken farther to actually do things like type conversions and checking for required
1:12 values, whether or not they're optional or they're non-optional and so on. So this is a really important concept in general,
1:18 and it is especially important in the FastAPI world.