from typing import Dict, List, Optional
class ExampleClass:
text: str = 'Some text'
number: int
def __init__(self, number: int, text: str = ''):
self.number = number
if text:
self.text = text
def iterate(self, vals: Optional[List[int]]) -> None:
for val in vals:
print(val)
def notify(who: Optional[ExampleClass], message: str = 'Default message') -> None:
return who.notify()
ex = ExampleClass(111)
ex.nonexistent
notify(ex)
another = ExampleClass('123')
> mypy ex1.py
ex1.py:14: error: Item "None" of "Optional[List[int]]" has no attribute "__iter__" (not iterable)
ex1.py:19: error: Item "ExampleClass" of "Optional[ExampleClass]" has no attribute "notify"
ex1.py:19: error: Item "None" of "Optional[ExampleClass]" has no attribute "notify"
ex1.py:24: error: "ExampleClass" has no attribute "nonexistent"
ex1.py:28: error: Argument 1 to "ExampleClass" has incompatible type "str"; expected "int"