Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Python Type Checking: Summary

Give Feedback

Type hinting in Python is a very useful feature that you can happily live without. Type hints don’t make you capable of writing any code you can’t write without using type hints. Instead, using type hints makes it easier for you to reason about code, find subtle bugs, and maintain a clean architecture.

In this course, you learned how type hinting works in Python, and how gradual typing makes type checks in Python more flexible than in many other languages. You’ve seen some of the pros and cons of using type hints, and how they can be added to code using annotations or type comments. Finally, you saw many of the different types that Python supports, as well as how to perform static type checking.

There are many resources to help you learn more about static type checking in Python. PEP 483 and PEP 484 give a lot of background on how type checking is implemented in Python. The Mypy documentation has a great reference section detailing all the different types available.

To download the code in this course, click the link below:

Download

Sample Code (.zip)

8.3 KB

00:00 This video is the conclusion and course review. Hey, congratulations! You completed the course! This course was but an introduction to type hinting and applying type checking to your code. To continue your learning, check out some of the links below this video.

00:16 I’m going to take you through a review of all that you covered in this course. You started out with an intro and course overview. Then you went right into the difference between dynamic typing and static typing, comparing the dynamic language of Python versus the static typing in something like Java. Then you learned about duck typing, where you do not check types at all.

00:41 Instead, you check for the presence of given methods or attributes.

00:48 Next, it was time to start adding type hints, and you learned how to add type hints to functions.

00:57 After that, you’re ready to type check your code using the tool Mypy, which you installed and got to practice finding type errors.

01:08 That was followed by the pros and the cons of adding type hints to your code, and you learned that type hints could be gradually added to your code. If you’re creating code that’s going to be shared with others, or is important enough to add unit tests to, then you probably should think about adding type hints.

01:26 The next video covered the history of annotations and how they’re now being used as type hints. You learned how a function has an .__annotations__ dictionary and how there’s an __annotations__ dictionary at the module level, too, for variables.

01:42 And then to compare annotations with type comments in the next video, where type comments allow you to add type checking to legacy Python code. Then there was a chance to play around with Python types a little bit further with the card game, and you got to practice using the typing module and a few additional type hints for sequences, like tuples and lists.

02:06 And then, finally, this conclusion and course review. I want to thank you for joining me on this course. Make sure that you take time to practice with what you’ve learned.

aaliquegrahame on Nov. 3, 2019

Great info! Not sure if I missed this but hints would work for user defined types as well right?

Geir Arne Hjelle RP Team on Nov. 3, 2019

Yes, type hints work great for user defined types as well.

I don’t think it’s covered in the videos, but you can find some information about using your own classes as types in the article the videos are based on (see the Supporting Material link under the video): realpython.com/python-type-checking/#classes-as-types

km on Jan. 8, 2020

Another wonderful learning !

Ghani on Oct. 17, 2020

Excellent tutorial; thanks!

Become a Member to join the conversation.