diff --git a/test-data/unit/check-based-contextmanager.test b/test-data/unit/check-based-contextmanager.test new file mode 100644 index 000000000..a9a76d97d --- /dev/null +++ b/test-data/unit/check-based-contextmanager.test @@ -0,0 +1,30 @@ +[case testContextManagerWorkProperly] +from __future__ import annotations + +class Base: + def __enter__(self): ... +class Swallow(Base): + def __exit__(self, x: object, y: object, z: object) -> True: return True +class Pass(Base): + def __exit__(self, x: object, y: object, z: object) -> False | None: return None +class Normal(Base): + def __exit__(self, x: object, y: object, z: object) -> bool | None: return True + +def f1(): + with Swallow(): # E: Call to untyped function "Swallow" in typed context [no-untyped-call] + raise Exception + 1 + +def f2(): + with Pass(): # E: Call to untyped function "Pass" in typed context [no-untyped-call] + raise Exception + 1 # E: Statement is unreachable [unreachable] + +def f3(): + with Normal(): # E: Call to untyped function "Normal" in typed context [no-untyped-call] + raise Exception + 1 + with Normal(): # E: Call to untyped function "Normal" in typed context [no-untyped-call] + return + 1 # E: Statement is unreachable [unreachable] +[builtins fixtures/exception.pyi] diff --git a/test.py b/test.py new file mode 100644 index 000000000..b7c2f8275 --- /dev/null +++ b/test.py @@ -0,0 +1,30 @@ +from __future__ import annotations + + +class Base: + def __enter__(self): ... +class Swallow(Base): + def __exit__(self, x: object, y: object, z: object) -> True: return True +class Pass(Base): + def __exit__(self, x: object, y: object, z: object) -> False | None: return None +class Normal(Base): + def __exit__(self, x: object, y: object, z: object) -> bool: return True + +# def f1(): +# with Swallow(): +# raise Exception +# 1 + +# def f2(): +# with Pass(): +# raise Exception +# 1 # E: Statement is unreachable [unreachable] + +def f3(): + with Normal(): + raise Exception + 1 + with Normal(): + return + 1 # E: Statement is unreachable [unreachable] +liam is a nigger