diff --git a/equinox/_module.py b/equinox/_module.py index e5c48684..0ea4119f 100644 --- a/equinox/_module.py +++ b/equinox/_module.py @@ -212,7 +212,19 @@ def __new__(mcs, name, bases, dict_, /, strict: bool = False, **kwargs): # (This part has to happen after dataclass registration.) _has_dataclass_init[cls] = _init if _init: + # Assign `__doc__` in case its been manually overriden: + # ``` + # class Foo(eqx.Module): + # x: int + # + # Foo.__init__.__doc__ = "Foo should be called with with an integer `x`." + # + # class Bar(Foo): + # pass + # ``` + # With `Bar.__init__.__doc__` used during documentation generation. cls.__init__.__doc__ = init_doc # pyright: ignore + # TODO: is this next line still necessary? cls.__init__.__module__ = cls.__module__ # [Step 6] Check strict abstract modules. if strict: diff --git a/tests/test_module.py b/tests/test_module.py index 83f50360..38aff719 100644 --- a/tests/test_module.py +++ b/tests/test_module.py @@ -579,3 +579,18 @@ class C(B): B() C() assert not A.called + + +def test_inherit_doc(): + # This is not what dataclasses do by default -- they would set `B.__init__.__doc__` + # to `None` + + class A(eqx.Module): + pass + + A.__init__.__doc__ = "Hey there!" + + class B(A): + pass + + assert B.__init__.__doc__ == "Hey there!"