From 1b1174c7fe2b4ebc04df3d9d4109edb13c9de2c2 Mon Sep 17 00:00:00 2001 From: DetachHead Date: Sun, 25 Feb 2024 12:53:52 +1000 Subject: [PATCH] add `None` context manager test --- .../pyright-internal/src/tests/checker.test.ts | 5 ++++- .../src/tests/samples/withBased.py | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/pyright-internal/src/tests/checker.test.ts b/packages/pyright-internal/src/tests/checker.test.ts index 83a28b3a3e..d9a8dd3f60 100644 --- a/packages/pyright-internal/src/tests/checker.test.ts +++ b/packages/pyright-internal/src/tests/checker.test.ts @@ -172,7 +172,10 @@ test('With2', () => { test('context manager where __exit__ returns bool | None', () => { const analysisResults = TestUtils.typeAnalyzeSampleFiles(['withBased.py']); - TestUtils.validateResultsButBased(analysisResults, { unreachableCodes: [{ line: 47 }], unusedCodes: undefined }); + TestUtils.validateResultsButBased(analysisResults, { + unreachableCodes: [{ line: 47 }, { line: 62 }], + unusedCodes: undefined, + }); }); test('With3', () => { diff --git a/packages/pyright-internal/src/tests/samples/withBased.py b/packages/pyright-internal/src/tests/samples/withBased.py index 1ff09abbf0..282992e117 100644 --- a/packages/pyright-internal/src/tests/samples/withBased.py +++ b/packages/pyright-internal/src/tests/samples/withBased.py @@ -45,4 +45,19 @@ def __exit__( def _(): with FalseOrNone(): raise Exception + print(1) # unreachable + + +class OnlyNone(contextlib.AbstractContextManager[None]): + def __exit__( + self, + __exc_type: type[BaseException] | None, + __exc_value: BaseException | None, + __traceback: TracebackType | None, + ) -> None: + ... + +def _(): + with OnlyNone(): + raise Exception print(1) # unreachable \ No newline at end of file