[Tutor] Type annotation errors
Peter Otten
__peter__ at web.de
Thu Jun 4 10:31:24 EDT 2020
Peter Otten wrote:
> There might be a way to tell mypy that two cases cannot occur and still
> use dicts as pseudo-structs
I found
https://mypy.readthedocs.io/en/stable/more_types.html#typeddict
with that:
from typing_extensions import TypedDict
Record = TypedDict("Record", {"shares": int, "name": str, "price": float})
def evaluate_portfolio(
portfolio: List[Record], stock_prices: Dict[str, float]
) -> Tuple[float, float]:
... # body unchanged
More information about the Tutor
mailing list