Hi anyone know how to resolve this error in py3? Getting error message like:
"int" has incompatible type "Union[float, int, str, None]"; expected "Union[str, bytes, SupportsInt, SupportsIndex, SupportsTrunc]
My type is an optional value Union[float, int, str, None]
. I would like to cast it when it's an int int(VALUE)
. Union is from typing
module
Solution found in mypy giving error as incompatible type "Optional[int]"; expected "Union[SupportsFloat, str, bytes, bytearray]
Example
Similar to
float
andstr
or for the value in the list[int(t) for t in list if isinstance(t, int)]