[Tutor] Type annotation errors

boB Stepp robertvstepp at gmail.com
Thu Jun 4 20:41:52 EDT 2020


On Thu, Jun 04, 2020 at 04:31:24PM +0200, Peter Otten wrote:
>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

Hmm.  This seems to be the exactly what the situation requires.  I had not
looked into typing_extensions yet.  Thanks!

-- 
Wishing you only the best,

boB Stepp


More information about the Tutor mailing list