Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
from contextlib import contextmanager
import linecache
import os
+import inspect
from io import StringIO
import re
import sys
isinstance(cell.cell_contents, deprecated) for cell in d.__closure__
))
+ def test_inspect(self):
+ @deprecated("depr")
+ def sync():
+ pass
+
+ @deprecated("depr")
+ async def coro():
+ pass
+
+ class Cls:
+ @deprecated("depr")
+ def sync(self):
+ pass
+
+ @deprecated("depr")
+ async def coro(self):
+ pass
+
+ self.assertFalse(inspect.iscoroutinefunction(sync))
+ self.assertTrue(inspect.iscoroutinefunction(coro))
+ self.assertFalse(inspect.iscoroutinefunction(Cls.sync))
+ self.assertTrue(inspect.iscoroutinefunction(Cls.coro))
+
def setUpModule():
py_warnings.onceregistry.clear()
c_warnings.onceregistry.clear()
return arg
elif callable(arg):
import functools
+ import inspect
@functools.wraps(arg)
def wrapper(*args, **kwargs):
warn(msg, category=category, stacklevel=stacklevel + 1)
return arg(*args, **kwargs)
+ if inspect.iscoroutinefunction(arg):
+ wrapper = inspect.markcoroutinefunction(wrapper)
+
arg.__deprecated__ = wrapper.__deprecated__ = msg
return wrapper
else:
--- /dev/null
+:func:`@warnings.deprecated <warnings.deprecated>` now copies the
+coroutine status of functions and methods so that
+:func:`inspect.iscoroutinefunction` returns the correct result.