microsoft / pyright

Static Type Checker for Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect type narrowing for isinstance when filter is a generic class with a type parameter that has a default

erictraut opened this issue · comments

from typing import Generic
from typing_extensions import TypeVar


T = TypeVar("T", bound=int, default=int)


class Foo(Generic[T]): ...


def func(obj: object):
    if isinstance(obj, Foo):
        reveal_type(obj) # Should be Foo[Unknown], but is currently Foo[int]

My first attempt at fixing this resulted in some apparent regressions that need to be investigated and addressed.

This is addressed in pyright 1.1.363, which I just published.