@@ -138,79 +138,30 @@ def protected_manager():
138138
139139
140140async def test_agen_protection ():
141- @_core .enable_ki_protection
142- async def agen_protected1 ():
143- assert _core .currently_ki_protected ()
144- try :
145- yield
146- finally :
147- assert _core .currently_ki_protected ()
148-
149- @_core .disable_ki_protection
150- async def agen_unprotected1 ():
151- assert not _core .currently_ki_protected ()
152- try :
153- yield
154- finally :
155- assert not _core .currently_ki_protected ()
156-
157- # Swap the order of the decorators:
158- @_core .enable_ki_protection
159- async def agen_protected2 ():
160- assert _core .currently_ki_protected ()
161- try :
162- yield
163- finally :
164- assert _core .currently_ki_protected ()
165-
166- @_core .disable_ki_protection
167- async def agen_unprotected2 ():
168- assert not _core .currently_ki_protected ()
169- try :
170- yield
171- finally :
172- assert not _core .currently_ki_protected ()
173-
174141 # Native async generators
175142 @_core .enable_ki_protection
176- async def agen_protected3 ():
143+ async def agen_protected ():
177144 assert _core .currently_ki_protected ()
178145 try :
179146 yield
180147 finally :
181148 assert _core .currently_ki_protected ()
182149
183150 @_core .disable_ki_protection
184- async def agen_unprotected3 ():
151+ async def agen_unprotected ():
185152 assert not _core .currently_ki_protected ()
186153 try :
187154 yield
188155 finally :
189156 assert not _core .currently_ki_protected ()
190157
191158 for agen_fn in [
192- agen_protected1 ,
193- agen_protected2 ,
194- agen_protected3 ,
195- agen_unprotected1 ,
196- agen_unprotected2 ,
197- agen_unprotected3 ,
159+ agen_protected ,
160+ agen_unprotected ,
198161 ]:
199162 async for _ in agen_fn (): # noqa
200163 assert not _core .currently_ki_protected ()
201164
202- # asynccontextmanager insists that the function passed must itself be an
203- # async gen function, not a wrapper around one
204- if isasyncgenfunction (agen_fn ):
205- async with contextlib .asynccontextmanager (agen_fn )():
206- assert not _core .currently_ki_protected ()
207-
208- # Another case that's tricky due to:
209- # https://bugs.python.org/issue29590
210- with pytest .raises (KeyError ):
211- async with contextlib .asynccontextmanager (agen_fn )():
212- raise KeyError
213-
214165
215166# Test the case where there's no magic local anywhere in the call stack
216167def test_ki_disabled_out_of_context ():
0 commit comments