mkdocstrings / pytkdocs

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

Nasty direct path to own types. #119

Closed Bluenix2 closed 2 years ago

Bluenix2 commented 2 years ago

Is your feature request related to a problem? Please describe. In my documentation generated by mkdocstrings's Python handler I get some very ugly tables thanks to the direct path of my own types.

Examples of this can be seen here: image

I would like to have the option to just use the class names (edited using Inspect): image

I do have some worse examples like this one, which is a pretty complex type but this doesn't make it better: image

Could look like this instead: image

Very noisy, but to all the fault of my own now.

Describe the solution you'd like Some option to only use the class names. The same way that when you list a class you get Option and not wumpy.interactions.commands.option.Option. If this could be individually applied as well that would allow someone to add it where necessary.

Describe alternatives you've considered Some how overriding pytkdocs, I don't even know where to start and it seems fragile.

Additional context This is something I personally need and wouldn't mind looking into it if I just get a pointer to appropriate files.

pawamoy commented 2 years ago

I've seen users patch mkdocstrings functions to better fit their needs. Maybe your feature request could be implemented the same way (as a workaround for now), by patching the rebuild_category_lists to post-process types so as to remove the leading parts. Draft regex-replace: re.sub(r"(\w+\.)*", "", annotation) (a simple split could work: annotation.rsplit(".", 1)[-1])

I think it could be done with custom templates as well (same logic, different place).

We could probably add an option in pytkdocs itself, but I'm pushing back on features right now because I'm working on a better replacement, that parses the code instead of introspecting objects in memory.

pawamoy commented 2 years ago

This is likely solved by the new handler. The annotations are rendered just as they are written in the source code. Feedback appreciated!