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

Autofix for undocumented-public-function: insert docstring stub #14492

Open
sbrugman opened this issue Nov 20, 2024 · 2 comments
Open

Autofix for undocumented-public-function: insert docstring stub #14492

sbrugman opened this issue Nov 20, 2024 · 2 comments
Labels
docstring Related to docstring linting or formatting fixes Related to suggested fixes for violations

Comments

@sbrugman
Copy link
Contributor

sbrugman commented Nov 20, 2024

The undocumented-public-function rule currently has no autofix.
Writing documentation for functions can be made more effective by providing the documentation template automatically.
PyCharm allows to insert a "documentation string stub":

def func1(arg1: str, arg2: int) -> int:
    raise ValueError("Value not valid")

Proposed by PyCharm (depends on the docstring style configuration):

def func1(arg1: str, arg2: int) -> int:
    """

    Args:
        arg1: 
        arg2: 

    Returns:
        object: 
    """
    raise ValueError("Value not valid")

Would you accept a similar (unsafe) fix in ruff?

Ideally, the rule considers arguments, return values and exceptions.

def func1(arg1: str, arg2: int) -> int:
    """...

    Args:
        arg1: ...
        arg2: ...

    Returns:
        ... 

    Raises:
        ValueError: ...
    """
    raise ValueError("Value not valid")
@MichaReiser
Copy link
Member

MichaReiser commented Nov 20, 2024

This could make sense, but only with Applicabilty::DisplayOnly so that the fix needs to be applied manually because this is more an editor refactor than a "proper fix".

I'm not sure how the CLI or LSP handle display only fixes

@MichaReiser MichaReiser added the fixes Related to suggested fixes for violations label Nov 20, 2024
@sbrugman
Copy link
Contributor Author

For completeness:

Applying the fix will break down undocumented-public-function (D103) into multiple violations:

  • empty-docstring-section (D414): Section has no content ("Returns")
  • undocumented-param (D417): Missing argument descriptions in the docstring for func1
  • and various others related to the function summary/description D415, D212, D205

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docstring Related to docstring linting or formatting fixes Related to suggested fixes for violations
Projects
None yet
Development

No branches or pull requests

3 participants