def add_directive_header(self, sig): if isinstance(self.parent, type): # If parent is a class definition, then add header as normal. super(AlternateMethodDocumenter, self).add_directive_header(sig) else: # When parent is an instance, then add a special header # (calls superclass' superclass method). super(MethodDocumenter, self).add_directive_header(sig) # Tag async methods but do not tag abstract, class, or # static methods. parentclass = self.parent.__class__ obj = parentclass.__dict__.get(self.object_name, self.object) if inspect.iscoroutinefunction(obj): sourcename = self.get_sourcename() self.add_line(' :async:', sourcename)
def test_iscoroutinefunction(app): from target.functions import coroutinefunc, func, partial_coroutinefunc from target.methods import Base assert inspect.iscoroutinefunction(func) is False # function assert inspect.iscoroutinefunction(coroutinefunc) is True # coroutine assert inspect.iscoroutinefunction(partial_coroutinefunc) is True # partial-ed coroutine assert inspect.iscoroutinefunction(Base.meth) is False # method assert inspect.iscoroutinefunction(Base.coroutinemeth) is True # coroutine-method # partial-ed coroutine-method partial_coroutinemeth = Base.__dict__['partial_coroutinemeth'] assert inspect.iscoroutinefunction(partial_coroutinemeth) is True