Static type checking with Mypy — Perfect Python

preview_player
Показать описание
Welcome to Perfect Python, the series where I show you how to take your code to the next level — perfection.

In this episode we'll be talking about enforcing static types using Mypy. This video won't turn Python into a statically typed language, but it will allow you to reap some of the benefits of it nonetheless. Static type checking provides clear insight into what your program is doing, and exactly what functions and classes expect to be passed to them. Autocomplete utilities also use this to provide the best experience to developers, so this isn't just useful for maintainers — it's useful for everyone.



If you enjoy my content, consider supporting me on Patreon (or hit the JOIN button below to become a member)!

If you need help with anything, feel free to join the Discord server:



If you have any questions, don't hesitate to ask in the comments! I'll try and answer as soon as I can, providing someone else hasn't already done so.

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

Thanks for the video. I am currently in the process of adding mypy to my toolkit. One small bug I noticed at 6:00 it should be "if n1 is None" instead of "if not n1" as you should expect "add_numbers(0, 1)" to return 1, and not 0.

theepicdev
Автор

Great tutorial and explanation of Liskov’s principle

guyfisher
Автор

Very nice explainer. Well done.

As a comment on typing dynamic languages in general, it always seems - having watched and cared about these things, and this thing in particular, for 25 years - that the developer community of any beloved, dynamic, and increasingly important language will eventually come around to the general conclusion that the dynamic part of their language is a hindrance to the maturation of everything to do with the language. See: PHP7, Python 3.7, the glorious savior of us all... TypeScript.


Keep up the great series. I'll be checking in!

i-see-right-through-you
Автор

I totally forgot that we can typehint in python :O

Preety Good and Helpfull Video 👍

icrazyrockstar
Автор

The fix for the substitution issue is to change the type of "text" from "int" to "Union[str, int]" and handle both in the code. Now the substitution is valid and the subclass handles a wider range of parameters. The mypy error goes away.

Unavailable
Автор

Thanks for your video, nice vidoe and voice!

xiliu
Автор

What do you think about pyright vs mypy vs pyre vs pytype? why do you use mypy over the others?

charliewhousen
Автор

do you have pylance extension installed in your vscode setup?

MeriemSaid-pg
Автор

Violation of Liskov is correct. It is one of the weakest solid principle but you can say that if you violate Liskov it is a code smell....

johnysmrz
Автор

Is it just me or does the 4k resolution look more pixelly then 1080 or 1440p

Great video btw :D

tdz
Автор

mypy vs pylint vs flake8

when should you use them and which would you prefer?

TheBigW
Автор

you can prepare before what are the things you gonna cover. if not it affects the users who consumes your video. just like you get confused in between

aravindr
Автор

I personnaly don't like mypy. I often need to ignore its errors.

charlesenglebert