[Python-checkins] bpo-36401: Have help() show readonly properties separately (GH-12517)
Raymond Hettinger
webhook-mailer at python.org
Sun Mar 24 20:07:50 EDT 2019
https://github.com/python/cpython/commit/62be33870e2f8517314bf9c7275548e799296f7e
commit: 62be33870e2f8517314bf9c7275548e799296f7e
branch: master
author: Raymond Hettinger <rhettinger at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-03-24T17:07:47-07:00
summary:
bpo-36401: Have help() show readonly properties separately (GH-12517)
files:
A Misc/NEWS.d/next/Library/2019-03-23-10-25-07.bpo-36401.hYpVBS.rst
M Lib/pydoc.py
M Lib/test/test_enum.py
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index daa7205bd74e..2f570e4dc5de 100644
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -203,6 +203,8 @@ def classify_class_attrs(object):
for (name, kind, cls, value) in inspect.classify_class_attrs(object):
if inspect.isdatadescriptor(value):
kind = 'data descriptor'
+ if isinstance(value, property) and value.fset is None:
+ kind = 'readonly property'
results.append((name, kind, cls, value))
return results
@@ -884,6 +886,8 @@ def spilldata(msg, attrs, predicate):
lambda t: t[1] == 'class method')
attrs = spill('Static methods %s' % tag, attrs,
lambda t: t[1] == 'static method')
+ attrs = spilldescriptors("Readonly properties %s:\n" % tag, attrs,
+ lambda t: t[1] == 'readonly property')
attrs = spilldescriptors('Data descriptors %s' % tag, attrs,
lambda t: t[1] == 'data descriptor')
attrs = spilldata('Data and other attributes %s' % tag, attrs,
@@ -1341,6 +1345,8 @@ def spilldata(msg, attrs, predicate):
lambda t: t[1] == 'class method')
attrs = spill("Static methods %s:\n" % tag, attrs,
lambda t: t[1] == 'static method')
+ attrs = spilldescriptors("Readonly properties %s:\n" % tag, attrs,
+ lambda t: t[1] == 'readonly property')
attrs = spilldescriptors("Data descriptors %s:\n" % tag, attrs,
lambda t: t[1] == 'data descriptor')
attrs = spilldata("Data and other attributes %s:\n" % tag, attrs,
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index 770decf2f4bf..47081cf75ca0 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -2825,7 +2825,7 @@ class Color(enum.Enum)
| The value of the Enum member.
|\x20\x20
| ----------------------------------------------------------------------
- | Data descriptors inherited from enum.EnumMeta:
+ | Readonly properties inherited from enum.EnumMeta:
|\x20\x20
| __members__
| Returns a mapping of member name->value.
diff --git a/Misc/NEWS.d/next/Library/2019-03-23-10-25-07.bpo-36401.hYpVBS.rst b/Misc/NEWS.d/next/Library/2019-03-23-10-25-07.bpo-36401.hYpVBS.rst
new file mode 100644
index 000000000000..cf097d7ed4ad
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-03-23-10-25-07.bpo-36401.hYpVBS.rst
@@ -0,0 +1,2 @@
+The class documentation created by pydoc now has a separate section for
+readonly properties.
More information about the Python-checkins
mailing list