7

I have a function with a long signature with type hint, like

def set_parameters(
        tokenizer: Union[None, "Tokenizer", str] = None,
        vocab: Optional["Vocab"] = None,
        vocab_from: Optional[Dict[str, str]] = None,
        max_sent_length: Optional[int] = None,
        max_turn_length: Optional[int] = None,
        convert_to_lower_letter: Optional[bool] = None,
        weak=False) -> "FieldContext":

I use Sphinx autodoc to generate docstring.

.. autofunction:: set_parameters

Then, Sphinx will ignore the line break and describe the function in one line.

set_parameters(tokenizer: Union[None, Tokenizer, str] = None, vocab: Optional[Vocab] = None, vocab_from: Optional[Dict[str, str]] = None, max_sent_length: Optional[int] = None,    max_turn_length: Optional[int] = None, convert_to_lower_letter: Optional[bool] = None, weak=False) -> FieldContext:

It's very ugly and hard to read. What I want is either it follows the line breaks in my code or do some line breaks itself automatically. Is there any way to realize?

mzjn
  • 48,958
  • 13
  • 128
  • 248
hzhwcmhf
  • 71
  • 2

1 Answers1

1

A quick and dirty option would be to use CSS:

dl.class > dt > em:before {
    content: ' ';
    display: block;
}

It's not perfect or pretty, but it at least puts the arguments into a list that is easier to visually scan.

Steve Piercy
  • 13,693
  • 1
  • 44
  • 57
  • Thanks, it works but not pretty. But you inspire me to do some tricks in html. – hzhwcmhf Feb 11 '20 at 11:24
  • 1
    See [this comment on the Sphinx issue tracker](https://github.com/sphinx-doc/sphinx/issues/1514#issuecomment-742703082) instead, which provides *substantially* prettier output. – Cecil Curry Feb 28 '23 at 08:57