Пример #1
0
        def docroutine(self,
                       object,
                       name=None,
                       mod=None,
                       funcs={},
                       classes={},
                       methods={},
                       cl=None):
            """Produce HTML documentation for a function or method object."""
            realname = object.__name__
            name = name or realname
            anchor = (cl and cl.__name__ or '') + '-' + name
            note = ''
            skipdocs = 0
            if _is_bound_method(object):
                imclass = object.__self__.__class__
                if cl:
                    if imclass is not cl:
                        note = ' from ' + self.classlink(imclass, mod)
                else:
                    if object.__self__ is not None:
                        note = ' method of %s instance' % self.classlink(
                            object.__self__.__class__, mod)
                    else:
                        note = ' unbound %s method' % self.classlink(
                            imclass, mod)

            if name == realname:
                title = '<span id="%s" class="signature">%s</span>' % (
                    anchor, realname)
            else:
                if (cl and realname in cl.__dict__
                        and cl.__dict__[realname] is object):
                    reallink = '<a href="#%s">%s</a>' % (cl.__name__ + '-' +
                                                         realname, realname)
                    skipdocs = 1
                else:
                    reallink = realname
                title = '<span id="%s" class="signature">%s</span> = %s' % (
                    anchor, name, reallink)
            argspec = None
            if inspect.isroutine(object):
                try:
                    signature = inspect.signature(object)
                except (ValueError, TypeError):
                    signature = None
                if signature:
                    argspec = str(signature)
                    if realname == '<lambda>':
                        title = '%s <em>lambda</em> ' % name
                        # XXX lambda's won't usually have
                        # func_annotations['return']
                        # since the syntax doesn't support but it is possible.
                        # So removing parentheses isn't truly safe.
                        argspec = argspec[1:-1]  # remove parentheses
            if not argspec:
                argspec = '(...)'

            decl = title + argspec + (note and self.grey(note))

            if skipdocs:
                return '<dl><dt>%s</dt><dd></dd></dl>\n' % decl
            else:
                doc = self.markup(getdoc(object), self.preformat, funcs,
                                  classes, methods)
                doc = doc and '<dd><code>%s</code></dd>' % doc
                return '<dl><dt>%s</dt><dd></dd>%s</dl>\n' % (decl, doc)
Пример #2
0
    def docroutine(self, object, name=None, mod=None, cl=None):
        """Produce text documentation for a function or method object."""
        realname = object.__name__
        name = name or realname
        note = ''
        skipdocs = 0
        if _is_bound_method(object):
            imclass = object.__self__.__class__
            if cl:
                if imclass is not cl:
                    note = ' from ' + classname(imclass, mod)
            else:
                if object.__self__ is not None:
                    note = ' method of %s instance' % classname(
                        object.__self__.__class__, mod)
                else:
                    note = ' unbound %s method' % classname(imclass, mod)

        if name == realname:
            title = self.bold(realname)
        else:
            if (cl and realname in cl.__dict__
                    and cl.__dict__[realname] is object):
                skipdocs = 1
            title = self.bold(name) + ' = ' + realname
        argspec = None

        if inspect.isroutine(object):
            try:
                signature = inspect.signature(object)
            except (ValueError, TypeError):
                signature = None
            if signature:
                argspec = str(signature)
                argspec = re.sub(', /\)', ')', argspec)
                argspec = re.sub(', /', '', argspec)
                if realname == '<lambda>':
                    title = self.bold(name) + ' lambda '
                    # XXX lambda's won't usually have func_annotations['return']
                    # since the syntax doesn't support but it is possible.
                    # So removing parentheses isn't truly safe.
                    argspec = argspec[1:-1]  # remove parentheses
        if argspec:
            dummyargs = False
        else:
            dummyargs = True
            argspec = '(*args, **kwargs)'
        decl = 'def ' + title + argspec + ':'
        if dummyargs:
            decl += '  # unknown args #'
        if note:
            decl += f'  # {note}'
        decl = decl.replace('#  #', '#')

        impl = 'raise NotImplementedError()'
        if skipdocs:
            return decl + '\n' + self.indent(impl) + '\n'
        else:
            doc = getdoc(object) or ''
            if doc:
                doc = f'"""\n{doc}\n"""'
            return decl + '\n' + self.indent((
                (doc + '\n') if doc else '') + impl).rstrip() + '\n'
Пример #3
0
 def update_event(self, inp=-1):
     self.set_output_val(0, pydoc._is_bound_method(self.input(0)))