-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-44904: Fix classmethod property bug in doctest module #28838
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
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all makes sense. Thanks for taking a look, anyhow!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__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? |
Even if we will deprecate class properties in future, the changes of this PR make the code simpler and compatible with other decorators. |
Thanks @AlexWaygood for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10. |
GH-29261 is a backport of this pull request to the 3.10 branch. |
GH-29262 is a backport of this pull request to the 3.9 branch. |
…8838) 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.htmlGH-class-methods.) Co-authored-by: Serhiy Storchaka <[email protected]> (cherry picked from commit b1302ab) Co-authored-by: Alex Waygood <[email protected]>
…8838) 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.htmlGH-class-methods.) Co-authored-by: Serhiy Storchaka <[email protected]> (cherry picked from commit b1302ab) Co-authored-by: Alex Waygood <[email protected]>
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.htmlGH-class-methods.) Co-authored-by: Serhiy Storchaka <[email protected]> (cherry picked from commit b1302ab) Co-authored-by: Alex Waygood <[email protected]>
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.htmlGH-class-methods.) Co-authored-by: Serhiy Storchaka <[email protected]> (cherry picked from commit b1302ab) Co-authored-by: Alex Waygood <[email protected]>
|
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