[New-bugs-announce] [issue36326] Build-out help() to read __slots__ with an optional data dictionary

Raymond Hettinger report at bugs.python.org
Sun Mar 17 06:11:16 EDT 2019


New submission from Raymond Hettinger <raymond.hettinger at gmail.com>:

The __slots__ variable already works with dictionaries.  The values are simply ignored. 

I propose teaching help() to read those optional dictionaries to give better information on member objects (much like we already have with property objects).

This is inspired by data dictionaries for database tables.

The pydoc implementation would be somewhat easy.  Roughly this:

   for name in data_descriptors:
       print(f' |  {name}'
       if isinstance(slots, dict) and name in slots:
           print(f' |      {slots[name]}')
       print(' |')


==== Example ====================================================

>>> 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', 
       )

>>> help(Bicycle)
Help on class Bicycle in module __main__:

class Bicycle(builtins.object)
 |  Data descriptors defined here:
 |  
 |  category
 |      Primary use: road, cross-over, or hybrid
 |  
 |  model
 |      Unique six digit vendor-supplied code
 |  
 |  price
 |      Rider size: child, small, medium, large, extra-large
 |  
 |  size
 |      Manufacturer suggested retail price

----------
components: Library (Lib)
messages: 338125
nosy: rhettinger
priority: normal
severity: normal
status: open
title: Build-out help() to read __slots__ with an optional data dictionary
type: enhancement
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36326>
_______________________________________


More information about the New-bugs-announce mailing list