[issue24879] Pydoc to list data descriptors in _fields order if it exists

2015-08-18 Thread Raymond Hettinger

Changes by Raymond Hettinger :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24879] Pydoc to list data descriptors in _fields order if it exists

2015-08-18 Thread Roundup Robot

Roundup Robot added the comment:

New changeset f5c40ab9e233 by Raymond Hettinger in branch 'default':
Issue #24879:  Teach pydoc to display named tuple fields in the order they were 
defined.
https://hg.python.org/cpython/rev/f5c40ab9e233

--
nosy: +python-dev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24879] Pydoc to list data descriptors in _fields order if it exists

2015-08-18 Thread Raymond Hettinger

Changes by Raymond Hettinger :


Added file: http://bugs.python.org/file40203/pydoc2.diff

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24879] Pydoc to list data descriptors in _fields order if it exists

2015-08-18 Thread R. David Murray

R. David Murray added the comment:

No, protocols and duck typing do not always use dunder names.  In fact checking 
for dunder names explicitly is probably the less common of the two cases.  (We 
are talking about "protocol" here in a generic sense, not the restricted set of 
those that include dunder methods.)

--
nosy: +r.david.murray

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24879] Pydoc to list data descriptors in _fields order if it exists

2015-08-17 Thread Yury Selivanov

Yury Selivanov added the comment:

> Named tuples are not a type, they are a protocol.  Guido has agreed that 
> checking for _fields is an acceptable and preferred way of finding out 
> whether something is a namedtuple.

They are, but for protocols we usually use dunder names.  "_fields" is a common 
enough attribute name for all kinds of objects, not necessarily namedtuples.

Can we at least check if the class is a tuple subclass and then use its 
'_fields' for sorting?

> I can add a check to at least check the value of _fields is an iterable of 
> strings.  If it still aliases with some random use of _fields, the only 
> consequence is that the matching field names will appear in a different order.

+1 for checking if it's an iterable of strings.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24879] Pydoc to list data descriptors in _fields order if it exists

2015-08-17 Thread Raymond Hettinger

Raymond Hettinger added the comment:

Named tuples are not a type, they are a protocol.  Guido has agreed that 
checking for _fields is an acceptable and preferred way of finding out whether 
something is a namedtuple.I can add a check to at least check the value of 
_fields is an iterable of strings.  If it still aliases with some random use of 
_fields, the only consequence is that the matching field names will appear in a 
different order.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24879] Pydoc to list data descriptors in _fields order if it exists

2015-08-17 Thread Yury Selivanov

Yury Selivanov added the comment:

Can this be enabled only for namedtuples?  Otherwise this might be a backwards 
incompatible change, for example:

  class Foo:
'''spam'''
_fields = None

--
nosy: +yselivanov

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24879] Pydoc to list data descriptors in _fields order if it exists

2015-08-16 Thread Raymond Hettinger

Raymond Hettinger added the comment:

With the attached patch, the new output is:

 |  --
 |  Data descriptors defined here:
 |  
 |  nickname
 |  Alias for field number 0
 |   
 |  firstname
 |  Alias for field number 1 
 | 
 |  age
 |  Alias for field number 2
 | 
 |  __dict__
 |  A new OrderedDict mapping field names to their values

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24879] Pydoc to list data descriptors in _fields order if it exists

2015-08-16 Thread Raymond Hettinger

Changes by Raymond Hettinger :


--
keywords: +patch
Added file: http://bugs.python.org/file40194/pydoc.diff

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24879] Pydoc to list data descriptors in _fields order if it exists

2015-08-16 Thread Raymond Hettinger

Changes by Raymond Hettinger :


--
assignee:  -> rhettinger
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24879] Pydoc to list data descriptors in _fields order if it exists

2015-08-16 Thread Raymond Hettinger

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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com