Skip to content

Commit 710d3d2

Browse files
authored
fix(lib): allow DocTest to discover methods from subclasses of eqx.Module
Closes #1016. In the end, there were two issues: (1) `DocTestFinder._from_module` was returning `False` because the `__module__` attribute was not correct, and (2) the documentation was not copied to the wrapper class so doctests could not be discovered. My solution is inspired from what Python is doing with their own decorators, see https://github.com/python/cpython/blob/4617d68d73409e83d6ab31106d10421d44048787/Lib/functools.py#L1033-L1049
1 parent 76d697c commit 710d3d2

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

equinox/_module.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,15 @@ def __init__(self, method):
680680
self.method = method
681681
if getattr(self.method, "__isabstractmethod__", False):
682682
self.__isabstractmethod__ = self.method.__isabstractmethod__
683+
# Fixes https://github.com/patrick-kidger/equinox/issues/1016
684+
try:
685+
self.__module__ = self.method.__module__
686+
except AttributeError:
687+
pass
688+
try:
689+
self.__doc__ = self.method.__doc__
690+
except AttributeError:
691+
pass
683692

684693
def __get__(self, instance, owner):
685694
del owner

0 commit comments

Comments
 (0)