0

Below is a sketch of a class I want to document. My first wish is to get short help from within Jupyter.

These help calls work as I expected:

help(thermo): showing everything (class, methods and properties)

help(thermo.select): showing the select help

help(thermo.table): showing the table help

Unfortunately, this one doesn't work as I would expect:

help(thermo.take) does not return the help from the take property.

Instead, this statement returns all the attributes from the take object. (2000+)

Could you clarify what happens, and suggest me how to get help(thermo.take) working as I would like?

Thanks

class substances(list, metaclass=substancesMeta):
    ''' A thermodynamic database of substances '''
    @property
    def take(self):
        ''' A simple way to take a substance. '''

    def select(self, ... ):
        ''' Select a subset of the database. '''

    def table(self, **kwargs):
        ''' Create a pandas dataframe from substances object '''
  • The problem lies in the fact that `take` is a property rather than a method of `substances`. – Daniel Oct 24 '17 at 15:57
  • *"how to get help(thermo.take) working as I would like"* - you can't. The point of the descriptor protocol is that the result of accessing `thermo.take` is whatever the getter returns. – jonrsharpe Oct 24 '17 at 16:00
  • Should I then add a metaclass to the Take class? (but I don't see right know how to take advantage of it) –  Oct 24 '17 at 19:43

1 Answers1

0

The point of properties is that thermo.take gets you the object returned by the getter (in this case, a Take object). That's why help(thermo.take) is equivalent to help(Take()) (or whatever your "take object" is).

You can bypass this behavior by calling help on the property of the class:

help(substances.take)
# Or
help(type(thermo).take)

This works because there's no self upon which you're calling take, so the only thing it has to return is your defined property.

scnerd
  • 5,836
  • 2
  • 21
  • 36