Open gpshead opened 5 years ago
This looks like https://google.github.io/pytype/faq.html#why-didnt-pytype-catch-that-my-program-might-pass-an-invalid-argument-to-a-function. When a function is passed an argument with multiple possible types, pytype allows it as long as one of the types is valid =/
I know --strict-parameter-checks is experimental, but for what it's worth, this is the reason I stopped using it:
x = {0: '1', 'a': 'b'}
print(x[0])
$ pytype-single --strict-parameter-checks repr.py
File "repr.py", line 2, in <module>: unsupported operand type(s) for item retrieval: Dict[Union[int, str], str] and int [unsupported-operands]
Function __getitem__ on Dict[Union[int, str], str] expects str
For more details, see https://google.github.io/pytype/errors.html#unsupported-operands
edit: This seems to have been fixed.
Take this example code, I was hoping pytype would flag the bug of blindly using an
&
on the result of anOptional[int]
function without checking for None. It unfortunately allows it.(aka experimental/users/gps/pytype/optional_int_binop.py internally)
I expect this can be simplified further, I started by recreating a similar (though already simpler) structure to pytype checked code I was fixing an actual bug in.