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

DOC: Doc inheritance #795

Closed
snowman2 opened this issue Mar 7, 2021 · 1 comment
Closed

DOC: Doc inheritance #795

snowman2 opened this issue Mar 7, 2021 · 1 comment

Comments

@snowman2
Copy link
Member

snowman2 commented Mar 7, 2021

if you want to limit the duplication of the docstrings (because now all the attributes/methods that needed to be added to dispatch to self._crs have a copy of the docstring), I think it should be relatively easy to use a decorator that automatically adds the docstring of the cython class.

Something like

def inherit_doc():
    """
    A decorator adding the docstring from the equivalent `_CRS` method.
    """

    def decorator(decorated):
        original_method = getattr(_CRS, decorated.__name__, None)
        if original_method:
            doc = original_method.__doc__ or ""
        else:
            doc = ""

        decorated.__doc__ = doc
        return decorated

    return decorator

Originally posted by @jorisvandenbossche in #793 (comment)

@snowman2
Copy link
Member Author

I have been thinking on this for a while. It definitely bothered me to have to copy over the docstrings from the cython _CRS class.

However, I think it is useful for developers to see the docstrings in the ,py file.

Current format:

    def to_json(self, pretty=False, indentation=2):
        """
        .. versionadded:: 2.4.0
        Convert the object to a JSON string.
        Parameters
        ----------
        pretty: bool
            If True, it will set the output to be a multiline string. Defaults to False.
        indentation: int
            If pretty is True, it will set the width of the indentation. Default is 2.
        Returns
        -------
        str
        """
        return self._crs.to_json(pretty=pretty, indentation=indentation)

Removing the docstrings:

    def to_json(self, pretty=False, indentation=2):
        return self._crs.to_json(pretty=pretty, indentation=indentation)

I am thinking I will leave it as is for the time being. I appreciate your suggestion @jorisvandenbossche as it was a nice solution that I thought would have been a good method to handle duplicate docstrings.

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

No branches or pull requests

1 participant