You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Docstrings of deprecated attributes aren't rendered properly #13489
Function docstrings are handled such that the 'summary' of the function is whatever comes before the first period. For example with this method:
deffit(self, X, y=None):
"""Fit data X. This is another part that isn't rendered in the summary."""
...
The summary will be Fit data X., and the full docstring will be rendered in the detailed method description, as expected.
Now, deprecated attributes become properties, and properties are functions. What sphinx renders as the deprecated attribute docstring is its summary. So deprecating an attribute with
@property@deprecated("The foo parameter is deprecated. Use bar instead")deffoo(self):
returnself.bar
will only describe foo with The foo parameter is deprecated., that is, whatever comes before the first period.
This is related to #8113, i.e. fixing #8113 could probably fix this.
update the dev guide and make it clear that this order should be enforced
update all use of property(deprecated(...)) to reverse the order (there are only 3 instances, all for OneHotEncoder. You can use git grep -A1 property | grep deprecated -B1 to check).
You mean a test ensuring that every deprecated attribute uses the decorators in the correct order? Unfortunately I think it would be pretty hard since it would have to use e.g. the technique proposed in #8122 (comment)
That being said the worst case scenario is that the orderer is reversed, which is exactly where we are today. So it's not that critical.
wouldn't some grep magic be enough for that? I know it's not critical, it's just that it's not easy to remember and things again get where they are now over time.
I'm not a grep wizard so I'm not sure but in my experience, grep isn't meant to work well with multiple line matches, and it's going to be a pain to ensure that a sequence of @property and @deprecated is bound to the same def.
$ git grep -A 10 "@property" | awk '/@property/,/def /' | grep -B1 "@deprecated"
doc/developers/contributing.rst: @property
doc/developers/contributing.rst- @deprecated("Attribute labels_ was deprecated in version 0.13 and "
--
sklearn/preprocessing/_encoders.py: @property
sklearn/preprocessing/_encoders.py- @deprecated("The ``active_features_`` attribute was deprecated in version "
--
sklearn/preprocessing/_encoders.py: @property
sklearn/preprocessing/_encoders.py- @deprecated("The ``feature_indices_`` attribute was deprecated in version "
--
sklearn/preprocessing/_encoders.py: @property
sklearn/preprocessing/_encoders.py- @deprecated("The ``n_values_`` attribute was deprecated in version "
This may miss the potential cases where there are multiple decorators there, and @deprecated is not right after @property, but I'm not sure if that ever happens.
If not pytest, a command in the linter step of the CIs could do that maybe.
Activity
NicolasHug commentedon Mar 22, 2019
As noted here #8122 (comment), the fix should be easy as long as we enforce the convention that
@deprecatedshould be put on top of@property:This is because with this order, it is easy for the
depreacteddecorator to know whether it's decorating a classical method or a property.@jnothman , according to #8122 (comment), you seem to be OK with enforcing this. Is that still the case? Also ping @adrinjalali @qinhanmin2014 @thomasjpfan , in case one of you would not like this.
If you're all OK, I'll submit a PR that:
property(deprecated(...))to reverse the order (there are only 3 instances, all forOneHotEncoder. You can usegit grep -A1 property | grep deprecated -B1to check).Please let me know.
adrinjalali commentedon Mar 22, 2019
sounds good to me, any chance we could have a common test for it?
NicolasHug commentedon Mar 22, 2019
You mean a test ensuring that every deprecated attribute uses the decorators in the correct order? Unfortunately I think it would be pretty hard since it would have to use e.g. the technique proposed in #8122 (comment)
That being said the worst case scenario is that the orderer is reversed, which is exactly where we are today. So it's not that critical.
adrinjalali commentedon Mar 22, 2019
wouldn't some
grepmagic be enough for that? I know it's not critical, it's just that it's not easy to remember and things again get where they are now over time.adrinjalali commentedon Mar 22, 2019
What I mean is just to check that between a
@propertyand adef, there's no@deprecated.NicolasHug commentedon Mar 22, 2019
I'm not a grep wizard so I'm not sure but in my experience, grep isn't meant to work well with multiple line matches, and it's going to be a pain to ensure that a sequence of
@propertyand@deprecatedis bound to the samedef.adrinjalali commentedon Mar 22, 2019
I guess the output of this has to be empty?
As is the output of the following line right now:
Or is it missing anything? I'm certain a
perlcommand could also do it all, but this is what I could come up with.NicolasHug commentedon Mar 22, 2019
Or this
git grep -A1 "@property" | grep -B1 "@deprecated"But can we really write pytest tests that use git grep and grep?
adrinjalali commentedon Mar 22, 2019
This may miss the potential cases where there are multiple decorators there, and
@deprecatedis not right after@property, but I'm not sure if that ever happens.If not
pytest, a command in the linter step of the CIs could do that maybe.NicolasHug commentedon Mar 23, 2019
Got it, thanks for the feedback Adrin. Waiting for the others input now.
jnothman commentedon Mar 24, 2019