mypy
mypy copied to clipboard
(🐞) Type becomes `Any` when context managers type is inferred after the usage
from typing import Iterator, Callable
from contextlib import contextmanager
class E:
a: str
def f(e: E) -> None:
with cm():
if e.a:
pass
reveal_type(e.a) # Revealed type is "builtins.str"
def f2() -> None:
pass
reveal_type(e.a) # Revealed type is "Any" # Revealed type is "builtins.str"
@contextmanager
def cm() -> Iterator[None]:
yield