numpydoc icon indicating copy to clipboard operation
numpydoc copied to clipboard

List a property as a class method

Open glemaitre opened this issue 3 years ago • 0 comments

In scikit-learn, we have the following use-case.

We want a class method (e.g. predict_proba) to only be defined under some condition meaning that hasattr(instance, "class_method") should return False or True depending of some internal class attributes. The trick used to get this behaviour is to implement this class method as a property where we can implement a checking mechanism which can raise an AttributeError allowing to use hasattr.

With this hack, the property is not listed in the summary of the methods: https://scikit-learn.org/dev/modules/generated/sklearn.linear_model.SGDClassifier.html#sklearn.linear_model.SGDClassifier We still get the property documented with the other methods thought.

I was wondering if there is any mechanism such that we could get this property shown in the methods toc?

glemaitre avatar Nov 09 '20 14:11 glemaitre