]> granicus.if.org Git - python/commitdiff
bpo-36401: Have help() show readonly properties separately (GH-12517)
authorRaymond Hettinger <rhettinger@users.noreply.github.com>
Mon, 25 Mar 2019 00:07:47 +0000 (17:07 -0700)
committerGitHub <noreply@github.com>
Mon, 25 Mar 2019 00:07:47 +0000 (17:07 -0700)
Lib/pydoc.py
Lib/test/test_enum.py
Misc/NEWS.d/next/Library/2019-03-23-10-25-07.bpo-36401.hYpVBS.rst [new file with mode: 0644]

index daa7205bd74e95afd891ba61188f3e7b6c9b0772..2f570e4dc5def8f39245c1340bffe92cebe3cb67 100644 (file)
@@ -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 @@ class HTMLDoc(Doc):
                           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 @@ location listed above.
                           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,
index 770decf2f4bfe7c6a7680737b39de60a286f8f12..47081cf75ca086d5715be6cd8bcff9e8f0b6f745 100644 (file)
@@ -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 (file)
index 0000000..cf097d7
--- /dev/null
@@ -0,0 +1,2 @@
+The class documentation created by pydoc now has a separate section for
+readonly properties.