Check that every function has an annotation [no-untyped-def]
If you use —disallow-untyped-defs
, mypy requires that all functionshave annotations (either a Python 3 annotation or a type comment).
Example:
- # mypy: disallow-untyped-defs
- def inc(x): # Error: Function is missing a type annotation [no-untyped-def]
- return x + 1
- def inc_ok(x: int) -> int: # OK
- return x + 1
- class Counter:
- # Error: Function is missing a type annotation [no-untyped-def]
- def __init__(self):
- self.value = 0
- class CounterOk:
- # OK: An explicit "-> None" is needed if "__init__" takes no arguments
- def __init__(self) -> None:
- self.value = 0