Enhancing your Python code with type hints and type checking

Publié le: 17 mai 2021
sur la chaîne: Devyx
287
3

In this tutorial, we are illustrating how Python type hints and type checking works by building some real-world functions that pull crypto currency pricing data!

But, uhh... why should we care about type hints?

Understanding the 'ingredients' that your Python functions and classes expect as inputs and return as outputs can be a game changer when you are writing a significant amount of code.

Is this value supposed to be a string? An integer? A list? If you're using type hints, the answer is already in your face. If you choose to not use type hints, then it's less obvious what you need to provide to (or what you will receive from) functions and classes in your development process.

Additionally, using type hints opens the door to using the `typeguard` library to type check your functions and classes. This makes the types enforced, rather than just providing hints at what the types are supposed to be.

The idea of enforcing static typing doesn't appeal to everyone in the Python ecosystem, but keep in mind there is a difference between having type hints and enforcing type checking. In general, having type hints will help you develop code more efficiently because it helps you pick up any arbitrary piece of code and quickly understand the ingredients necessary to make that code work properly.


Sur cette page du site, vous pouvez voir la vidéo en ligne Enhancing your Python code with type hints and type checking durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Devyx 17 mai 2021, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 287 fois et il a aimé 3 téléspectateurs. Bon visionnage!