mkdocstrings / pytkdocs

Load Python objects documentation.
https://mkdocstrings.github.io/pytkdocs
ISC License
50 stars 32 forks source link

[FEATURE] Allow method_descriptors to be serialized as methods #103

Closed jmrgibson closed 3 years ago

jmrgibson commented 3 years ago

Hi,

I'm trying to add support for python methods created using pyo3. These methods are "built-in" methods, however they can still expose the __doc__ attribute and a function signature via __text_signature__.

The current implementation detects method_descriptors (which is what most native functions end up as), and serializes them as regular methods (since from a caller point of view, they act the same). If the user doesn't provide the __text_signature__ attribute, inspect.signature will error out, so I made it optional, as I still think it would be useful to have the docstring in the resulting documentation if it exists.

Please let me know if this is the right direction for this approach. There are other modifications coming to mkdocstrings too, as it currently doesn't populate functions/methods with __text_signature__ or with no signature very well.

Thanks,

jmrgibson commented 3 years ago

Hmm. I don't really want to add rust + pyo3 as a dependency, but I should be able to make a test that creates a method descriptor using pure python. I'll dig through python docs and have a test sometime this week.

jmrgibson commented 3 years ago

I was able to use the built-in int.__add__, which was very convenient. Test added.

pawamoy commented 3 years ago

Thanks again!