Skip to content

Commit 62be338

Browse files
authored
bpo-36401: Have help() show readonly properties separately (GH-12517)
1 parent 113d735 commit 62be338

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

Lib/pydoc.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ def classify_class_attrs(object):
203203
for (name, kind, cls, value) in inspect.classify_class_attrs(object):
204204
if inspect.isdatadescriptor(value):
205205
kind = 'data descriptor'
206+
if isinstance(value, property) and value.fset is None:
207+
kind = 'readonly property'
206208
results.append((name, kind, cls, value))
207209
return results
208210

@@ -884,6 +886,8 @@ def spilldata(msg, attrs, predicate):
884886
lambda t: t[1] == 'class method')
885887
attrs = spill('Static methods %s' % tag, attrs,
886888
lambda t: t[1] == 'static method')
889+
attrs = spilldescriptors("Readonly properties %s:\n" % tag, attrs,
890+
lambda t: t[1] == 'readonly property')
887891
attrs = spilldescriptors('Data descriptors %s' % tag, attrs,
888892
lambda t: t[1] == 'data descriptor')
889893
attrs = spilldata('Data and other attributes %s' % tag, attrs,
@@ -1341,6 +1345,8 @@ def spilldata(msg, attrs, predicate):
13411345
lambda t: t[1] == 'class method')
13421346
attrs = spill("Static methods %s:\n" % tag, attrs,
13431347
lambda t: t[1] == 'static method')
1348+
attrs = spilldescriptors("Readonly properties %s:\n" % tag, attrs,
1349+
lambda t: t[1] == 'readonly property')
13441350
attrs = spilldescriptors("Data descriptors %s:\n" % tag, attrs,
13451351
lambda t: t[1] == 'data descriptor')
13461352
attrs = spilldata("Data and other attributes %s:\n" % tag, attrs,

Lib/test/test_enum.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2825,7 +2825,7 @@ class Color(enum.Enum)
28252825
| The value of the Enum member.
28262826
|\x20\x20
28272827
| ----------------------------------------------------------------------
2828-
| Data descriptors inherited from enum.EnumMeta:
2828+
| Readonly properties inherited from enum.EnumMeta:
28292829
|\x20\x20
28302830
| __members__
28312831
| Returns a mapping of member name->value.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The class documentation created by pydoc now has a separate section for
2+
readonly properties.

0 commit comments

Comments
 (0)