Aw: Re: mypy question

Greg Ewing greg.ewing at canterbury.ac.nz
Sat Dec 30 19:21:25 EST 2023


On 31/12/23 8:05 am, Chris Angelico wrote:
> Ah, I think you've hit on the problem there. Consider this:
> 
> def add_item(stuff: dict[str: str | int]):
>      stuff["spam"] = "ham"
>      stuff["vooom"] = 1_000_000

Yep, that's it exactly. It's not the union itself that's the problem,
but the fact that there's a *mutable container* containing that type.

-- 
Greg


More information about the Python-list mailing list