-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test for context managers that return
bool | None
, `False | Non…
…e` and `True | None`
- Loading branch information
1 parent
8934f7b
commit 9d59de6
Showing
3 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import contextlib | ||
from types import TracebackType | ||
from typing import Iterator, Literal | ||
|
||
from typing_extensions import assert_never | ||
|
||
class BoolOrNone(contextlib.AbstractContextManager[None]): | ||
def __exit__( | ||
self, | ||
__exc_type: type[BaseException] | None, | ||
__exc_value: BaseException | None, | ||
__traceback: TracebackType | None, | ||
) -> bool | None: | ||
... | ||
|
||
def _(): | ||
with BoolOrNone(): | ||
raise Exception | ||
print(1) # reachable | ||
|
||
class TrueOrNone(contextlib.AbstractContextManager[None]): | ||
def __exit__( | ||
self, | ||
__exc_type: type[BaseException] | None, | ||
__exc_value: BaseException | None, | ||
__traceback: TracebackType | None, | ||
) -> Literal[True] | None: | ||
... | ||
|
||
def _(): | ||
with TrueOrNone(): | ||
raise Exception | ||
print(1) # reachable | ||
|
||
|
||
class FalseOrNone(contextlib.AbstractContextManager[None]): | ||
def __exit__( | ||
self, | ||
__exc_type: type[BaseException] | None, | ||
__exc_value: BaseException | None, | ||
__traceback: TracebackType | None, | ||
) -> Literal[False] | None: | ||
... | ||
|
||
def _(): | ||
with FalseOrNone(): | ||
raise Exception | ||
print(1) # unreachable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters