2

I have the following http client class

class MyClient:
  """Class docstring"""

  @overload
  def __init__(self, url): ...

  @overload
  def __init__(self, *, scheme, auth, host, port, path): ...

  def __init__(self, url=None, **kwargs): ...

and I'd like to generate the Sphinx documentation for the class's two signatures.

I can use py:class and write the two signatures by hand, but this solution requires me to copy the docstring violating DRY.

.. py:class:: MyClient(url)
              MyClient(*, scheme, auth, host, port, path)

    Class docstring

On the other hand, using autoclass will fetch the docstring automatically, but does not allow specifying multiple singatures.

.. autoclass:: MyClient

generates

class MyClient(url=None, **kwargs)
    Class docstring

Is there a way to write two signatures and insert class' docstring automatically at the same time?

mzjn
  • 48,958
  • 13
  • 128
  • 248
warownia1
  • 2,771
  • 1
  • 22
  • 30
  • Since noone seems to have a clue, an alternative would be to write `@classmethod`s instead of overloading `__init__`. e.g., keep the middle one and have a `from_url(cls, url=None, **kwargs)`. – Arne Mar 11 '20 at 07:50
  • 1
    See https://github.com/sphinx-doc/sphinx/issues/3610 – mzjn Mar 12 '20 at 10:54

0 Answers0