def process_signature(app, what: str, name: str, obj, options, signature, return_annotation): if not callable(obj): return if what in ('class', 'exception'): obj = getattr(obj, '__init__', getattr(obj, '__new__', None)) if not getattr(obj, '__annotations__', None): return obj = unwrap(obj) try: argspec = getargspec(obj) except (TypeError, ValueError): return if argspec.args: if what in ('class', 'exception'): del argspec.args[0] elif what == 'method': outer = inspect.getmodule(obj) for clsname in obj.__qualname__.split('.')[:-1]: outer = getattr(outer, clsname) method_object = outer.__dict__[obj.__name__] if not isinstance(method_object, (classmethod, staticmethod)): del argspec.args[0] try: result = formatargspec(obj, *argspec[:-1]), None except NameError: # This happens when the type annotation is conditionally imported with TYPE_CHECKING return return result
def format_args(self): # for classes, the relevant signature is the __init__ method's callmeth = self.get_attr(self.object, '__call__', None) if callmeth is None: return None try: argspec = getargspec(callmeth) except TypeError: # still not possible: happens e.g. for old-style classes # with __call__ in C return None if argspec[0] and argspec[0][0] in ('cls', 'self'): del argspec[0][0] if sphinx_version < [1, 4]: return formatargspec(*argspec) else: return formatargspec(callmeth, *argspec)
def format_args(self): function = self.object.body # TODO: consider extending (or adding a sibling to) Task.argspec so it # preserves more of the full argspec tuple. # TODO: whether to preserve the initial context argument is an open # question. For now, it will appear, but only pending invoke#170 - # after which point "call tasks as raw functions" may be less common. # TODO: also, it may become moot-ish if we turn this all into emission # of custom domain objects and/or make the CLI arguments the focus return autodoc.formatargspec(function, *getargspec(function))
def process_signature(app, what: str, name: str, obj, options, signature, return_annotation): if callable(obj): if what in ('class', 'exception'): obj = getattr(obj, '__init__') try: argspec = getargspec(obj) except TypeError: return if what in ('method', 'class', 'exception') and argspec.args: del argspec.args[0] return formatargspec(obj, *argspec[:-1]), None
def verify_arg_spec(f, expected): assert formatargspec(f, *getargspec(f)) == expected
def verify_arg_spec(f, expected): eq_(formatargspec(f, *getargspec(f)), expected)