Exemple #1
0
 def get(self, ob, summary=False):
     if summary:
         return epydoc2stan.format_summary(ob)
     else:
         doc = epydoc2stan.format_docstring(ob)
         typ = epydoc2stan.type2stan(ob)
         if typ is None:
             return doc
         else:
             return [doc, ' (type: ', typ, ')']
Exemple #2
0
def moduleSummary(modorpack):
    r = tags.li(util.taglink(modorpack), ' - ',
                epydoc2stan.format_summary(modorpack))
    if not isinstance(modorpack, model.Package):
        return r
    contents = [
        m for m in modorpack.contents.values()
        if m.isVisible and m.name != '__init__'
    ]
    if not contents:
        return r
    ul = tags.ul()
    for m in sorted(contents, key=lambda m: m.fullName()):
        ul(moduleSummary(m))
    return r(ul)
Exemple #3
0
def subclassesFrom(hostsystem, cls, anchors):
    r = tags.li()
    name = cls.fullName()
    if name not in anchors:
        r(tags.a(name=name))
        anchors.add(name)
    r(util.taglink(cls), ' - ', epydoc2stan.format_summary(cls))
    scs = [
        sc for sc in cls.subclasses if sc.system is hostsystem
        and ' ' not in sc.fullName() and sc.isVisible
    ]
    if len(scs) > 0:
        ul = tags.ul()
        for sc in sorted(scs, key=_lckey):
            ul(subclassesFrom(hostsystem, sc, anchors))
        r(ul)
    return r
Exemple #4
0
def moduleSummary(module: model.Module, page_url: str) -> Tag:
    r: Tag = tags.li(
        tags.code(epydoc2stan.taglink(module, page_url)), ' - ',
        epydoc2stan.format_summary(module)
        )
    if module.isPrivate:
        r(class_='private')
    if not isinstance(module, model.Package):
        return r
    contents = [m for m in module.contents.values()
                if isinstance(m, model.Module) and m.isVisible]
    if not contents:
        return r
    ul = tags.ul()
    def fullName(obj: model.Documentable) -> str:
        return obj.fullName()
    for m in sorted(contents, key=fullName):
        ul(moduleSummary(m, page_url))
    r(ul)
    return r
Exemple #5
0
def test_property_decorator(systemcls: Type[model.System]) -> None:
    """A function decorated with '@property' is documented as an attribute."""
    mod = fromText('''
    class C:
        @property
        def prop(self) -> str:
            """For sale."""
            return 'seaside'
        @property
        def oldschool(self):
            """
            @return: For rent.
            @rtype: string
            @see: U{https://example.com/}
            """
            return 'downtown'
    ''',
                   modname='test',
                   systemcls=systemcls)
    C = mod.contents['C']

    prop = C.contents['prop']
    assert isinstance(prop, model.Attribute)
    assert prop.kind == 'Property'
    assert prop.docstring == """For sale."""
    assert type2str(prop.annotation) == 'str'

    oldschool = C.contents['oldschool']
    assert isinstance(oldschool, model.Attribute)
    assert oldschool.kind == 'Property'
    assert isinstance(oldschool.parsed_docstring, ParsedEpytextDocstring)
    assert unwrap(oldschool.parsed_docstring) == """For rent."""
    assert flatten(format_summary(oldschool)) == '<span>For rent.</span>'
    assert isinstance(oldschool.parsed_type, ParsedEpytextDocstring)
    assert str(unwrap(oldschool.parsed_type)) == 'string'
    fields = oldschool.parsed_docstring.fields
    assert len(fields) == 1
    assert fields[0].tag() == 'see'
Exemple #6
0
def subclassesFrom(
        hostsystem: model.System,
        cls: model.Class,
        anchors: MutableSet[str],
        page_url: str
        ) -> Tag:
    r: Tag = tags.li()
    if isClassNodePrivate(cls):
        r(class_='private')
    name = cls.fullName()
    if name not in anchors:
        r(tags.a(name=name))
        anchors.add(name)
    r(tags.code(epydoc2stan.taglink(cls, page_url)), ' - ',
      epydoc2stan.format_summary(cls))
    scs = [sc for sc in cls.subclasses if sc.system is hostsystem and ' ' not in sc.fullName()
           and sc.isVisible]
    if len(scs) > 0:
        ul = tags.ul()
        for sc in sorted(scs, key=_lckey):
            ul(subclassesFrom(hostsystem, sc, anchors, page_url))
        r(ul)
    return r
Exemple #7
0
 def get(self, ob: model.Documentable, summary: bool = False) -> Tag:
     if summary:
         return epydoc2stan.format_summary(ob)
     else:
         return epydoc2stan.format_docstring(ob)
Exemple #8
0
def summary2html(obj: model.Documentable) -> str:
    stan = epydoc2stan.format_summary(obj)
    assert stan.tagName == 'span', stan
    return flatten(stan.children)
Exemple #9
0
 def get_summary(func: str) -> str:
     stan = epydoc2stan.format_summary(mod.contents[func])
     assert stan.tagName == 'span', stan
     return flatten(stan.children)