pytype icon indicating copy to clipboard operation
pytype copied to clipboard

Variable annotation loses TypeVar information

Open cebtenzzre opened this issue 2 years ago • 0 comments

Software versions

Python 3.9.9 pytype 2021.12.15

Example

from typing import Generic, TypeVar

T = TypeVar('T')

class Foo(Generic[T]):
    def __init__(self, x: list[T]):
        pass

foo = Foo(['a'])
reveal_type(foo)  # Foo[str]

fooa: Foo[str] = foo
reveal_type(fooa)  # Foo

Description

While trying to make an MWE for a false positive caused by the interaction of #215 and a TypeVar bound, I stumbled across this. The type of foo is correctly inferred as Foo[str], but once you annotate it pytype forgets the specific type.

cebtenzzre avatar Dec 16 '21 02:12 cebtenzzre