bpo-44904: Fix classmethod property bug in doctest module #28838
Conversation
The doctest module raised an error if a docstring contained an example that attempted to access a classmethod property. (Stacking '@classmethod' on top of `@property` has been supported since Python 3.9; see https://docs.python.org/3/howto/descriptor.html#class-methods.)
Lib/doctest.py
Outdated
@@ -1037,7 +1037,9 @@ def _find(self, tests, obj, name, module, source_lines, globs, seen): | |||
if isinstance(val, staticmethod): | |||
val = getattr(obj, valname) | |||
if isinstance(val, classmethod): | |||
val = getattr(obj, valname).__func__ | |||
# Lookup via __dict__ instead of getattr |
This PR should not go forward until issue 45356 is resolved. Wrapping classmethod around property seems to have some intrinsic flaws that shouldn't be papered over.
Also, when replacing getattr with a dict lookup, we need to consider whether the entire __mro__
should be searched.
Lastly, any "solution" to this or the help() bug should probably share a standardized solution, perhaps some variant of hasattr() that doesn't have the __getattr__
hook and that doesn't trigger descriptor behavior.
This all makes sense. Thanks for taking a look, anyhow!
__mro__
is not related here. We iterate the class' __dict__
and look at methods defined in the class.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Lib/doctest.py
Outdated
@@ -1037,7 +1037,9 @@ def _find(self, tests, obj, name, module, source_lines, globs, seen): | |||
if isinstance(val, staticmethod): | |||
val = getattr(obj, valname) | |||
if isinstance(val, classmethod): | |||
val = getattr(obj, valname).__func__ | |||
# Lookup via __dict__ instead of getattr |
__mro__
is not related here. We iterate the class' __dict__
and look at methods defined in the class.
@rhettinger, I am going to merge this issue. Do you still have objections? |
The doctest module raised an error if a docstring contained an example that
attempted to access a classmethod property. (Stacking
@classmethod
on top of@property
has been supported since Python 3.9; seehttps://docs.python.org/3/howto/descriptor.html#class-methods.)
https://bugs.python.org/issue44904
The text was updated successfully, but these errors were encountered: