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

How to document properties parameters? #486

Open
sdiebolt opened this issue Aug 8, 2023 · 1 comment
Open

How to document properties parameters? #486

sdiebolt opened this issue Aug 8, 2023 · 1 comment

Comments

@sdiebolt
Copy link
Contributor

sdiebolt commented Aug 8, 2023

I'm wondering how to porperly document property getters and setters. Until now, I've been documenting everything in the getter, leaving the setter without docstring. That way, the generated HTML documentation shows the whole property documentation. However, I get a PR02: Unknown parameters warning on my getters since they have a Parameters section documenting the parameters of the setter. What am I doing wrong?

@timhoffm
Copy link
Contributor

timhoffm commented Sep 26, 2024

Why do you need a parameters section on properties at all? Properties are logically attributes, i.e. repesent one value that can be read or written. Docstrings are meant for the user and for them, properties appear attribute-like. The functions and their parameters are an implementation detail that's not relevant for the documentation.

I would suggest to document it like this:

class Rectangle:
    ...

    @property
    def width(self) -> float:
        """The width of the rectangle."""
        return self._width

    @width.setter
    def width(self, w: float) -> None:
        self._width = w

This is analogous to the attribute definition

class Rectangle:

    width : float
    """The width of the rectangle."""

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

2 participants