pdoc icon indicating copy to clipboard operation
pdoc copied to clipboard

Not showing docs when PyO3 registers a struct with a different name

Open elbaro opened this issue 3 months ago • 1 comments

My PyO3 module exposes a Rust struct in two places:

# mylib.SyncConn
m.add_class::<SyncConn>()?;

# mylib.sync.Conn
let sync = PyModule::new(py, "sync")?;
sync.add("Conn", py.get_type::<SyncConn>())?;
m.add_submodule(&sync)?;

pdoc correctly shows the class members of SyncConn not sync.Conn:

Image

As a workaround, I manually assigned an instance of pdoc.doc.Class to the other. This works if I want to show the full class members in both places, but if I want to customize them differently, I cannot deepcopy pdoc.doc.Class.

all_modules["pyro_mysql.sync"].members["Conn"] = copy.deepcopy(
        all_modules["pyro_mysql"].members["SyncConn"]
    )

all_modules["pyro_mysql"].members[
    "SyncConn"
].docstring = "See `pyro_mysql.sync.Conn`."
all_modules["pyro_mysql"].members["SyncConn"].own_members = []
all_modules["pyro_mysql"].members["SyncConn"].methods = []
all_modules["pyro_mysql"].members["SyncConn"].staticmembers = []
all_modules["pyro_mysql"].members["SyncConn"].classmembers = []

System Information

pdoc: 15.0.4 Python: 3.14.0rc2

elbaro avatar Sep 16 '25 07:09 elbaro

I think this is because your class' __name__ is SyncConn and not Conn, which triggers a heuristic for static class attributes (https://github.com/mitmproxy/pdoc/issues/464). I suppose we could fine-tune the heuristic a bit, but generally speaking I'd just recommend to not expose classes under different names. Aside from pdoc, that's always going to be a can of worms in Python.

mhils avatar Oct 11 '25 20:10 mhils