I have dictionary:
example: dict[str, Union[str, int]] = {"foo": 1, "bar": "baz"}
Values are strings and integers. When I try to use values from it I definitely know what type of data I get from a particular key. But mypy doesn’t know value, that i want to use is a string or integer.
For example, I want to compare int value with another int
res: bool = example["foo"] > 1
I understand why mypy says “Unsupported operand types for > (“str” and “int”)”, but I want to ignore this errors. What can I do?
I think Any type won’t be best solution. Maybe I can configure mypy to ignore this errors?
Sorry for my bad english, thanks)
Тимур Котов is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.