summaryrefslogtreecommitdiff
path: root/Lib/pydoc.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-11-12 19:47:38 +0200
committerSerhiy Storchaka <storchaka@gmail.com>2015-11-12 19:47:38 +0200
commit1e8528022c0d57004d5e45f69761bfce2cda5573 (patch)
treef734f46424bc122530a852abb6fbb2f27c089761 /Lib/pydoc.py
parent7006c33c21ba0db56f80b9236e6c6b373e479ed2 (diff)
parentd9f3a4fea570a035b5767518abca56a6d529a4a4 (diff)
downloadcpython-1e8528022c0d57004d5e45f69761bfce2cda5573.tar.gz
Issue #25607: Restore old distutils logging threshold after running tests that
parse command line arguments.
Diffstat (limited to 'Lib/pydoc.py')
-rw-r--r--[-rwxr-xr-x]Lib/pydoc.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index a9c04f0728..a73298d715 100755..100644
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -209,6 +209,18 @@ def classify_class_attrs(object):
results.append((name, kind, cls, value))
return results
+def sort_attributes(attrs, object):
+ 'Sort the attrs list in-place by _fields and then alphabetically by name'
+ # This allows data descriptors to be ordered according
+ # to a _fields attribute if present.
+ fields = getattr(object, '_fields', [])
+ try:
+ field_order = {name : i-len(fields) for (i, name) in enumerate(fields)}
+ except TypeError:
+ field_order = {}
+ keyfunc = lambda attr: (field_order.get(attr[0], 0), attr[0])
+ attrs.sort(key=keyfunc)
+
# ----------------------------------------------------- module manipulation
def ispackage(path):
@@ -867,8 +879,7 @@ class HTMLDoc(Doc):
object.__module__)
tag += ':<br>\n'
- # Sort attrs by name.
- attrs.sort(key=lambda t: t[0])
+ sort_attributes(attrs, object)
# Pump out the attrs, segregated by kind.
attrs = spill('Methods %s' % tag, attrs,
@@ -1286,8 +1297,8 @@ location listed above.
else:
tag = "inherited from %s" % classname(thisclass,
object.__module__)
- # Sort attrs by name.
- attrs.sort()
+
+ sort_attributes(attrs, object)
# Pump out the attrs, segregated by kind.
attrs = spill("Methods %s:\n" % tag, attrs,