@@ -367,6 +367,14 @@ def _is_descriptor(obj):
367
367
inspect .ismemberdescriptor (obj ))
368
368
369
369
370
+ def _unwrap_descriptor (obj ):
371
+ if isinstance (obj , property ):
372
+ return (getattr (obj , 'fget' , False ) or
373
+ getattr (obj , 'fset' , False ) or
374
+ getattr (obj , 'fdel' , obj ))
375
+ return getattr (obj , '__get__' , obj )
376
+
377
+
370
378
def _filter_type (type : Type [T ],
371
379
values : Union [Iterable ['Doc' ], Mapping [str , 'Doc' ]]) -> List [T ]:
372
380
"""
@@ -488,7 +496,7 @@ def source(self) -> str:
488
496
available, an empty string.
489
497
"""
490
498
try :
491
- lines , _ = inspect .getsourcelines (self .obj )
499
+ lines , _ = inspect .getsourcelines (_unwrap_descriptor ( self .obj ) )
492
500
except (ValueError , TypeError , OSError ):
493
501
return ''
494
502
return inspect .cleandoc ('' .join (['\n ' ] + lines ))
@@ -1002,7 +1010,7 @@ def definition_order_index(
1002
1010
(inspect .isclass (obj ) or _is_descriptor (obj )) and inspect .getdoc (obj )),
1003
1011
cls = self ,
1004
1012
kind = kind ,
1005
- obj = getattr (obj , 'fget' , getattr ( obj , '__get__' , None )) ,
1013
+ obj = _is_descriptor (obj ) and obj or None ,
1006
1014
instance_var = (_is_descriptor (obj ) or
1007
1015
name in getattr (self .obj , '__slots__' , ())))
1008
1016
@@ -1277,7 +1285,8 @@ def return_annotation(self, *, link=None) -> str:
1277
1285
lambda : _get_type_hints (cast (Class , self .cls ).obj )[self .name ],
1278
1286
# global variables
1279
1287
lambda : _get_type_hints (not self .cls and self .module .obj )[self .name ],
1280
- lambda : inspect .signature (self .obj ).return_annotation ,
1288
+ # properties
1289
+ lambda : inspect .signature (_unwrap_descriptor (self .obj )).return_annotation ,
1281
1290
# Use raw annotation strings in unmatched forward declarations
1282
1291
lambda : cast (Class , self .cls ).obj .__annotations__ [self .name ],
1283
1292
# Extract annotation from the docstring for C builtin function
0 commit comments