Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for class-level docstring #5

Closed
edmondchuc opened this issue Jul 28, 2022 · 2 comments
Closed

Add support for class-level docstring #5

edmondchuc opened this issue Jul 28, 2022 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@edmondchuc
Copy link

Hi! Awesome library.

Currently, stubdoc only supports adding docstring to functions and class methods.

if '.' not in callable_name:
stub_str = _add_doctring_to_target_function(
stub_str=stub_str,
function_name=callable_name,
module=module,
)
continue
stub_str = _add_docstring_to_class_method(
stub_str=stub_str,
method_name=callable_name,
module=module,
)

It would be great if it supported class-level docstrings as well as class getters and setters (@property).

Stub file with docstring generated by stubdoc:

class NamedNode:
    @property
    def value(self) -> str: ...
    def __init__(self, value: str) -> None:
        """
        Initialize self.  See help(type(self)) for accurate signature.
        """
    def __str__(self) -> str: ...
    def __repr__(self) -> str: ...
    def __hash__(self) -> int: ...
    def __eq__(self, other: Any) -> bool: ...
    def __ge__(self, other: Any) -> bool: ...
    def __gt__(self, other: Any) -> bool: ...
    def __le__(self, other: Any) -> bool: ...
    def __lt__(self, other: Any) -> bool: ...
    def __ne__(self, other: Any) -> bool: ...

Desired output:

class NamedNode:
    """An RDF `node identified by an IRI <https://www.w3.org/TR/rdf11-concepts/#dfn-iri>`_.

    :param value: the IRI as a string.
    :raises ValueError: if the IRI is not valid according to `RFC 3987 <https://tools.ietf.org/rfc/rfc3987>`_.

    The :py:func:`str` function provides a serialization compatible with N-Triples, Turtle, and SPARQL:

    >>> str(NamedNode('http://example.com'))
    '<http://example.com>'
    """
    @property
    def value(self) -> str:
        """the named node IRI.
        
        >>> NamedNode("http://example.com").value
        'http://example.com'
        """
    def __init__(self, value: str) -> None:
        """
        Initialize self.  See help(type(self)) for accurate signature.
        """
    def __str__(self) -> str: ...
    def __repr__(self) -> str: ...
    def __hash__(self) -> int: ...
    def __eq__(self, other: Any) -> bool: ...
    def __ge__(self, other: Any) -> bool: ...
    def __gt__(self, other: Any) -> bool: ...
    def __le__(self, other: Any) -> bool: ...
    def __lt__(self, other: Any) -> bool: ...
    def __ne__(self, other: Any) -> bool: ...
@simon-ritchie
Copy link
Owner

Hi @edmondchuc

Thanks for posting the nice proposal

Currently, I'm too busy and probably it takes a long time to support it
Please be patient to support its feature

P.S. If you favorite this project, please leave a star⭐️
It motivate me to support this proposal

@simon-ritchie
Copy link
Owner

I've released the v0.1.11 and probably supported these features!

https://github.com/simon-ritchie/stubdoc/releases/tag/0.1.11

$ pip install stubdoc==0.1.11

If you notice this version does not work correctly, please notify me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants