Show Menu

Type Checking and mypy Cheat Sheet by

python     type     mypy     type-checking

MyPy Tool

mypy [files]
Command line to check syntax
-v
Be Verbose
-any-­exp­rs-­report PATH
Provide a path to generate a coverage report
This tool will show you Type Errors found in the code. If verbose is off and the command returns nothing, the code is OK.

Type Definition

from typing import Dict, List, Tuple
Import types definition
var: str = "­"
Define str a variable
var: Dict[str, int] = {}
Define Dict a variable
var: Tuple[str, float, int] = ()
Define Tuple a variable
MyType = Dict[str, int]
Define a custom 'Type`
var: MyType = {}
Define MyType a variable
def functi­on(arg: str) -> int:
Define a function that takes an strand returns an int
var: Any
The Any type accepts all types
var: Union[str, int]
This Union type accepts either a str or an int
pip install mypy
pip install typing

Download the Type Checking and mypy Cheat Sheet

1 Page
//media.cheatography.com/storage/thumb/amicheletti_type-checking-and-mypy.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          More Cheat Sheets by amicheletti