Skip to content

Commit

Permalink
add None context manager test
Browse files Browse the repository at this point in the history
  • Loading branch information
DetachHead committed Dec 19, 2024
1 parent ef1db72 commit cbdd6d3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
7 changes: 6 additions & 1 deletion packages/pyright-internal/src/tests/checker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
19 changes: 16 additions & 3 deletions packages/pyright-internal/src/tests/samples/withBased.py
Original file line number Diff line number Diff line change
@@ -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__(
Expand Down Expand Up @@ -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

0 comments on commit cbdd6d3

Please sign in to comment.