Enhancing your Python code with type hints and type checking

Publicado em: 17 Maio 2021
no canal de: 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.


Nesta página do site você pode assistir ao vídeo on-line Enhancing your Python code with type hints and type checking duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Devyx 17 Maio 2021, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 287 vezes e gostou 3 espectadores. Boa visualização!