pytype icon indicating copy to clipboard operation
pytype copied to clipboard

Incorrect type inference with list.__getitem__ (--protocols)

Open cebtenzzre opened this issue 2 years ago • 0 comments

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.

cebtenzzre avatar Dec 01 '21 06:12 cebtenzzre