From cbdd6d3e52b41277f2d51a6da61cacd3f6c0ac8d 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 --- .../src/tests/checker.test.ts | 7 ++++++- .../src/tests/samples/withBased.py | 19 ++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/packages/pyright-internal/src/tests/checker.test.ts b/packages/pyright-internal/src/tests/checker.test.ts index 83a28b3a3e..a227711d6f 100644 --- a/packages/pyright-internal/src/tests/checker.test.ts +++ b/packages/pyright-internal/src/tests/checker.test.ts @@ -172,7 +172,12 @@ 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, { + hints: [ + { code: DiagnosticRule.reportUnreachable, line: 45 }, + { code: DiagnosticRule.reportUnreachable, line: 60 }, + ], + }); }); test('With3', () => { diff --git a/packages/pyright-internal/src/tests/samples/withBased.py b/packages/pyright-internal/src/tests/samples/withBased.py index 1ff09abbf0..61dc2481d5 100644 --- a/packages/pyright-internal/src/tests/samples/withBased.py +++ b/packages/pyright-internal/src/tests/samples/withBased.py @@ -1,8 +1,6 @@ import contextlib from types import TracebackType -from typing import Iterator, Literal - -from typing_extensions import assert_never +from typing import Literal class BoolOrNone(contextlib.AbstractContextManager[None]): def __exit__( @@ -45,4 +43,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