New submission from Raymond Hettinger:

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.

----------
components: Library (Lib)
messages: 248714
nosy: rhettinger
priority: normal
severity: normal
status: open
title: Pydoc to list data descriptors in _fields order if it exists
type: enhancement
versions: Python 3.6

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue24879>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to