pytype
pytype copied to clipboard
Incorrect type inference with list.__getitem__ (--protocols)
Software versions
Python 3.9.7 pytype 2021.11.29
Testcase
x = [0]
def get(i):
return x[i]
Description
pytype-single --protocols repr.py
generates this .pyi:
from typing import List, Union
x: List[int]
def get(i: Union[int, slice]) -> list: ...
I would expect __getitem__ on a list of integers to have a chance of returning an integer - Union[int, List[int]]
at the strictest, though Any
would be more useful. pytype thinks it returns a list of unknown type.