Skip to content

Support word wrapping for types #11403

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

Open
ooliver1 opened this issue May 5, 2023 · 1 comment
Open

Support word wrapping for types #11403

ooliver1 opened this issue May 5, 2023 · 1 comment

Comments

@ooliver1
Copy link

ooliver1 commented May 5, 2023

Is your feature request related to a problem? Please describe.
This request is to support word wrapping in types for parameters/attributes/...

Describe the solution you'd like

    """...

    Parameters
    ----------
    choices: Union[Dict[:class:`str`, Union[:class:`str`, :class:`int`, :class:`float`]],
             Iterable[Union[:class:`str`, :class:`int`, :class:`float`]]]
        A list of choices that a user must choose.

   ...
   """

Describe alternatives you've considered
I am aware type aliases are possible, but sometimes it is not worth making a whole alias for one type.

Additional context
image
This is the current result, a - in the middle where the wrap took place.

@picnixz
Copy link
Member

picnixz commented May 22, 2023

Currently, it does not work for Google docstrings, but for reST docstrings, you can use a backslash \ and the r prefix.

def foo(choices):
    r"""...

    :param choices: whatever
    :type choices: Union[Dict[:class:`str`, Union[:class:`str`, :class:`int`, :class:`float`]], \
        Iterable[Union[:class:`str`, :class:`int`, :class:`float`]]]
   """

Unfortunately, the type will still be rendered on a single line which may then become quite long. Instead, I would suggest using a type annotation and from __future__ import annotations directly because:

  1. you can use shorter Python syntax like dict[str, str | int] directly.
  2. the references are usually well found unless they are guarded by a if TYPE_CHECKING block. In there are imports there, I don't think they will be all found (especially if there are aliases).

@AA-Turner AA-Turner added this to the some future version milestone Aug 11, 2023
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

3 participants