Issue 36325: Build-out help() to support a class level data dictionary (original) (raw)

class Bicycle:

data_dictionary = dict( category = 'Primary use: road, cross-over, or hybrid', model = 'Unique six digit vendor-supplied code', size = 'Rider size: child, small, medium, large, extra-large', price = 'Manufacturer suggested retail price', )

help(Bicycle) class Bicycle(builtins.object) | Data fields defined here: | | category | Primary use: road, cross-over, or hybrid | | model | Unique six digit vendor-supplied code | | size | Rider size: child, small, medium, large, extra-large | | price | Manufacturer suggested retail price | | ---------------------------------------------------------------------- | | Data descriptors defined here: |
| dict | dictionary for instance variables (if defined) |
| weakref | list of weak references to the object (if defined) |
| ---------------------------------------------------------------------- | Data and other attributes defined here: |
| data_dictionary = {'category': 'Primary use: road, cross-over, or .

Something like this would be especially helpful for classes using slots.

The member objects show-up in help(), but there is no way to attach an explanation like we can with property objects.

So there is a slots only alternative that would only involve modifying help() and nothing else:

class Bicycle:

   __slots__ = dict(
       category = 'Primary use: road, cross-over, or hybrid',
       model = 'Unique six digit vendor-supplied code',
       size = 'Rider size: child, small, medium, large, extra-large',
       price = 'Manufacturer suggested retail price', 
   )