fix(lib): allow DocTest to discover methods from subclasses Module#1018
Merged
patrick-kidger merged 2 commits intopatrick-kidger:mainfrom May 8, 2025
Merged
fix(lib): allow DocTest to discover methods from subclasses Module#1018patrick-kidger merged 2 commits intopatrick-kidger:mainfrom
Module#1018patrick-kidger merged 2 commits intopatrick-kidger:mainfrom
Conversation
equinox/_module.py
Outdated
Comment on lines
+683
to
+691
| # Fixes https://github.com/patrick-kidger/equinox/issues/1016 | ||
| try: | ||
| self.__module__ = self.method.__module__ | ||
| except AttributeError: | ||
| pass | ||
| try: | ||
| self.__doc__ = self.method.__doc__ | ||
| except AttributeError: | ||
| pass |
Owner
There was a problem hiding this comment.
Could each of these be @propertys instead?
Contributor
Author
There was a problem hiding this comment.
I guess it should, see below, you prefer this way?
>>> class Foo:
... def __init__(self):
... self.bar = 1
...
>>> class Baz:
... @property
... def bar(self):
... return 1
...
>>> hasattr(Foo(), "bar")
True
>>> hasattr(Baz(), "bar")
True
>>>
Contributor
Author
I'll try to implement some tests! |
…odule` Closes patrick-kidger#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
Contributor
Author
Done @patrick-kidger |
Owner
|
Awesome, this looks good to me --so merged! Thank you for the fix and for the contribution :) |
Contributor
Author
|
Thanks for your quick review and your awesome package! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1016.
In the end, there were two issues: (1)
DocTestFinder._from_modulewas returningFalsebecause 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