Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
bpo-19072: Make @classmethod support chained decorators#8405
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
Merged
rhettinger merged 6 commits into python:master from berkerpeksag:19072-classmethod-descriptorAug 24, 2019
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
6 commits Select commit Hold shift + click to select a range
1689459 bpo-19072: Make @classmethod support chained decorators
berkerpeksag 8402e69 add newline back
berkerpeksag 92b6650 Fix wording in NEWS entry
rhettinger a5ce586 Add documentation
rhettinger a013182 Merge branch 'master' into 19072-classmethod-descriptor
rhettinger 4d3e413 Fix markup
rhettinger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -183,6 +183,27 @@ def test_refleaks_in___init__(self): | ||
| fake_prop.__init__('fget', 'fset', 'fdel', 'doc') | ||
| self.assertAlmostEqual(gettotalrefcount() - refs_before, 0, delta=10) | ||
| @unittest.skipIf(sys.flags.optimize >= 2, | ||
| "Docstrings are omitted with -O2 and above") | ||
| def test_class_property(self): | ||
| class A: | ||
| @classmethod | ||
| @property | ||
| def __doc__(cls): | ||
rhettinger marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| return 'A doc for %r' % cls.__name__ | ||
| self.assertEqual(A.__doc__, "A doc for 'A'") | ||
| @unittest.skipIf(sys.flags.optimize >= 2, | ||
| "Docstrings are omitted with -O2 and above") | ||
| def test_class_property_override(self): | ||
| class A: | ||
| """First""" | ||
| @classmethod | ||
| @property | ||
| def __doc__(cls): | ||
| return 'Second' | ||
| self.assertEqual(A.__doc__, 'Second') | ||
| # Issue 5890: subclasses of property do not preserve method __doc__ strings | ||
| class PropertySub(property): | ||
3 changes: 3 additions & 0 deletions 3 Misc/NEWS.d/next/Core and Builtins/2018-07-23-13-09-54.bpo-19072.Gc59GS.rst
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| The :class:`classmethod` decorator can now wrap other descriptors | ||
| such as property objects. Adapted from a patch written by Graham | ||
| Dumpleton. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -741,6 +741,10 @@ cm_descr_get(PyObject *self, PyObject *obj, PyObject *type) | ||
| } | ||
| if (type == NULL) | ||
| type = (PyObject *)(Py_TYPE(obj)); | ||
| if (Py_TYPE(cm->cm_callable)->tp_descr_get != NULL){ | ||
rhettinger marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| return Py_TYPE(cm->cm_callable)->tp_descr_get(cm->cm_callable, type, | ||
| NULL); | ||
| } | ||
| return PyMethod_New(cm->cm_callable, type); | ||
| } | ||
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.
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.
Does sys.flags.optimize really affects this test?