Author rhettinger
Recipients rhettinger
Date 2015-08-17.05:33:07
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1439789590.43.0.926064650189.issue24879@psf.upfronthosting.co.za>
In-reply-to
Content
Currently, help() lists out data descriptors in alphabetical order.  This is fine in the general case, however if the fields are parts of a named tuple, it is more sensible to list them in the order found in the tuple.

The presence of a named tuple can be detected by the presence of a _fields attribute that is a list of strings.  That strings can be used as a primary sort key before an alphabetical sort of anything not listed in _fields.

>>> Person = namedtuple('Person', ['nickname', 'firstname', 'age'])
>>> help(Person)
Help on class Person in module __main__:

class Person(builtins.tuple)
 |  Person(nickname, firstname, age)
 |  
 ...
 |  
 |  ----------------------------------------------------------------------
 |  Static methods defined here:
 |  
 |  __new__(_cls, nickname, firstname, age)
 |      Create new instance of Person(nickname, firstname, age)
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  __dict__
 |      A new OrderedDict mapping field names to their values
 |  
 |  age
 |      Alias for field number 2
 |  
 |  firstname
 |      Alias for field number 1
 |  
 |  nickname
 |      Alias for field number 0
 |  
 |  ----------------------------------------------------------------------
 |  Data and other attributes defined here:
 |  
 |  _fields = ('nickname', 'firstname', 'age')
 |  
 ...

The data descriptors should list nickname, then firstname, then age to match the tuple order in _fields.
History
Date User Action Args
2015-08-17 05:33:10rhettingersetrecipients: + rhettinger
2015-08-17 05:33:10rhettingersetmessageid: <1439789590.43.0.926064650189.issue24879@psf.upfronthosting.co.za>
2015-08-17 05:33:10rhettingerlinkissue24879 messages
2015-08-17 05:33:07rhettingercreate