Skip to content
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

Added test and explanation for assigning __init__.__doc__ #515

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions equinox/_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 15 additions & 0 deletions tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
Loading