numpy / numpy/numpydoc

FR: Add "Supported Signatures" Section to the NumPy Docstring Style Guide

Open
#430 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
355
Forks
181
Avg merge
1d 9h
Merged PRs (30d)
3

Description

Python doesn't natively support function overloading (like how C++ does), but imitates it with optional positional and keyword arguments. With the advent of the typing.overload decorator, we have the ability to express correlations between parameter and return types. C/C++ and Fortran methods ported to Python sometimes have function overloads that differ in arity and type. For polymorphic functions, it would be nice to have a section in the docstring describing the accepted signatures for a function.

A suggestion (dummy example) of what this might look like is:

from __future__ import annotations

from collections.abc import Sequence


def double(input_: int | Sequence[int]) -> int | list[int]:
    """Returns the input doubled.

    If the input is a sequence, returns the sequence
    with every item doubled. Otherwise, it returns
    the passed number doubled.

    Parameters
    ----------
    input_ : int or Sequence[int]
        The number (or number array) to be doubled

    Supported Signatures
    --------------------
    double( int ) -> int
    double( Sequence[int] ) -> list[int]

    Returns
    -------
    int or list[int]
        The input doubled if the input is a single ``int``,
        else the list with its elements doubled.
    """
    ...

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the NumPy docstring style guide and the existing section-handling documentation or tests in this repository. Compare the proposed “Supported Signatures” example with current conventions, then define completion as documented, consistently formatted support for the new section and coverage for the demonstrated signatures.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.