Python Type Hinting and Type-Checking Crash Course with mypy [Tutorial]

preview_player
Показать описание
Is your autocomplete not working in VSCode? Add type hints!
Python is a dynamically typed language which means that type checking is performed at run-time (when executed). If there is an error in the code it will be thrown at execution. This can lead to unexpected errors and bugs if you are not careful as a developer. By using a static type checker tool like mypy and using type hints in Python we can dramatically reduce chances of runtime errors in Python code.

Source code:

00:00 Intro
00:35 Why use type hinting
01:17 mypy: How to enforce type checking
01:44 Run mypy and VSCode extension
02:10 Automated type checking!
02:22 Adding type hints to functions
03:30 Adding type hints to Lists
04:04 Adding type hints to Dicts
04:18 TypedDicts types
05:28 Sequences types
06:33 Optional and Any types
07:09 Custom types
07:45 Generic types
09:32 Wrap-up

Please consider liking if you found the video useful and subscribe for more!

Рекомендации по теме
Комментарии
Автор

This was quite useful, actually. There are a lot of videos about typing in Python, but this one is straight to the point. No bla bla bla stuff. Thank you

justchary
Автор

mypy extension is not showing type error what should i do?

osamafreelancer
Автор

Help! I have mypy installed and it works from the terminal but the extension does not work at all. VScodium says it's an invalid extension and says "Unable to resolve nonexistent file"

element
Автор

how do you import libraries like requests though? i get an error like this: Library stubs not installed for "requests"mypyimport-untyped
pip install types-requests doesn't help too :(

bobsmithy