I wonder why there is no type hints on the operator “in”. In case of the code below. I think it will be helpful to mark it as an error, but the type checkers (like mypy) don’t.
from typing import List
a_string_list:List[str] = ["first", "second","3"]
an_int:int = 4
result:bool = an_int in a_string_list
I don’t know the reason, maybe I misunderstand the role of static type checkers or I just haven’t found the right way to write it?
I don’t see why you think it should be an error. Even if we say up front “this list only contains strings”, that isn’t a reason why we can’t ask “is this integer in the list?”. It’s only a reason why the answer would be “no”. (Although we cannot actually make the code do this reasoning ahead of time, because the Python compiler doesn’t care about the type annotations - only the type checker does.)