@@ -48,6 +48,7 @@ class ObjType(enum.Enum):
48
48
MODULE = 'module'
49
49
CLASS = 'class'
50
50
CALLABLE = 'callable'
51
+ # properties or any `descriptor`
51
52
PROPERTY = 'property'
52
53
OTHER = 'other'
53
54
@@ -62,7 +63,9 @@ def get_obj_type(py_obj: Any) -> ObjType:
62
63
return ObjType .CLASS
63
64
elif callable (py_obj ):
64
65
return ObjType .CALLABLE
65
- elif isinstance (py_obj , property ):
66
+ elif hasattr (py_obj , '__get__' ):
67
+ # This handles any descriptor not only properties.
68
+ # https://docs.python.org/3/howto/descriptor.html
66
69
return ObjType .PROPERTY
67
70
else :
68
71
return ObjType .OTHER
@@ -956,6 +959,8 @@ def _get_other_member_doc(
956
959
# breaks on the site.
957
960
info = pprint .pformat (obj ).replace ('`' , r'\`' )
958
961
info = f'`{ info } `'
962
+ elif get_obj_type (obj ) is ObjType .PROPERTY :
963
+ info = None
959
964
else :
960
965
class_full_name = parser_config .reverse_index .get (id (type (obj )), None )
961
966
if class_full_name is None :
@@ -967,12 +972,10 @@ def _get_other_member_doc(
967
972
class_full_name = f'{ module } .{ class_name } '
968
973
info = f'Instance of `{ class_full_name } `'
969
974
970
- if description is None :
971
- result = info
972
- else :
973
- result = f'{ info } \n \n { description } '
975
+ parts = [info , description ]
976
+ parts = [item for item in parts if item is not None ]
974
977
975
- return result
978
+ return ' \n \n ' . join ( parts )
976
979
977
980
978
981
def _parse_md_docstring (
@@ -1086,13 +1089,13 @@ def visit_AnnAssign(self, node) -> None: # pylint: disable=invalid-name
1086
1089
class ASTDefaultValueExtractor (ast .NodeVisitor ):
1087
1090
"""Extracts the default values by parsing the AST of a function."""
1088
1091
1089
- _PAREN_NUMBER_RE = re .compile (r'^\(([0-9.e-]+)\)' )
1092
+ _PAREN_NUMBER_RE = re .compile (r'^\((True|False| [0-9.e-]+)\)' )
1090
1093
1091
1094
def __init__ (self ):
1092
1095
self .ast_args_defaults = {}
1093
1096
self .ast_kw_only_defaults = {}
1094
1097
1095
- def _preprocess (self , val : str ) -> str :
1098
+ def _preprocess (self , val ) -> str :
1096
1099
text_default_val = astor .to_source (val ).strip ().replace (
1097
1100
'\t ' , '\\ t' ).replace ('\n ' , '\\ n' ).replace ('"""' , "'" )
1098
1101
text_default_val = self ._PAREN_NUMBER_RE .sub ('\\ 1' , text_default_val )
@@ -2208,7 +2211,7 @@ def _augment_attributes(self,
2208
2211
# namedtuple fields first, in order.
2209
2212
for name , desc in self ._namedtuplefields .items ():
2210
2213
# If a namedtuple field has been filtered out, it's description will
2211
- # not have been set in the `member_info` loop , so skip fields with `None`
2214
+ # not have been set in loop in `collect_docs` , so skip fields with `None`
2212
2215
# as the description.
2213
2216
if desc is not None :
2214
2217
attrs [name ] = desc
0 commit comments