UPDATE: Although the original example is now special-cased in a plugin, the underlying problem is not solved, see #1317 (comment)
The following:
from typing import *
from contextlib import *
T = TypeVar("T")
@contextmanager
def foo(x):
# type: (T) -> Iterator[T]
yield x
y = 1
with foo(2) as f:
y = f
gives this error:
error: Incompatible types in assignment (expression has type "T", variable has type "int")
It should recognize the input as an int which would lead to the output being an int as well, not a T. This is probably due to the way the contextmanager stub is defined in typeshed.
UPDATE: Although the original example is now special-cased in a plugin, the underlying problem is not solved, see #1317 (comment)
The following:
gives this error:
It should recognize the input as an
intwhich would lead to the output being anintas well, not aT. This is probably due to the way thecontextmanagerstub is defined in typeshed.