コード例 #1
0
ファイル: __init__.py プロジェクト: zhangaigh/autodocsumm
 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
     if sphinx_version < [1, 7]:
         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)
     else:
         try:
             args = Signature(callmeth).format_args()
         except TypeError:
             return None
         else:
             args = args.replace('\\', '\\\\')
             return args
コード例 #2
0
 def process_signature(obj):
     try:
         argspec = getargspec(obj)
     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(obj, *argspec)
コード例 #3
0
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':
            module = inspect.getmodule(obj)
            clsname = obj.__qualname__.rsplit('.', 1)[0]
            cls = getattr(module, clsname)
            method_object = cls.__dict__[obj.__name__]
            if not isinstance(method_object, (classmethod, staticmethod)):
                del argspec.args[0]

    return formatargspec(obj, *argspec[:-1]), None
コード例 #4
0
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
コード例 #5
0
ファイル: extended_autodoc.py プロジェクト: Chilipp/psyplot
 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)
コード例 #6
0
ファイル: autodoc.py プロジェクト: revolter/invocations
 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))
コード例 #7
0
ファイル: autodoc.py プロジェクト: pyinvoke/invocations
 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))
コード例 #8
0
ファイル: conf.py プロジェクト: maxfischer2781/indico_sixpay
def wraplet_signature(app, what, name, obj, options, signature,
                      return_annotation):
    """have wrapplets use the signature of the slave"""
    try:
        wrapped = obj._raw_slave
    except AttributeError:
        return None
    else:
        slave_argspec = autodoc.getargspec(wrapped)
        slave_signature = autodoc.formatargspec(obj, *slave_argspec)
        return (slave_signature, return_annotation)
コード例 #9
0
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
コード例 #10
0
def process_signature(app, what: str, name: str, obj, options, signature, return_annotation):
    if callable(obj) and getattr(obj, '__annotations__', None):
        if what in ('class', 'exception'):
            obj = getattr(obj, '__init__')

        obj = unwrap(obj)
        try:
            argspec = getargspec(obj)
        except (TypeError, ValueError):
            return

        if what in ('method', 'class', 'exception') and argspec.args:
            del argspec.args[0]

        return formatargspec(obj, *argspec[:-1]), None
コード例 #11
0
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_name = obj.__name__
            if method_name.startswith("__") and not method_name.endswith("__"):
                # If the method starts with double underscore (dunder)
                # Python applies mangling so we need to prepend the class name.
                # This doesn't happen if it always ends with double underscore.
                class_name = obj.__qualname__.split('.')[-2]
                method_name = "_{c}{m}".format(c=class_name, m=method_name)

            method_object = outer.__dict__[method_name]
            if not isinstance(method_object, (classmethod, staticmethod)):
                del argspec.args[0]

    return formatargspec(obj, *argspec[:-1]), None
コード例 #12
0
ファイル: test_autodoc.py プロジェクト: atodorov/sphinx
 def verify_arg_spec(f, expected):
     assert formatargspec(f, *getargspec(f)) == expected
コード例 #13
0
 def verify_arg_spec(f, expected):
     assert formatargspec(f, *getargspec(f)) == expected
コード例 #14
0
ファイル: test_autodoc.py プロジェクト: xzflin/sphinx
 def verify_arg_spec(f, expected):
     eq_(formatargspec(f, *getargspec(f)), expected)
コード例 #15
0
ファイル: test_autodoc.py プロジェクト: agronholm/sphinx
 def verify_arg_spec(f, expected):
     eq_(formatargspec(f, *getargspec(f)), expected)