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 1b1174c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 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,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', () => {
Expand Down
15 changes: 15 additions & 0 deletions packages/pyright-internal/src/tests/samples/withBased.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1b1174c

Please sign in to comment.