bpo-36933: Remove sys.set_coroutine_wrapper (marked for removal in 3.8) (GH-13577)

It has been documented as deprecated and to be removed in 3.8; 

From a comment on another thread – which I can't find ; leave get_coro_wrapper() for now, but always return `None`.


https://bugs.python.org/issue36933
This commit is contained in:
Matthias Bussonnier 2019-05-28 00:10:59 -07:00 committed by Miss Islington (bot)
parent 436c2b0d67
commit 3880f263d2
11 changed files with 7 additions and 287 deletions

View file

@ -2146,99 +2146,6 @@ class CoroAsyncIOCompatTest(unittest.TestCase):
self.assertEqual(buffer, [1, 2, 'MyException'])
class SysSetCoroWrapperTest(unittest.TestCase):
def test_set_wrapper_1(self):
async def foo():
return 'spam'
wrapped = None
def wrap(gen):
nonlocal wrapped
wrapped = gen
return gen
with self.assertWarns(DeprecationWarning):
self.assertIsNone(sys.get_coroutine_wrapper())
with self.assertWarns(DeprecationWarning):
sys.set_coroutine_wrapper(wrap)
with self.assertWarns(DeprecationWarning):
self.assertIs(sys.get_coroutine_wrapper(), wrap)
try:
f = foo()
self.assertTrue(wrapped)
self.assertEqual(run_async(f), ([], 'spam'))
finally:
with self.assertWarns(DeprecationWarning):
sys.set_coroutine_wrapper(None)
f.close()
with self.assertWarns(DeprecationWarning):
self.assertIsNone(sys.get_coroutine_wrapper())
wrapped = None
coro = foo()
self.assertFalse(wrapped)
coro.close()
def test_set_wrapper_2(self):
with self.assertWarns(DeprecationWarning):
self.assertIsNone(sys.get_coroutine_wrapper())
with self.assertRaisesRegex(TypeError, "callable expected, got int"):
with self.assertWarns(DeprecationWarning):
sys.set_coroutine_wrapper(1)
with self.assertWarns(DeprecationWarning):
self.assertIsNone(sys.get_coroutine_wrapper())
def test_set_wrapper_3(self):
async def foo():
return 'spam'
def wrapper(coro):
async def wrap(coro):
return await coro
return wrap(coro)
with self.assertWarns(DeprecationWarning):
sys.set_coroutine_wrapper(wrapper)
try:
with silence_coro_gc(), self.assertRaisesRegex(
RuntimeError,
r"coroutine wrapper.*\.wrapper at 0x.*attempted to "
r"recursively wrap .* wrap .*"):
foo()
finally:
with self.assertWarns(DeprecationWarning):
sys.set_coroutine_wrapper(None)
def test_set_wrapper_4(self):
@types.coroutine
def foo():
return 'spam'
wrapped = None
def wrap(gen):
nonlocal wrapped
wrapped = gen
return gen
with self.assertWarns(DeprecationWarning):
sys.set_coroutine_wrapper(wrap)
try:
foo()
self.assertIs(
wrapped, None,
"generator-based coroutine was wrapped via "
"sys.set_coroutine_wrapper")
finally:
with self.assertWarns(DeprecationWarning):
sys.set_coroutine_wrapper(None)
class OriginTrackingTest(unittest.TestCase):
def here(self):
info = inspect.getframeinfo(inspect.currentframe().f_back)