From 7dfd6668a523a5334f83207cd797202433014997 Mon Sep 17 00:00:00 2001 From: DetachHead Date: Sat, 30 Sep 2023 00:05:39 +1000 Subject: [PATCH 1/2] ermmmm whhat the spruce --- .../unit/check-based-contextmanager.test | 30 +++++++++++++++++++ test.py | 30 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 test-data/unit/check-based-contextmanager.test create mode 100644 test.py diff --git a/test-data/unit/check-based-contextmanager.test b/test-data/unit/check-based-contextmanager.test new file mode 100644 index 000000000..712a5ded6 --- /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..5032c75e5 --- /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 \ No newline at end of file From 4374e1b2232c5ccda3359b18a57359fa3ce7a610 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 10 Oct 2023 09:20:27 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- test-data/unit/check-based-contextmanager.test | 4 ++-- test.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test-data/unit/check-based-contextmanager.test b/test-data/unit/check-based-contextmanager.test index 712a5ded6..a9a76d97d 100644 --- a/test-data/unit/check-based-contextmanager.test +++ b/test-data/unit/check-based-contextmanager.test @@ -10,7 +10,7 @@ class Pass(Base): class Normal(Base): def __exit__(self, x: object, y: object, z: object) -> bool | None: return True -def f1(): +def f1(): with Swallow(): # E: Call to untyped function "Swallow" in typed context [no-untyped-call] raise Exception 1 @@ -20,7 +20,7 @@ def f2(): raise Exception 1 # E: Statement is unreachable [unreachable] -def f3(): +def f3(): with Normal(): # E: Call to untyped function "Normal" in typed context [no-untyped-call] raise Exception 1 diff --git a/test.py b/test.py index 5032c75e5..b7c2f8275 100644 --- a/test.py +++ b/test.py @@ -10,7 +10,7 @@ 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(): +# def f1(): # with Swallow(): # raise Exception # 1 @@ -20,11 +20,11 @@ def __exit__(self, x: object, y: object, z: object) -> bool: return True # raise Exception # 1 # E: Statement is unreachable [unreachable] -def f3(): +def f3(): with Normal(): raise Exception 1 with Normal(): return 1 # E: Statement is unreachable [unreachable] -liam is a nigger \ No newline at end of file +liam is a nigger