8000 FIX deprecated properties correctly wraps the property's docstring (#… · samronsin/scikit-learn@cad1277 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cad1277

Browse files
thomasjpfansamronsin
authored andcommitted
FIX deprecated properties correctly wraps the property's docstring (scikit-learn#20385)
1 parent 4ef8ca1 commit cad1277

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

doc/whats_new/v1.0.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,9 @@ Changelog
604604
precision of the computed variance was very poor when the real variance is
605605
exactly zero. :pr:`19766` by :user:`Jérémie du Boisberranger <jeremiedbb>`.
606606

607+
- |Fix| Propreties that are decorated with :func:`utils.deprecated` correctly
608+
wraps the property's docstring. :pr:`20385` by `Thomas Fan`_.
609+
607610
:mod:`sklearn.validation`
608611
.........................
609612

sklearn/utils/deprecation.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,13 @@ def _decorate_property(self, prop):
9898
msg = self.extra
9999

100100
@property
101+
@functools.wraps(prop)
101102
def wrapped(*args, **kwargs):
102103
warnings.warn(msg, category=FutureWarning)
103104
return prop.fget(*args, **kwargs)
104105

106+
wrapped.__doc__ = self._update_doc(wrapped.__doc__)
107+
105108
return wrapped
106109

107110
def _update_doc(self, olddoc):

sklearn/utils/tests/test_deprecation.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ class MockClass2:
1919
def method(self):
2020
pass
2121

22+
@deprecated("n_features_ is deprecated") # type: ignore
23+
@property
24+
def n_features_(self):
25+
"""Number of input features."""
26+
return 10
27+
2228

2329
class MockClass3:
2430
@deprecated()
@@ -55,3 +61,12 @@ def test_is_deprecated():
5561

5662
def test_pickle():
5763
pickle.loads(pickle.dumps(mock_function))
64+
65+
66+
def test_deprecated_property_docstring_exists():
67+
"""Deprecated property contains the original docstring."""
68+
mock_class_property = getattr(MockClass2, "n_features_")
69+
assert (
70+
"DEPRECATED: n_features_ is deprecated\n\n Number of input features."
71+
== mock_class_property.__doc__
72+
)

0 commit comments

Comments
 (0)
0