Skip to content

Conversation

@rhkarls
Copy link
Contributor

@rhkarls rhkarls commented Mar 25, 2025

Description of Changes

  • Wrote at least one-line docstrings (for any new functions)
  • Added unit test(s) covering the changes (if testable)
  • Included a screenshot or animation (if affecting the UI, see Licecap)

The aim of this PR is to make the auto-generated docstrings pass numpydoc linting. Some changes also included for the Google and Sphinx docstring style. See #24040

Specifically, this PR:

How to deal with None return values is a bit unclear.
Currently, this PR has removed the return section if it only returns None.

Google style-guide: "If the function only returns None, this section is not required."
Numpydoc: not mentioned, but convention appears to be to omit the section: https://stackoverflow.com/a/66176351
Sphinx: unclear

An alternative, in the case of numpy, would be to produce something like this to pass numpydoc linting.

Returns
-------
None
	None.

Or keep the current behavior on master.

Once the changes to be included in this PR are agreed on I will deal with the tests.

Links and references:
Google docstring style: https://google.github.io/styleguide/pyguide.html#383-functions-and-methods
Sphinx docstring style: https://sphinx-rtd-tutorial.readthedocs.io/en/latest/docstrings.html#the-sphinx-docstring-format ,
Numpydoc: https://numpydoc.readthedocs.io/en/latest/format.html#sections

Additional note:
There are some inconsistencies in how the return section is generated, at least for numpy style, with multiple return values and depending on if the return value is type annotated or not.
These are however still valid docstrings as far as I can tell, so I consider this outside the scope of this PR.

Issue(s) Resolved

Fixes #24040 and #22043

Affirmation

By submitting this Pull Request or typing my (user)name below,
I affirm the Developer Certificate of Origin
with respect to all commits and content included in this PR,
and understand I am releasing the same under Spyder's MIT (Expat) license.

I certify the above statement is true and correct: @rhkarls

@rhkarls
Copy link
Contributor Author

rhkarls commented Mar 25, 2025

Examples of generated docstrings for the various styles with master and with this PR.

Numpy style

master
"""
Example file for numpydoc linting.
"""

def func_no_return_no_arg():
    """
    

    Returns
    -------
    None.

    """
    print("no args or returns")


def func_no_return_with_arg(x):
    """
    

    Parameters
    ----------
    x : TYPE
        DESCRIPTION.

    Returns
    -------
    None.

    """
    print("x")
    
def func_with_return_no_arg():
    """
    

    Returns
    -------
    bool
        DESCRIPTION.

    """
    
    return True


def func_with_return_args(x, y):
    """
    

    Parameters
    ----------
    x : TYPE
        DESCRIPTION.
    y : TYPE
        DESCRIPTION.

    Returns
    -------
    x : TYPE
        DESCRIPTION.

    """
    return x


def func_with_multiplte_return_vals(x, y):
    """
    

    Parameters
    ----------
    x : TYPE
        DESCRIPTION.
    y : TYPE
        DESCRIPTION.

    Returns
    -------
    x : TYPE
        DESCRIPTION.
    y : TYPE
        DESCRIPTION.

    """

    return x, y


def func_with_multiple_return_vals_type_ann(
    x: int, y: float, z: float = None
) -> tuple[float, float]:
    """
    

    Parameters
    ----------
    x : int
        DESCRIPTION.
    y : float
        DESCRIPTION.
    z : float, optional
        DESCRIPTION. The default is None.

    Returns
    -------
    tuple[float, float]
        DESCRIPTION.

    """

    return x, y


def func_raise_type_ann(x: int, y: float, z: float = None) -> float:
    """
    

    Parameters
    ----------
    x : int
        DESCRIPTION.
    y : float
        DESCRIPTION.
    z : float, optional
        DESCRIPTION. The default is None.

    Raises
    ------
    ValueError
        DESCRIPTION.

    Returns
    -------
    float
        DESCRIPTION.

    """
    try:
        return x / y
    except ZeroDivisionError as exc:
        raise ValueError(":( y cannot be zero") from exc
Output of numpydoc lint with master
numpydoc lint C:\Users\rhkarls\.spyder-py3-dev\temp_numpy.py --ignore ES01 SA01 EX01
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| file                          | item                                               | check   | description                                        |
+===============================+====================================================+=========+====================================================+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_no_return_no_arg                   | GL01    | Docstring text (summary) should start in the line  |
| py3-dev\temp_numpy.py:5       |                                                    |         | immediately after the opening quotes (not in the   |
|                               |                                                    |         | same line, or leaving a blank line in between)     |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_no_return_no_arg                   | GL02    | Closing quotes should be placed in the line after  |
| py3-dev\temp_numpy.py:5       |                                                    |         | the last text in the docstring (do not close the   |
|                               |                                                    |         | quotes in the same line as the text, or leave a    |
|                               |                                                    |         | blank line between the last text and the quotes)   |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_no_return_no_arg                   | GL03    | Double line break found; please use only one blank |
| py3-dev\temp_numpy.py:5       |                                                    |         | line to separate sections or paragraphs, and do    |
|                               |                                                    |         | not leave blank lines at the end of docstrings     |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_no_return_no_arg                   | SS01    | No summary found (a short summary in a single line |
| py3-dev\temp_numpy.py:5       |                                                    |         | should be present at the beginning of the          |
|                               |                                                    |         | docstring)                                         |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_no_return_no_arg                   | RT03    | Return value has no description                    |
| py3-dev\temp_numpy.py:5       |                                                    |         |                                                    |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_no_return_with_arg                 | GL01    | Docstring text (summary) should start in the line  |
| py3-dev\temp_numpy.py:17      |                                                    |         | immediately after the opening quotes (not in the   |
|                               |                                                    |         | same line, or leaving a blank line in between)     |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_no_return_with_arg                 | GL02    | Closing quotes should be placed in the line after  |
| py3-dev\temp_numpy.py:17      |                                                    |         | the last text in the docstring (do not close the   |
|                               |                                                    |         | quotes in the same line as the text, or leave a    |
|                               |                                                    |         | blank line between the last text and the quotes)   |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_no_return_with_arg                 | GL03    | Double line break found; please use only one blank |
| py3-dev\temp_numpy.py:17      |                                                    |         | line to separate sections or paragraphs, and do    |
|                               |                                                    |         | not leave blank lines at the end of docstrings     |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_no_return_with_arg                 | SS01    | No summary found (a short summary in a single line |
| py3-dev\temp_numpy.py:17      |                                                    |         | should be present at the beginning of the          |
|                               |                                                    |         | docstring)                                         |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_no_return_with_arg                 | RT03    | Return value has no description                    |
| py3-dev\temp_numpy.py:17      |                                                    |         |                                                    |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_with_return_no_arg                 | GL01    | Docstring text (summary) should start in the line  |
| py3-dev\temp_numpy.py:33      |                                                    |         | immediately after the opening quotes (not in the   |
|                               |                                                    |         | same line, or leaving a blank line in between)     |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_with_return_no_arg                 | GL02    | Closing quotes should be placed in the line after  |
| py3-dev\temp_numpy.py:33      |                                                    |         | the last text in the docstring (do not close the   |
|                               |                                                    |         | quotes in the same line as the text, or leave a    |
|                               |                                                    |         | blank line between the last text and the quotes)   |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_with_return_no_arg                 | GL03    | Double line break found; please use only one blank |
| py3-dev\temp_numpy.py:33      |                                                    |         | line to separate sections or paragraphs, and do    |
|                               |                                                    |         | not leave blank lines at the end of docstrings     |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_with_return_no_arg                 | SS01    | No summary found (a short summary in a single line |
| py3-dev\temp_numpy.py:33      |                                                    |         | should be present at the beginning of the          |
|                               |                                                    |         | docstring)                                         |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_with_return_args                   | GL01    | Docstring text (summary) should start in the line  |
| py3-dev\temp_numpy.py:47      |                                                    |         | immediately after the opening quotes (not in the   |
|                               |                                                    |         | same line, or leaving a blank line in between)     |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_with_return_args                   | GL02    | Closing quotes should be placed in the line after  |
| py3-dev\temp_numpy.py:47      |                                                    |         | the last text in the docstring (do not close the   |
|                               |                                                    |         | quotes in the same line as the text, or leave a    |
|                               |                                                    |         | blank line between the last text and the quotes)   |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_with_return_args                   | GL03    | Double line break found; please use only one blank |
| py3-dev\temp_numpy.py:47      |                                                    |         | line to separate sections or paragraphs, and do    |
|                               |                                                    |         | not leave blank lines at the end of docstrings     |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_with_return_args                   | SS01    | No summary found (a short summary in a single line |
| py3-dev\temp_numpy.py:47      |                                                    |         | should be present at the beginning of the          |
|                               |                                                    |         | docstring)                                         |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_with_return_args                   | RT02    | The first line of the Returns section should       |
| py3-dev\temp_numpy.py:47      |                                                    |         | contain only the type, unless multiple values are  |
|                               |                                                    |         | being returned                                     |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_with_multiplte_return_vals         | GL01    | Docstring text (summary) should start in the line  |
| py3-dev\temp_numpy.py:67      |                                                    |         | immediately after the opening quotes (not in the   |
|                               |                                                    |         | same line, or leaving a blank line in between)     |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_with_multiplte_return_vals         | GL02    | Closing quotes should be placed in the line after  |
| py3-dev\temp_numpy.py:67      |                                                    |         | the last text in the docstring (do not close the   |
|                               |                                                    |         | quotes in the same line as the text, or leave a    |
|                               |                                                    |         | blank line between the last text and the quotes)   |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_with_multiplte_return_vals         | GL03    | Double line break found; please use only one blank |
| py3-dev\temp_numpy.py:67      |                                                    |         | line to separate sections or paragraphs, and do    |
|                               |                                                    |         | not leave blank lines at the end of docstrings     |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_with_multiplte_return_vals         | SS01    | No summary found (a short summary in a single line |
| py3-dev\temp_numpy.py:67      |                                                    |         | should be present at the beginning of the          |
|                               |                                                    |         | docstring)                                         |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_with_multiple_return_vals_type_ann | GL01    | Docstring text (summary) should start in the line  |
| py3-dev\temp_numpy.py:90      |                                                    |         | immediately after the opening quotes (not in the   |
|                               |                                                    |         | same line, or leaving a blank line in between)     |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_with_multiple_return_vals_type_ann | GL02    | Closing quotes should be placed in the line after  |
| py3-dev\temp_numpy.py:90      |                                                    |         | the last text in the docstring (do not close the   |
|                               |                                                    |         | quotes in the same line as the text, or leave a    |
|                               |                                                    |         | blank line between the last text and the quotes)   |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_with_multiple_return_vals_type_ann | GL03    | Double line break found; please use only one blank |
| py3-dev\temp_numpy.py:90      |                                                    |         | line to separate sections or paragraphs, and do    |
|                               |                                                    |         | not leave blank lines at the end of docstrings     |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_with_multiple_return_vals_type_ann | SS01    | No summary found (a short summary in a single line |
| py3-dev\temp_numpy.py:90      |                                                    |         | should be present at the beginning of the          |
|                               |                                                    |         | docstring)                                         |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_raise_type_ann                     | GL01    | Docstring text (summary) should start in the line  |
| py3-dev\temp_numpy.py:115     |                                                    |         | immediately after the opening quotes (not in the   |
|                               |                                                    |         | same line, or leaving a blank line in between)     |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_raise_type_ann                     | GL02    | Closing quotes should be placed in the line after  |
| py3-dev\temp_numpy.py:115     |                                                    |         | the last text in the docstring (do not close the   |
|                               |                                                    |         | quotes in the same line as the text, or leave a    |
|                               |                                                    |         | blank line between the last text and the quotes)   |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_raise_type_ann                     | GL03    | Double line break found; please use only one blank |
| py3-dev\temp_numpy.py:115     |                                                    |         | line to separate sections or paragraphs, and do    |
|                               |                                                    |         | not leave blank lines at the end of docstrings     |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_raise_type_ann                     | GL07    | Sections are in the wrong order. Correct order is: |
| py3-dev\temp_numpy.py:115     |                                                    |         | Parameters, Returns, Raises                        |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
| C:\Users\rhkarls\.spyder-     | temp_numpy.func_raise_type_ann                     | SS01    | No summary found (a short summary in a single line |
| py3-dev\temp_numpy.py:115     |                                                    |         | should be present at the beginning of the          |
|                               |                                                    |         | docstring)                                         |
+-------------------------------+----------------------------------------------------+---------+----------------------------------------------------+
this PR
"""
Example file for numpydoc linting.
"""

def func_no_return_no_arg():
    """
    SUMMARY.
    """
    print("no args or returns")


def func_no_return_with_arg(x):
    """
    SUMMARY.

    Parameters
    ----------
    x : TYPE
        DESCRIPTION.
    """
    print("x")
    
def func_with_return_no_arg():
    """
    SUMMARY.

    Returns
    -------
    bool
        DESCRIPTION.
    """
    
    return True


def func_with_return_args(x, y):
    """
    SUMMARY.

    Parameters
    ----------
    x : TYPE
        DESCRIPTION.
    y : TYPE
        DESCRIPTION.

    Returns
    -------
    TYPE
        DESCRIPTION.
    """
    return x


def func_with_multiplte_return_vals(x, y):
    """
    SUMMARY.

    Parameters
    ----------
    x : TYPE
        DESCRIPTION.
    y : TYPE
        DESCRIPTION.

    Returns
    -------
    x : TYPE
        DESCRIPTION.
    y : TYPE
        DESCRIPTION.
    """

    return x, y


def func_with_multiple_return_vals_type_ann(
    x: int, y: float, z: float = None
) -> tuple[float, float]:
    """
    SUMMARY.

    Parameters
    ----------
    x : int
        DESCRIPTION.
    y : float
        DESCRIPTION.
    z : float, optional
        DESCRIPTION. The default is None.

    Returns
    -------
    tuple[float, float]
        DESCRIPTION.
    """

    return x, y


def func_raise_type_ann(x: int, y: float, z: float = None) -> float:
    """
    SUMMARY.

    Parameters
    ----------
    x : int
        DESCRIPTION.
    y : float
        DESCRIPTION.
    z : float, optional
        DESCRIPTION. The default is None.

    Returns
    -------
    float
        DESCRIPTION.

    Raises
    ------
    ValueError
        DESCRIPTION.
    """
    try:
        return x / y
    except ZeroDivisionError as exc:
        raise ValueError(":( y cannot be zero") from exc

This passes numpydoc linting with numpydoc lint file_numpy.py --ignore ES01 SA01 EX01

Google style

master
def func_no_return_no_arg():
    """
    

    Returns:
        None.

    """
    print("no args or returns")


def func_no_return_with_arg(x):
    """
    

    Args:
        x (TYPE): DESCRIPTION.

    Returns:
        None.

    """
    print("x")
    
def func_with_return_no_arg():
    """
    

    Returns:
        bool: DESCRIPTION.

    """
    
    return True


def func_with_return_args(x, y):
    """
    

    Args:
        x (TYPE): DESCRIPTION.
        y (TYPE): DESCRIPTION.

    Returns:
        TYPE: DESCRIPTION.

    """

    return x + y


def func_with_multiplte_return_vals(x, y):
    """
    

    Args:
        x (TYPE): DESCRIPTION.
        y (TYPE): DESCRIPTION.

    Returns:
        x (TYPE): DESCRIPTION.
        y (TYPE): DESCRIPTION.

    """

    return x, y


def func_with_multiple_return_vals_type_ann(
    x: int, y: float, z: float = None
) -> tuple[float, float]:
    """
    

    Args:
        x (int): DESCRIPTION.
        y (float): DESCRIPTION.
        z (float, optional): DESCRIPTION. Defaults to None.

    Returns:
        tuple[float, float]: DESCRIPTION.

    """
    return x, y


def func_raise_type_ann(x: int, y: float, z: float = None) -> float:
    """
    

    Args:
        x (int): DESCRIPTION.
        y (float): DESCRIPTION.
        z (float, optional): DESCRIPTION. Defaults to None.

    Raises:
        ValueError: DESCRIPTION.

    Returns:
        float: DESCRIPTION.

    """
    try:
        return x / y
    except ZeroDivisionError as exc:
        raise ValueError(":( y cannot be zero") from exc
this PR
def func_no_return_no_arg():
    """SUMMARY.
    """
    print("no args or returns")


def func_no_return_with_arg(x):
    """SUMMARY.

    Args:
        x (TYPE): DESCRIPTION.
    """
    print("x")
    
def func_with_return_no_arg():
    """SUMMARY.

    Returns:
        bool: DESCRIPTION.
    """
    
    return True


def func_with_return_args(x, y):
    """SUMMARY.

    Args:
        x (TYPE): DESCRIPTION.
        y (TYPE): DESCRIPTION.

    Returns:
        TYPE: DESCRIPTION.
    """

    return x + y


def func_with_multiplte_return_vals(x, y):
    """SUMMARY.

    Args:
        x (TYPE): DESCRIPTION.
        y (TYPE): DESCRIPTION.

    Returns:
        x (TYPE): DESCRIPTION.
        y (TYPE): DESCRIPTION.
    """

    return x, y


def func_with_multiple_return_vals_type_ann(
    x: int, y: float, z: float = None
) -> tuple[float, float]:
    """SUMMARY.

    Args:
        x (int): DESCRIPTION.
        y (float): DESCRIPTION.
        z (float, optional): DESCRIPTION. Defaults to None.

    Returns:
        tuple[float, float]: DESCRIPTION.
    """
    return x, y


def func_raise_type_ann(x: int, y: float, z: float = None) -> float:
    """SUMMARY.

    Args:
        x (int): DESCRIPTION.
        y (float): DESCRIPTION.
        z (float, optional): DESCRIPTION. Defaults to None.

    Returns:
        float: DESCRIPTION.

    Raises:
        ValueError: DESCRIPTION.
    """
    try:
        return x / y
    except ZeroDivisionError as exc:
        raise ValueError(":( y cannot be zero") from exc

Sphinx style

master
def func_no_return_no_arg():
    """
    
    :return: DESCRIPTION
    :rtype: TYPE

    """
    print("no args or returns")


def func_no_return_with_arg(x):
    """
    
    :param x: DESCRIPTION
    :type x: TYPE
    :return: DESCRIPTION
    :rtype: TYPE

    """
    print("x")
    
def func_with_return_no_arg():
    """
    
    :return: DESCRIPTION
    :rtype: TYPE

    """
    
    return True


def func_with_return_args(x, y):
    """
    
    :param x: DESCRIPTION
    :type x: TYPE
    :param y: DESCRIPTION
    :type y: TYPE
    :return: DESCRIPTION
    :rtype: TYPE

    """

    return x + y


def func_with_multiplte_return_vals(x, y):
    """
    
    :param x: DESCRIPTION
    :type x: TYPE
    :param y: DESCRIPTION
    :type y: TYPE
    :return: DESCRIPTION
    :rtype: TYPE

    """

    return x, y


def func_with_multiple_return_vals_type_ann(
    x: int, y: float, z: float = None
) -> tuple[float, float]:
    """
    
    :param x: DESCRIPTION
    :type x: int
    :param y: DESCRIPTION
    :type y: float
    :param z: DESCRIPTION, defaults to None
    :type z: float, optional
    :return: DESCRIPTION
    :rtype: tuple[float, float]

    """

    return x, y


def func_raise_type_ann(x: int, y: float, z: float = None) -> float:
    """
    
    :param x: DESCRIPTION
    :type x: int
    :param y: DESCRIPTION
    :type y: float
    :param z: DESCRIPTION, defaults to None
    :type z: float, optional
    :raises ValueError: DESCRIPTION
    :return: DESCRIPTION
    :rtype: float

    """
    try:
        return x / y
    except ZeroDivisionError as exc:
        raise ValueError(":( y cannot be zero") from exc
this PR
def func_no_return_no_arg():
    """SUMMARY.
    """
    print("no args or returns")


def func_no_return_with_arg(x):
    """SUMMARY.

    :param x: DESCRIPTION
    :type x: TYPE
    """
    print("x")
    
def func_with_return_no_arg():
    """SUMMARY.

    :return: DESCRIPTION
    :rtype: TYPE
    """
    
    return True


def func_with_return_args(x, y):
    """SUMMARY.

    :param x: DESCRIPTION
    :type x: TYPE
    :param y: DESCRIPTION
    :type y: TYPE
    :return: DESCRIPTION
    :rtype: TYPE
    """

    return x + y


def func_with_multiplte_return_vals(x, y):
    """SUMMARY.

    :param x: DESCRIPTION
    :type x: TYPE
    :param y: DESCRIPTION
    :type y: TYPE
    :return: DESCRIPTION
    :rtype: TYPE
    """

    return x, y


def func_with_multiple_return_vals_type_ann(
    x: int, y: float, z: float = None
) -> tuple[float, float]:
    """SUMMARY.

    :param x: DESCRIPTION
    :type x: int
    :param y: DESCRIPTION
    :type y: float
    :param z: DESCRIPTION, defaults to None
    :type z: float, optional
    :return: DESCRIPTION
    :rtype: tuple[float, float]
    """

    return x, y


def func_raise_type_ann(x: int, y: float, z: float = None) -> float:
    """SUMMARY.

    :param x: DESCRIPTION
    :type x: int
    :param y: DESCRIPTION
    :type y: float
    :param z: DESCRIPTION, defaults to None
    :type z: float, optional
    :raises ValueError: DESCRIPTION
    :return: DESCRIPTION
    :rtype: float
    """
    try:
        return x / y
    except ZeroDivisionError as exc:
        raise ValueError(":( y cannot be zero") from exc

@rhkarls rhkarls changed the title PR: formatting of generated docstrings according to style-guides [WIP] PR: formatting of generated docstrings according to style-guides Jun 12, 2025
@rhkarls
Copy link
Contributor Author

rhkarls commented Jun 12, 2025

@ccordoba12 I understand fully this is not a prioritized issue ahead of 6.1 - just checking if there is an interest in including the PR some time in the future - if so then I can fix the tests when I have a free moment

@CAM-Gerlach
Copy link
Member

CAM-Gerlach commented Jan 13, 2026

Hey @rhkarls , thanks for all your work here and sorry no one responded to you until now! These are pretty much all good improvements, a number of which had really annoyed me too (which I only have myself to blame for, haha, as I co-developed and reviewed this functionality with a contributor many years ago) and was starting to work on finally fixing them myself before I found this PR.

In particular, I was using Spyder's docstring generation to expand Spyder's own docstrings (see e.g. #25512 for one example) , but was wasting loads of time manually fixing loads of style issues (many fixed here), dealing with lots of bugs and edge cases (e.g. it wouldn't work for Black-format docstrings) and having to manually integrate the existing docstrings with the new generated ones. As such, to speed up that work I was starting to make some changes in Spyder myself when I came across this PR, so it seemed prudent to rebase this on top of the latest master, rebase my own work on top of this, and then make the additional fixes and improvements on top of that.

See #25558 for the result, which incorporates your main commit verbatim (though not quite the return None change as you have it; see there for more details but that could be added in a followup PR as an optional setting). I hope you don't mind; since I didn't want to invalidate your existing PR but we needed this for Spyder's own docstrings. Thanks again for your work here and you are more than welcome to review and test that PR; happy to hear any feedback!

@rhkarls
Copy link
Contributor Author

rhkarls commented Jan 17, 2026

Thanks for the ping @CAM-Gerlach, I appreciate it! And #25558 looks great, and I can see that a much more extensive overhaul is the way to go - looking forward to seeing that PR merged, its a really great feature of Spyder!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generated docstrings do not follow style-guides and do not pass linting (numpydoc) Option for docstring to not add empty lines and indentation at end

2 participants