1
- import contextlib
1
+ from contextlib import AbstractContextManager , contextmanager
2
2
from types import TracebackType
3
- from typing import Iterator , Literal
3
+ from typing import Iterator , Literal , Iterator
4
4
5
5
from typing_extensions import assert_never
6
6
7
- class BoolOrNone (contextlib . AbstractContextManager [None ]):
7
+ class BoolOrNone (AbstractContextManager [None ]):
8
8
def __exit__ (
9
9
self ,
10
10
__exc_type : type [BaseException ] | None ,
@@ -18,7 +18,7 @@ def _():
18
18
raise Exception
19
19
print (1 ) # reachable
20
20
21
- class TrueOrNone (contextlib . AbstractContextManager [None ]):
21
+ class TrueOrNone (AbstractContextManager [None ]):
22
22
def __exit__ (
23
23
self ,
24
24
__exc_type : type [BaseException ] | None ,
@@ -33,7 +33,7 @@ def _():
33
33
print (1 ) # reachable
34
34
35
35
36
- class FalseOrNone (contextlib . AbstractContextManager [None ]):
36
+ class FalseOrNone (AbstractContextManager [None ]):
37
37
def __exit__ (
38
38
self ,
39
39
__exc_type : type [BaseException ] | None ,
@@ -48,7 +48,7 @@ def _():
48
48
print (1 ) # unreachable
49
49
50
50
51
- class OnlyNone (contextlib . AbstractContextManager [None ]):
51
+ class OnlyNone (AbstractContextManager [None ]):
52
52
def __exit__ (
53
53
self ,
54
54
__exc_type : type [BaseException ] | None ,
@@ -60,4 +60,15 @@ def __exit__(
60
60
def _ ():
61
61
with OnlyNone ():
62
62
raise Exception
63
- print (1 ) # unreachable
63
+ print (1 ) # unreachable
64
+
65
+
66
+ @contextmanager
67
+ def foo () -> Iterator [None ]: ...
68
+
69
+
70
+ with foo ():
71
+ a = 1
72
+
73
+ # no reportPossiblyUnboundVariable since _GeneratorContextManager cannot suppress exceptions anymore as of python 3.7
74
+ print (a )
0 commit comments