def create(cls, target_type: Type[Target], *,
            union_membership: UnionMembership) -> "TargetTypeHelpInfo":
     return cls(
         alias=target_type.alias,
         summary=get_docstring_summary(target_type),
         description=get_docstring(target_type),
         fields=tuple(
             TargetFieldHelpInfo.create(field)
             for field in target_type.class_field_types(
                 union_membership=union_membership)
             if not field.alias.startswith("_")
             and field.deprecated_removal_version is None),
     )
示例#2
0
 def create(
     cls, target_type: Type[Target], *, union_membership: UnionMembership
 ) -> TargetTypeHelpInfo:
     description: Optional[str]
     summary: Optional[str]
     if hasattr(target_type, "help"):
         description = target_type.help
         summary = first_paragraph(description)
     else:
         description = get_docstring(target_type)
         summary = get_docstring_summary(target_type)
     return cls(
         alias=target_type.alias,
         summary=summary,
         description=description,
         fields=tuple(
             TargetFieldHelpInfo.create(field)
             for field in target_type.class_field_types(union_membership=union_membership)
             if not field.alias.startswith("_") and field.deprecated_removal_version is None
         ),
     )
示例#3
0
 def get_description(cls) -> Optional[str]:
     return get_docstring_summary(cls)
示例#4
0
 def create(cls, target_type: Type[Target]) -> "AbbreviatedTargetInfo":
     return cls(alias=target_type.alias,
                description=get_docstring_summary(target_type))
示例#5
0
def test_get_docstring() -> None:
    class SingleLineDocstring:
        """Hello."""

    assert get_docstring_summary(SingleLineDocstring) == "Hello."
    assert get_docstring(SingleLineDocstring) == "Hello."
    assert get_docstring(SingleLineDocstring, flatten=True) == "Hello."

    class MultilineDocstring:
        """Hello.

        Extra description.
        """

    assert get_docstring_summary(MultilineDocstring) == "Hello."
    assert get_docstring(MultilineDocstring) == dedent("""\
        Hello.

        Extra description.""")
    assert get_docstring(MultilineDocstring,
                         flatten=True) == "Hello. Extra description."

    class NoDocstring:
        pass

    assert get_docstring_summary(NoDocstring) is None
    assert get_docstring(NoDocstring) is None
    assert get_docstring(NoDocstring, flatten=True) is None

    long_summary = (
        "This is all one sentence, it's just really really really long so it stretches to a "
        "whole new line.")

    class MultilineSummary:
        """This is all one sentence, it's just really really really long so it stretches to a whole
        new line."""

    assert get_docstring_summary(MultilineSummary) == long_summary
    assert get_docstring(MultilineSummary) == dedent("""\
        This is all one sentence, it's just really really really long so it stretches to a whole
        new line.""")
    assert get_docstring(MultilineSummary, flatten=True) == long_summary

    class MultilineSummaryWithDetails:
        """This is all one sentence, it's just really really really long so it stretches to a whole
        new line.

        We also have some extra detail.

            * l1
            * l2
        """

    assert get_docstring_summary(MultilineSummaryWithDetails) == long_summary
    assert get_docstring(MultilineSummaryWithDetails) == dedent("""\
        This is all one sentence, it's just really really really long so it stretches to a whole
        new line.

        We also have some extra detail.

            * l1
            * l2""")
    assert (get_docstring(MultilineSummaryWithDetails, flatten=True) ==
            f"{long_summary} We also have some extra detail. * l1 * l2")

    class SneakyDocstring:
        """Hello 😀!\n\nSneaky."""

    assert get_docstring_summary(SneakyDocstring) == "Hello 😀!"
    assert get_docstring(SneakyDocstring) == dedent("""\
        Hello 😀!

        Sneaky.""")
    assert get_docstring(SneakyDocstring,
                         flatten=True) == "Hello 😀! Sneaky."