def resolve_all(items):
for item in items:
item.case.resolve()
def cancel_all(items):
resolve_all(items)
notify_all(items)
...
def notify(who: User, message: str = 'Default message') -> None:
...
def count_chars(text: str) -> Dict[str, int]:
...
class ExampleClass:
text: str = 'Some text'
number: int
def __init__(self, number: int, text: str = ''):
self.number = number
if text:
self.text = text
@dataclass
class InventoryItem:
'''Class for keeping track of an item in inventory.'''
name: str
unit_price: float
quantity_on_hand: int = 0
def total_cost(self) -> float:
return self.unit_price * self.quantity_on_hand
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"