@@ -173,6 +173,18 @@ def is_method(self) -> bool:
173
173
function_type = type (lambda : None )
174
174
return self .parent_is_class () and isinstance (self .obj , function_type )
175
175
176
+ def is_method_descriptor (self ) -> bool :
177
+ """
178
+ Tell if this node's object is a method descriptor.
179
+
180
+ Built-in methods (e.g. those implemented in C/Rust) are often
181
+ method descriptors, rather than normal methods.
182
+
183
+ Returns:
184
+ If this node's object is a method descriptor.
185
+ """
186
+ return inspect .ismethoddescriptor (self .obj )
187
+
176
188
def is_staticmethod (self ) -> bool :
177
189
"""
178
190
Tell if this node's object is a staticmethod.
@@ -360,6 +372,8 @@ def get_object_documentation(self, dotted_path: str, members: Optional[Union[Set
360
372
root_object = self .get_staticmethod_documentation (leaf )
361
373
elif leaf .is_classmethod ():
362
374
root_object = self .get_classmethod_documentation (leaf )
375
+ elif leaf .is_method_descriptor ():
376
+ root_object = self .get_regular_method_documentation (leaf )
363
377
elif leaf .is_method ():
364
378
root_object = self .get_regular_method_documentation (leaf )
365
379
elif leaf .is_function ():
@@ -792,7 +806,7 @@ def get_regular_method_documentation(self, node: ObjectNode) -> Method:
792
806
793
807
def get_method_documentation (self , node : ObjectNode , properties : Optional [List [str ]] = None ) -> Method :
794
808
"""
795
- Get the documentation for a method.
809
+ Get the documentation for a method or method descriptor .
796
810
797
811
Arguments:
798
812
node: The node representing the method and its parents.
@@ -819,12 +833,23 @@ def get_method_documentation(self, node: ObjectNode, properties: Optional[List[s
819
833
else :
820
834
properties .append ("async" )
821
835
836
+ try :
837
+ # for "built-in" functions, e.g. those implemented in C,
838
+ # inspect.signature() uses the __text_signature__ attribute, which
839
+ # provides a limited but still useful amount of signature information.
840
+ # "built-in" functions with no __text_signature__ will
841
+ # raise a ValueError().
842
+ signature = inspect .signature (method )
843
+ except ValueError as error :
844
+ self .errors .append (f"Couldn't read signature for '{ path } ': { error } " )
845
+ signature = None
846
+
822
847
return Method (
823
848
name = node .name ,
824
849
path = path ,
825
850
file_path = node .file_path ,
826
851
docstring = inspect .getdoc (method ),
827
- signature = inspect . signature ( method ) ,
852
+ signature = signature ,
828
853
properties = properties or [],
829
854
source = source ,
830
855
)
0 commit comments