numpy / numpy/numpydoc

List a property as a class method

Open
#305 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
355
Forks
181
Avg merge
1d 9h
Merged PRs (30d)
3

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no repository file, test, or implementation entry point; begin by reproducing the linked scikit-learn generated documentation and tracing how numpydoc builds the methods table of contents. Done means establishing whether a documented property can appear in that methods TOC and covering the conditional-method case.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, scikit-learn
Domain
documentation
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.